@@ -23,7 +23,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
23
23
import { FontInfo } from 'vs/editor/common/config/fontInfo' ;
24
24
import { IDimension } from 'vs/editor/common/core/dimension' ;
25
25
import { Position } from 'vs/editor/common/core/position' ;
26
- import { IRange } from 'vs/editor/common/core/range' ;
26
+ import { IRange , Range } from 'vs/editor/common/core/range' ;
27
27
import { ScrollType } from 'vs/editor/common/editorCommon' ;
28
28
import { NewSymbolName , NewSymbolNameTag , ProviderResult } from 'vs/editor/common/languages' ;
29
29
import { localize } from 'vs/nls' ;
@@ -85,7 +85,13 @@ interface IRenameInputField {
85
85
/**
86
86
* @returns a `boolean` standing for `shouldFocusEditor`, if user didn't pick a new name, or a {@link RenameInputFieldResult}
87
87
*/
88
- getInput ( where : IRange , value : string , selectionStart : number , selectionEnd : number , supportPreview : boolean , candidates : ProviderResult < NewSymbolName [ ] > [ ] , cts : CancellationTokenSource ) : Promise < RenameInputFieldResult | boolean > ;
88
+ getInput (
89
+ where : IRange ,
90
+ currentName : string ,
91
+ supportPreview : boolean ,
92
+ candidates : ProviderResult < NewSymbolName [ ] > [ ] ,
93
+ cts : CancellationTokenSource
94
+ ) : Promise < RenameInputFieldResult | boolean > ;
89
95
90
96
acceptInput ( wantsPreview : boolean ) : void ;
91
97
cancelInput ( focusEditor : boolean , caller : string ) : void ;
@@ -349,13 +355,13 @@ export class RenameInputField implements IRenameInputField, IContentWidget, IDis
349
355
getInput (
350
356
where : IRange ,
351
357
currentName : string ,
352
- selectionStart : number ,
353
- selectionEnd : number ,
354
358
supportPreview : boolean ,
355
359
candidates : ProviderResult < NewSymbolName [ ] > [ ] ,
356
360
cts : CancellationTokenSource
357
361
) : Promise < RenameInputFieldResult | boolean > {
358
362
363
+ const { start : selectionStart , end : selectionEnd } = this . _getSelection ( where , currentName ) ;
364
+
359
365
this . _isEditingRenameCandidate = false ;
360
366
361
367
this . _domNode ! . classList . toggle ( 'preview' , supportPreview ) ;
@@ -441,6 +447,24 @@ export class RenameInputField implements IRenameInputField, IContentWidget, IDis
441
447
return inputResult . p ;
442
448
}
443
449
450
+ /**
451
+ * This allows selecting only part of the symbol name in the input field based on the selection in the editor
452
+ */
453
+ private _getSelection ( where : IRange , currentName : string ) : { start : number ; end : number } {
454
+ assertType ( this . _editor . hasModel ( ) ) ;
455
+
456
+ const selection = this . _editor . getSelection ( ) ;
457
+ let start = 0 ;
458
+ let end = currentName . length ;
459
+
460
+ if ( ! Range . isEmpty ( selection ) && ! Range . spansMultipleLines ( selection ) && Range . containsRange ( where , selection ) ) {
461
+ start = Math . max ( 0 , selection . startColumn - where . startColumn ) ;
462
+ end = Math . min ( where . endColumn , selection . endColumn ) - where . startColumn ;
463
+ }
464
+
465
+ return { start, end } ;
466
+ }
467
+
444
468
private _show ( ) : void {
445
469
this . _trace ( 'invoking _show' ) ;
446
470
this . _editor . revealLineInCenterIfOutsideViewport ( this . _position ! . lineNumber , ScrollType . Smooth ) ;
0 commit comments