@@ -3,10 +3,8 @@ import * as vscode from 'vscode';
33
44import { VimError } from '../../error' ;
55import { VimState } from '../../state/vimState' ;
6- import { StatusBar } from '../../statusBar' ;
76import { ExCommand } from '../../vimscript/exCommand' ;
87import { bangParser , fileNameParser , numberParser } from '../../vimscript/parserUtils' ;
9- import { find } from 'lodash' ;
108import { findTabInActiveTabGroup } from '../../util/util' ;
119
1210interface IBufferDeleteCommandArguments {
@@ -35,37 +33,47 @@ export class BufferDeleteCommand extends ExCommand {
3533 throw VimError . NoWriteSinceLastChange ( ) ;
3634 }
3735
36+ const activeBuffer =
37+ vscode . window . tabGroups . activeTabGroup . tabs . findIndex ( ( t ) => t . isActive ) + 1 ;
38+ if ( this . arguments . buffers . length === 0 ) {
39+ this . arguments . buffers = [ activeBuffer ] ;
40+ }
41+
3842 let deletedBuffers = 0 ;
3943
40- if ( this . arguments . buffers . length === 0 ) {
41- await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
42- } else {
43- for ( let buffer of this . arguments . buffers ) {
44- if ( typeof buffer === 'string' ) {
45- const [ idx , tab ] = findTabInActiveTabGroup ( buffer ) ;
46- buffer = idx + 1 ;
47- }
44+ for ( let buffer of this . arguments . buffers ) {
45+ if ( typeof buffer === 'string' ) {
46+ const [ idx , tab ] = findTabInActiveTabGroup ( buffer ) ;
47+ buffer = idx + 1 ;
48+ }
4849
49- if ( buffer < 1 ) {
50- throw VimError . PositiveCountRequired ( ) ;
51- }
52- if ( buffer > vscode . window . tabGroups . activeTabGroup . tabs . length ) {
53- continue ;
54- }
50+ if ( buffer < 1 ) {
51+ throw VimError . PositiveCountRequired ( ) ;
52+ }
53+ if ( buffer > vscode . window . tabGroups . activeTabGroup . tabs . length ) {
54+ continue ;
55+ }
5556
57+ if ( buffer !== activeBuffer ) {
5658 try {
5759 await vscode . commands . executeCommand ( 'workbench.action.openEditorAtIndex' , buffer - 1 ) ;
5860 } catch ( e ) {
5961 continue ;
6062 }
63+ }
6164
65+ if ( this . arguments . bang ) {
66+ await vscode . commands . executeCommand ( 'workbench.action.revertAndCloseActiveEditor' ) ;
67+ } else {
6268 await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
63- ++ deletedBuffers ;
6469 }
70+ ++ deletedBuffers ;
6571 }
6672
6773 if ( deletedBuffers === 0 ) {
6874 throw VimError . NoBuffersDeleted ( ) ;
6975 }
7076 }
77+
78+ // TODO: executeWithRange
7179}
0 commit comments