@@ -6,7 +6,7 @@ import { Register, RegisterContent } from '../../register/register';
66import { RecordedState } from '../../state/recordedState' ;
77import { VimState } from '../../state/vimState' ;
88import { ExCommand } from '../../vimscript/exCommand' ;
9- import { IPutCommandArguments , PutExCommand } from './put' ;
9+ import { PutExCommand } from './put' ;
1010
1111class RegisterDisplayItem implements vscode . QuickPickItem {
1212 public readonly label : string ;
@@ -78,57 +78,40 @@ export class RegisterCommand extends ExCommand {
7878 } ) ,
7979 ) ;
8080
81+ // The user clicked a QuickPick item
8182 quickPick . onDidChangeSelection ( ( items ) => {
82- if ( items . length === 0 ) {
83- return ;
84- }
85-
86- RegisterCommand . showRegisterContent ( vimState , items [ 0 ] ) ;
83+ RegisterCommand . showRegisterContent ( items ) ;
8784 quickPick . dispose ( ) ;
8885 } ) ;
8986
9087 quickPick . onDidTriggerItemButton ( async ( event ) => {
91- void RegisterCommand . paste ( vimState , event . item ) ;
88+ await RegisterCommand . paste ( vimState , event . item ) ;
9289 quickPick . dispose ( ) ;
9390 } ) ;
9491
95- quickPick . show ( ) ;
96- }
97-
98- private static showRegisterContent ( vimState : VimState , item : RegisterDisplayItem ) {
99- const paste : vscode . MessageItem = {
100- title : 'Paste' ,
101- isCloseAffordance : false ,
102- } ;
103-
104- void vscode . window
105- . showInformationMessage ( `${ item . label } ${ item . stringContent } ` , paste )
106- . then ( ( action ) => {
107- if ( ! action || action !== paste ) {
108- return ;
109- }
110-
111- void RegisterCommand . paste ( vimState , item ) ;
112- } ) ;
92+ return new Promise < void > ( ( resolve ) => {
93+ quickPick . onDidHide ( resolve ) ;
94+ quickPick . show ( ) ;
95+ } ) ;
11396 }
11497
115- private static async paste ( vimState : VimState , item : RegisterDisplayItem ) {
116- // TODO: Can I reuse PutCommand here?
117-
118- const content = item . stringContent ;
119- if ( content === '' ) {
98+ private static showRegisterContent ( items : readonly RegisterDisplayItem [ ] ) {
99+ if ( items . length === 0 ) {
120100 return ;
121101 }
122102
123- const editor = vscode . window . activeTextEditor ;
124- if ( ! editor ) {
125- return ;
126- }
103+ const item = items [ 0 ] ;
127104
128- vimState . recordedState . registerKey = item . key ;
105+ const message = `${ item . label } ${ item . stringContent } ` ;
106+ vscode . window . showInformationMessage ( message ) ;
107+ }
129108
130- editor . edit ( ( builder ) => {
131- builder . insert ( vimState . cursorStopPosition , content ) ;
109+ private static async paste ( vimState : VimState , item : RegisterDisplayItem ) {
110+ const putCommand = new PutExCommand ( {
111+ register : item . key ,
112+ bang : false ,
132113 } ) ;
114+
115+ await putCommand . execute ( vimState ) ;
133116 }
134117}
0 commit comments