提交 c952dafd 编写于 作者: B Benjamin Pasero

grid - lift activeTextEditorControl to text editor service

上级 7a6f19c6
......@@ -18,7 +18,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import H = editorCommon.Handler;
import { ICodeEditorService, getCodeEditor } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import * as types from 'vs/base/common/types';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
......@@ -26,7 +26,7 @@ import { ITextEditorService } from 'vs/editor/browser/services/textEditorService
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
const CORE_WEIGHT = KeybindingsRegistry.WEIGHT.editorCore();
......@@ -1620,10 +1620,19 @@ function findFocusedEditor(accessor: ServicesAccessor): ICodeEditor {
return accessor.get(ICodeEditorService).getFocusedCodeEditor();
}
function getWorkbenchActiveEditor(accessor: ServicesAccessor): ICodeEditor {
function getActiveEditor(accessor: ServicesAccessor): ICodeEditor {
const editorService = accessor.get(ITextEditorService);
let activeEditor = (<any>editorService).getActiveEditor && (<any>editorService).getActiveEditor();
return getCodeEditor(activeEditor);
let activeEditor = editorService.activeTextEditorControl;
if (isCodeEditor(activeEditor)) {
return activeEditor;
}
if (isDiffEditor(activeEditor)) {
return activeEditor.getModifiedEditor();
}
return null;
}
function registerCommand(command: Command) {
......@@ -1663,7 +1672,7 @@ class EditorOrNativeTextInputCommand extends Command {
}
// Redirecting to last active editor
let activeEditor = getWorkbenchActiveEditor(accessor);
let activeEditor = getActiveEditor(accessor);
if (activeEditor) {
activeEditor.focus();
return this._runEditorHandler(activeEditor, args);
......
......@@ -18,8 +18,8 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { MenuId, MenuRegistry, IMenuItem } from 'vs/platform/actions/common/actions';
import { ITextEditorService } from 'vs/editor/browser/services/textEditorService';
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ICodeEditorService, getCodeEditor } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
import { ITextModel } from 'vs/editor/common/model';
export type ServicesAccessor = ServicesAccessor;
......@@ -85,10 +85,19 @@ export abstract class Command {
//#region EditorCommand
function getWorkbenchActiveEditor(accessor: ServicesAccessor): ICodeEditor {
function getActiveEditor(accessor: ServicesAccessor): ICodeEditor {
const editorService = accessor.get(ITextEditorService);
let activeEditor = (<any>editorService).getActiveEditor && (<any>editorService).getActiveEditor();
return getCodeEditor(activeEditor);
let activeEditor = editorService.activeTextEditorControl;
if (isCodeEditor(activeEditor)) {
return activeEditor;
}
if (isDiffEditor(activeEditor)) {
return activeEditor.getModifiedEditor();
}
return null;
}
export interface IContributionCommandOptions<T> extends ICommandOptions {
......@@ -128,8 +137,8 @@ export abstract class EditorCommand extends Command {
let editor = codeEditorService.getFocusedCodeEditor();
if (!editor) {
// Fallback to use what the workbench considers the active editor
editor = getWorkbenchActiveEditor(accessor);
// Fallback to use the active editor
editor = getActiveEditor(accessor);
}
if (!editor) {
......
......@@ -8,6 +8,7 @@
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditor } from 'vs/editor/common/editorCommon';
export const ITextEditorService = createDecorator<ITextEditorService>('textEditorService');
......@@ -15,6 +16,11 @@ export interface ITextEditorService {
_serviceBrand: ServiceIdentifier<ITextEditorService>;
/**
* The currently active text editor or `null` if none.
*/
readonly activeTextEditorControl: IEditor;
/**
* Open a text editor.
*/
......
......@@ -100,6 +100,10 @@ export class SimpleEditorService implements ITextEditorService {
this.openEditorDelegate = null;
}
get activeTextEditorControl(): editorCommon.IEditor {
return null;
}
public setEditor(editor: editorCommon.IEditor): void {
this.editor = editor;
}
......
......@@ -18,6 +18,7 @@ suite('OpenerService', function () {
const editorService = new class implements ITextEditorService {
_serviceBrand: any;
activeTextEditorControl: null;
openTextEditor(input: IResourceInput): any {
lastInput = input;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册