提交 2a936541 编写于 作者: B Benjamin Pasero

Can no longer open image files from the git viewlet (fixes #33739)

上级 eac1f7dd
......@@ -179,8 +179,7 @@ export class CommandCenter {
}
if (!left) {
const document = await workspace.openTextDocument(right);
await window.showTextDocument(document, opts);
await commands.executeCommand<void>('vscode.open', right, opts);
return;
}
......@@ -372,8 +371,7 @@ export class CommandCenter {
opts.selection = activeTextEditor.selection;
}
const document = await workspace.openTextDocument(uri);
await window.showTextDocument(document, opts);
await commands.executeCommand<void>('vscode.open', uri, opts);
}
}
......
......@@ -15,7 +15,7 @@ import * as modes from 'vs/editor/common/modes';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { IWorkspaceSymbolProvider } from 'vs/workbench/parts/search/common/search';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { Position as EditorPosition, ITextEditorOptions } from 'vs/platform/editor/common/editor';
export class ExtHostApiCommands {
......@@ -205,20 +205,11 @@ export class ExtHostApiCommands {
});
this._register('vscode.diff', (left: URI, right: URI, label: string, options?: vscode.TextDocumentShowOptions) => {
let editorOptions: ITextEditorOptions;
if (options) {
editorOptions = {
pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
preserveFocus: options.preserveFocus,
selection: typeof options.selection === 'object' ? typeConverters.fromRange(options.selection) : undefined
};
}
return this._commands.executeCommand('_workbench.diff', [
left, right,
label,
undefined,
editorOptions,
typeConverters.toTextEditorOptions(options),
options ? typeConverters.fromViewColumn(options.viewColumn) : undefined
]);
}, {
......@@ -231,13 +222,29 @@ export class ExtHostApiCommands {
]
});
this._register('vscode.open', (resource: URI, column: vscode.ViewColumn) => {
return this._commands.executeCommand('_workbench.open', [resource, typeConverters.fromViewColumn(column)]);
this._register('vscode.open', (resource: URI, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions) => {
let options: ITextEditorOptions;
let column: EditorPosition;
if (columnOrOptions) {
if (typeof columnOrOptions === 'number') {
column = typeConverters.fromViewColumn(columnOrOptions);
} else {
options = typeConverters.toTextEditorOptions(columnOrOptions);
column = typeConverters.fromViewColumn(columnOrOptions.viewColumn);
}
}
return this._commands.executeCommand('_workbench.open', [
resource,
options,
column
]);
}, {
description: 'Opens the provided resource in the editor. Can be a text or binary file, or a http(s) url. If you need more control over the options for opening a text file, use vscode.window.showTextDocument instead.',
args: [
{ name: 'resource', description: 'Resource to open', constraint: URI },
{ name: 'column', description: '(optional) Column in which to open', constraint: v => v === void 0 || typeof v === 'number' }
{ name: 'columnOrOptions', description: '(optional) Either the column in which to open or editor options, see vscode.TextDocumentShowOptions', constraint: v => v === void 0 || typeof v === 'number' || typeof v === 'object' }
]
});
}
......
......@@ -7,7 +7,7 @@
import Severity from 'vs/base/common/severity';
import * as modes from 'vs/editor/common/modes';
import * as types from './extHostTypes';
import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { Position as EditorPosition, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IDecorationOptions, EndOfLineSequence } from 'vs/editor/common/editorCommon';
import * as vscode from 'vscode';
import URI from 'vs/base/common/uri';
......@@ -452,3 +452,15 @@ export namespace ProgressLocation {
return undefined;
}
}
export function toTextEditorOptions(options?: vscode.TextDocumentShowOptions): ITextEditorOptions {
if (options) {
return {
pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
preserveFocus: options.preserveFocus,
selection: typeof options.selection === 'object' ? fromRange(options.selection) : undefined
} as ITextEditorOptions;
}
return undefined;
}
\ No newline at end of file
......@@ -412,11 +412,11 @@ export function registerCommands(): void {
});
});
CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, number]) {
CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, IEditorOptions, EditorPosition]) {
const editorService = accessor.get(IWorkbenchEditorService);
const [resource, column] = args;
const [resource, options, column] = args;
return editorService.openEditor({ resource }, column).then(() => {
return editorService.openEditor({ resource, options }, column).then(() => {
return void 0;
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册