@@ -2014,6 +2014,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
20142014 void this . addRegionToAnEntry ( ) ;
20152015 } ) ;
20162016
2017+ vscode . commands . registerCommand ( "weAudit.addRegionToAnEntryWithLabel" , ( ) => {
2018+ void this . addRegionToAnEntryWithLabel ( ) ;
2019+ } ) ;
2020+
20172021 vscode . commands . registerCommand ( "weAudit.deleteLocation" , ( entry : FullLocationEntry ) => {
20182022 this . deleteLocation ( entry ) ;
20192023 } ) ;
@@ -3169,9 +3173,11 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
31693173 }
31703174
31713175 /**
3172- * Add the selected code region to an existing entry
3176+ * Shared helper that adds the current editor selection(s) to an existing entry.
3177+ * Optionally prompts for a label that is applied to each new location.
3178+ * @param getLabel function that resolves to the label to assign, or undefined to skip labeling
31733179 */
3174- async addRegionToAnEntry ( ) : Promise < void > {
3180+ private async addRegionToEntryWithOptionalLabel ( getLabel ?: ( ) => Promise < string | undefined > ) : Promise < void > {
31753181 const editor = vscode . window . activeTextEditor ;
31763182 if ( editor === undefined ) {
31773183 return ;
@@ -3211,12 +3217,23 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32113217 return ;
32123218 }
32133219
3220+ let label : string | undefined ;
3221+ if ( getLabel ) {
3222+ label = await getLabel ( ) ;
3223+ if ( label === undefined ) {
3224+ return ;
3225+ }
3226+ }
3227+
32143228 const entry = pickItem . entry ;
3215- // Add each selection as a separate region
3229+ // Add each selection as a separate region, optionally tagging with the provided label
32163230 for ( const location of locations ) {
3231+ if ( label !== undefined ) {
3232+ location . label = label ;
3233+ }
32173234 entry . locations . push ( location ) ;
32183235 }
3219- void this . updateSavedData ( entry . author ) ;
3236+ this . updateSavedData ( entry . author ) ;
32203237 this . decorateWithUri ( editor . document . uri ) ;
32213238 this . refresh ( editor . document . uri ) ;
32223239 // reveal the entry in the tree view if the treeview is visible,
@@ -3227,6 +3244,25 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32273244 }
32283245 }
32293246
3247+ /**
3248+ * Add the selected code region to an existing entry
3249+ */
3250+ async addRegionToAnEntry ( ) : Promise < void > {
3251+ await this . addRegionToEntryWithOptionalLabel ( ) ;
3252+ }
3253+
3254+ /**
3255+ * Add the selected code region to an existing entry, prompting for a label
3256+ */
3257+ async addRegionToAnEntryWithLabel ( ) : Promise < void > {
3258+ await this . addRegionToEntryWithOptionalLabel ( async ( ) =>
3259+ vscode . window . showInputBox ( {
3260+ title : "Enter a label for this location" ,
3261+ ignoreFocusOut : true ,
3262+ } ) ,
3263+ ) ;
3264+ }
3265+
32303266 /**
32313267 * Loads the saved findings from a file
32323268 * @param config the configuration to load from
0 commit comments