Skip to content

Commit ab4f3cc

Browse files
committed
:bd[elete] suppresses unsaved changes warning
1 parent 1bd90e1 commit ab4f3cc

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/cmd_line/commands/bufferDelete.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import * as vscode from 'vscode';
33

44
import { VimError } from '../../error';
55
import { VimState } from '../../state/vimState';
6-
import { StatusBar } from '../../statusBar';
76
import { ExCommand } from '../../vimscript/exCommand';
87
import { bangParser, fileNameParser, numberParser } from '../../vimscript/parserUtils';
9-
import { find } from 'lodash';
108
import { findTabInActiveTabGroup } from '../../util/util';
119

1210
interface 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

Comments
 (0)