提交 5f44e365 编写于 作者: J Johannes Rieken

fix issue #4945

上级 24fb832c
...@@ -6,9 +6,10 @@ ...@@ -6,9 +6,10 @@
'use strict'; 'use strict';
import * as assert from 'assert'; import * as assert from 'assert';
import {commands, workspace, Uri} from 'vscode'; import {join} from 'path';
import {commands, workspace, window, Uri} from 'vscode';
suite("commands namespace tests", () => { suite('commands namespace tests', () => {
test('getCommands', function(done) { test('getCommands', function(done) {
...@@ -39,7 +40,7 @@ suite("commands namespace tests", () => { ...@@ -39,7 +40,7 @@ suite("commands namespace tests", () => {
}, done); }, done);
}); });
test('api-command: workbench.html.preview', function() { test('api-command: workbench.html.preview', function () {
let registration = workspace.registerTextDocumentContentProvider('speciale', { let registration = workspace.registerTextDocumentContentProvider('speciale', {
provideTextDocumentContent(uri) { provideTextDocumentContent(uri) {
...@@ -47,12 +48,33 @@ suite("commands namespace tests", () => { ...@@ -47,12 +48,33 @@ suite("commands namespace tests", () => {
} }
}); });
let virtualDocumentUri = Uri.parse('speciale://authority/path') let virtualDocumentUri = Uri.parse('speciale://authority/path');
return commands.executeCommand('vscode.previewHtml', virtualDocumentUri).then(success => { return commands.executeCommand('vscode.previewHtml', virtualDocumentUri).then(success => {
assert.ok(success); assert.ok(success);
registration.dispose(); registration.dispose();
}); });
}) });
test('editorCommand with extra args', function () {
let args: IArguments;
let registration = commands.registerTextEditorCommand('t1', function() {
args = arguments;
});
return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => {
return window.showTextDocument(doc).then(editor => {
return commands.executeCommand('t1', 12345, commands);
}).then(() => {
assert.ok(args);
assert.equal(args.length, 4);
assert.ok(args[2] === 12345);
assert.ok(args[3] === commands);
registration.dispose();
});
});
});
}); });
...@@ -2865,7 +2865,7 @@ declare namespace vscode { ...@@ -2865,7 +2865,7 @@ declare namespace vscode {
* @param thisArg The `this` context used when invoking the handler function. * @param thisArg The `this` context used when invoking the handler function.
* @return Disposable which unregisters this command on disposal. * @return Disposable which unregisters this command on disposal.
*/ */
export function registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit) => void, thisArg?: any): Disposable; export function registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => void, thisArg?: any): Disposable;
/** /**
* Executes the command denoted by the given command identifier. * Executes the command denoted by the given command identifier.
......
...@@ -162,9 +162,8 @@ export class ExtHostAPIImplementation { ...@@ -162,9 +162,8 @@ export class ExtHostAPIImplementation {
registerCommand<T>(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable { registerCommand<T>(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
return extHostCommands.registerCommand(id, command, thisArgs); return extHostCommands.registerCommand(id, command, thisArgs);
}, },
registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void, thisArg?: any): vscode.Disposable { registerTextEditorCommand(id: string, callback: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => void, thisArg?: any): vscode.Disposable {
let actualCallback: typeof callback = thisArg ? callback.bind(thisArg) : callback; return extHostCommands.registerCommand(id, (...args: any[]) => {
return extHostCommands.registerCommand(id, () => {
let activeTextEditor = extHostEditors.getActiveTextEditor(); let activeTextEditor = extHostEditors.getActiveTextEditor();
if (!activeTextEditor) { if (!activeTextEditor) {
console.warn('Cannot execute ' + id + ' because there is no active text editor.'); console.warn('Cannot execute ' + id + ' because there is no active text editor.');
...@@ -172,7 +171,9 @@ export class ExtHostAPIImplementation { ...@@ -172,7 +171,9 @@ export class ExtHostAPIImplementation {
} }
activeTextEditor.edit((edit: vscode.TextEditorEdit) => { activeTextEditor.edit((edit: vscode.TextEditorEdit) => {
actualCallback(activeTextEditor, edit); args.unshift(activeTextEditor, edit);
callback.apply(thisArg, args);
}).then((result) => { }).then((result) => {
if (!result) { if (!result) {
console.warn('Edits from command ' + id + ' were not applied.'); console.warn('Edits from command ' + id + ' were not applied.');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册