@@ -3167,69 +3167,11 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
31673167 }
31683168
31693169 /**
3170- * Add the selected code region to an existing entry
3170+ * Shared helper that adds the current editor selection(s) to an existing entry.
3171+ * Optionally prompts for a label that is applied to each new location.
3172+ * @param getLabel function that resolves to the label to assign, or undefined to skip labeling
31713173 */
3172- async addRegionToAnEntry ( ) : Promise < void > {
3173- const editor = vscode . window . activeTextEditor ;
3174- if ( editor === undefined ) {
3175- return ;
3176- }
3177- const locations = this . getActiveSelectionLocation ( ) ;
3178- if ( locations === undefined || locations . length === 0 ) {
3179- return ;
3180- }
3181-
3182- // create a quick pick to select the entry to add the region to
3183- const items = this . treeEntries
3184- . filter ( ( entry ) => {
3185- if ( entry . locations . length === 0 || entry . locations [ 0 ] . rootPath !== locations [ 0 ] . rootPath ) {
3186- return false ;
3187- }
3188- return true ;
3189- } )
3190- . map ( ( entry ) => {
3191- return {
3192- label : entry . label ,
3193- entry : entry ,
3194- } ;
3195- } ) ;
3196-
3197- // if we have no findings so far, create a new one
3198- if ( items . length === 0 ) {
3199- this . addFinding ( ) ;
3200- return ;
3201- }
3202-
3203- vscode . window
3204- . showQuickPick ( items , {
3205- ignoreFocusOut : true ,
3206- title : "Select the finding to add the region to" ,
3207- } )
3208- . then ( ( pickItem ) => {
3209- if ( pickItem === undefined ) {
3210- return ;
3211- }
3212- const entry = pickItem . entry ;
3213- // Add each selection as a separate region
3214- for ( const location of locations ) {
3215- entry . locations . push ( location ) ;
3216- }
3217- this . updateSavedData ( entry . author ) ;
3218- this . decorateWithUri ( editor . document . uri ) ;
3219- this . refresh ( editor . document . uri ) ;
3220- // reveal the entry in the tree view if the treeview is visible,
3221- // for some reason, it won't expand even if though it is created
3222- // with an expanded state
3223- if ( treeView . visible ) {
3224- treeView . reveal ( entry , { expand : 1 , select : false } ) ;
3225- }
3226- } ) ;
3227- }
3228-
3229- /**
3230- * Add the selected code region to an existing entry, prompting for a label
3231- */
3232- async addRegionToAnEntryWithLabel ( ) : Promise < void > {
3174+ private async addRegionToEntryWithOptionalLabel ( getLabel ?: ( ) => Promise < string | undefined > ) : Promise < void > {
32333175 const editor = vscode . window . activeTextEditor ;
32343176 if ( editor === undefined ) {
32353177 return ;
@@ -3269,19 +3211,20 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32693211 return ;
32703212 }
32713213
3272- const label = await vscode . window . showInputBox ( {
3273- title : "Enter a label for this location" ,
3274- ignoreFocusOut : true ,
3275- } ) ;
3276-
3277- if ( label === undefined ) {
3278- return ;
3214+ let label : string | undefined ;
3215+ if ( getLabel ) {
3216+ label = await getLabel ( ) ;
3217+ if ( label === undefined ) {
3218+ return ;
3219+ }
32793220 }
32803221
32813222 const entry = pickItem . entry ;
3282- // Add each selection as a separate region with the label
3223+ // Add each selection as a separate region, optionally tagging with the provided label
32833224 for ( const location of locations ) {
3284- location . label = label ;
3225+ if ( label !== undefined ) {
3226+ location . label = label ;
3227+ }
32853228 entry . locations . push ( location ) ;
32863229 }
32873230 this . updateSavedData ( entry . author ) ;
@@ -3295,6 +3238,25 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32953238 }
32963239 }
32973240
3241+ /**
3242+ * Add the selected code region to an existing entry
3243+ */
3244+ async addRegionToAnEntry ( ) : Promise < void > {
3245+ await this . addRegionToEntryWithOptionalLabel ( ) ;
3246+ }
3247+
3248+ /**
3249+ * Add the selected code region to an existing entry, prompting for a label
3250+ */
3251+ async addRegionToAnEntryWithLabel ( ) : Promise < void > {
3252+ await this . addRegionToEntryWithOptionalLabel ( async ( ) =>
3253+ vscode . window . showInputBox ( {
3254+ title : "Enter a label for this location" ,
3255+ ignoreFocusOut : true ,
3256+ } ) ,
3257+ ) ;
3258+ }
3259+
32983260 /**
32993261 * Loads the saved findings from a file
33003262 * @param config the configuration to load from
0 commit comments