-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1665 from mspaulding06/close-command-support
Add :close support based on :quit
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use strict"; | ||
|
||
import * as vscode from "vscode"; | ||
import * as node from "../node"; | ||
import * as error from '../../error'; | ||
|
||
export interface ICloseCommandArguments extends node.ICommandArgs { | ||
bang?: boolean; | ||
range?: node.LineRange; | ||
quitAll?: boolean; | ||
} | ||
|
||
// | ||
// Implements :close | ||
// http://vimdoc.sourceforge.net/htmldoc/windows.html#:close | ||
// | ||
export class CloseCommand extends node.CommandBase { | ||
protected _arguments : ICloseCommandArguments; | ||
|
||
constructor(args : ICloseCommandArguments) { | ||
super(); | ||
this._name = 'close'; | ||
this._arguments = args; | ||
} | ||
|
||
get arguments() : ICloseCommandArguments { | ||
return this._arguments; | ||
} | ||
|
||
async execute() : Promise<void> { | ||
if (this.activeTextEditor!.document.isDirty && !this.arguments.bang) { | ||
throw error.VimError.fromCode(error.ErrorCode.E37); | ||
} | ||
|
||
if (vscode.window.visibleTextEditors.length === 1) { | ||
throw error.VimError.fromCode(error.ErrorCode.E444); | ||
} | ||
|
||
let oldViewColumn = this.activeTextEditor!.viewColumn; | ||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); | ||
|
||
if (vscode.window.activeTextEditor !== undefined && vscode.window.activeTextEditor.viewColumn === oldViewColumn) { | ||
await vscode.commands.executeCommand('workbench.action.previousEditor'); | ||
} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use strict"; | ||
|
||
import * as node from "../commands/close"; | ||
import {Scanner} from '../scanner'; | ||
import {VimError, ErrorCode} from '../../error'; | ||
|
||
export function parseCloseCommandArgs(args : string) : node.CloseCommand { | ||
if (!args) { | ||
return new node.CloseCommand({}); | ||
} | ||
var scannedArgs : node.ICloseCommandArguments = {}; | ||
var scanner = new Scanner(args); | ||
const c = scanner.next(); | ||
if (c === '!') { | ||
scannedArgs.bang = true; | ||
scanner.ignore(); | ||
} else if (c !== ' ') { | ||
throw VimError.fromCode(ErrorCode.E488); | ||
} | ||
scanner.skipWhiteSpace(); | ||
if (!scanner.isAtEof) { | ||
throw VimError.fromCode(ErrorCode.E488); | ||
} | ||
return new node.CloseCommand(scannedArgs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use strict"; | ||
|
||
// The module 'assert' provides assertion methods from node | ||
import * as assert from 'assert'; | ||
|
||
import {commandParsers} from '../../src/cmd_line/subparser'; | ||
|
||
suite(":close args parser", () => { | ||
|
||
test("has all aliases", () => { | ||
assert.equal(commandParsers.close.name, commandParsers.clo.name); | ||
}); | ||
|
||
test("can parse empty args", () => { | ||
var args = commandParsers.close(""); | ||
assert.equal(args.arguments.bang, undefined); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("ignores trailing white space", () => { | ||
var args = commandParsers.close(" "); | ||
assert.equal(args.arguments.bang, undefined); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("can parse !", () => { | ||
var args = commandParsers.close("!"); | ||
assert.ok(args.arguments.bang); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("throws if space before !", () => { | ||
assert.throws(() => commandParsers.close(" !")); | ||
}); | ||
|
||
test("ignores space after !", () => { | ||
|
||
var args = commandParsers.close("! "); | ||
assert.equal(args.arguments.bang, true); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("throws if bad input", () => { | ||
assert.throws(() => commandParsers.close("x")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters