提交 17a6e236 编写于 作者: I isidor

introduce simple widget editor. Use a command delegate so extensions do not intercept commands

上级 344e93c6
......@@ -24,7 +24,7 @@ export class CodeEditor extends CodeEditorWidget {
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService
) {
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
}
protected _getContributions(): IEditorContributionCtor[] {
......
......@@ -7,9 +7,7 @@
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { Position } from 'vs/editor/common/core/position';
import { Selection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import { CoreNavigationCommands, CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
......@@ -35,26 +33,35 @@ export interface IMouseDispatchData {
shiftKey: boolean;
}
export interface ICommandDelegate {
paste(source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[]): void;
type(source: string, text: string): void;
replacePreviousChar(source: string, text: string, replaceCharCnt: number): void;
compositionStart(source: string): void;
compositionEnd(source: string): void;
cut(source: string): void;
}
export class ViewController {
private readonly configuration: Configuration;
private readonly viewModel: IViewModel;
private readonly _execCoreEditorCommandFunc: ExecCoreEditorCommandFunc;
private readonly outgoingEvents: ViewOutgoingEvents;
private readonly commandService: ICommandService;
private readonly commandDelegate: ICommandDelegate;
constructor(
configuration: Configuration,
viewModel: IViewModel,
execCommandFunc: ExecCoreEditorCommandFunc,
outgoingEvents: ViewOutgoingEvents,
commandService: ICommandService
commandDelegate: ICommandDelegate
) {
this.configuration = configuration;
this.viewModel = viewModel;
this._execCoreEditorCommandFunc = execCommandFunc;
this.outgoingEvents = outgoingEvents;
this.commandService = commandService;
this.commandDelegate = commandDelegate;
}
private _execMouseCommand(editorCommand: CoreEditorCommand, args: any): void {
......@@ -63,36 +70,27 @@ export class ViewController {
}
public paste(source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[]): void {
this.commandService.executeCommand(editorCommon.Handler.Paste, {
text: text,
pasteOnNewLine: pasteOnNewLine,
multicursorText: multicursorText
});
this.commandDelegate.paste(source, text, pasteOnNewLine, multicursorText);
}
public type(source: string, text: string): void {
this.commandService.executeCommand(editorCommon.Handler.Type, {
text: text
});
this.commandDelegate.type(source, text);
}
public replacePreviousChar(source: string, text: string, replaceCharCnt: number): void {
this.commandService.executeCommand(editorCommon.Handler.ReplacePreviousChar, {
text: text,
replaceCharCnt: replaceCharCnt
});
this.commandDelegate.replacePreviousChar(source, text, replaceCharCnt);
}
public compositionStart(source: string): void {
this.commandService.executeCommand(editorCommon.Handler.CompositionStart, {});
this.commandDelegate.compositionStart(source);
}
public compositionEnd(source: string): void {
this.commandService.executeCommand(editorCommon.Handler.CompositionEnd, {});
this.commandDelegate.compositionEnd(source);
}
public cut(source: string): void {
this.commandService.executeCommand(editorCommon.Handler.Cut, {});
this.commandDelegate.cut(source);
}
public setSelection(source: string, modelSelection: Selection): void {
......
......@@ -8,14 +8,13 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { Range } from 'vs/editor/common/core/range';
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { TextAreaHandler, ITextAreaHandlerHelper } from 'vs/editor/browser/controller/textAreaHandler';
import { PointerHandler } from 'vs/editor/browser/controller/pointerHandler';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { ViewController, ExecCoreEditorCommandFunc } from 'vs/editor/browser/view/viewController';
import { ViewController, ExecCoreEditorCommandFunc, ICommandDelegate } from 'vs/editor/browser/view/viewController';
import { ViewEventDispatcher } from 'vs/editor/common/view/viewEventDispatcher';
import { ContentViewOverlays, MarginViewOverlays } from 'vs/editor/browser/view/viewOverlays';
import { ViewContentWidgets } from 'vs/editor/browser/viewParts/contentWidgets/contentWidgets';
......@@ -93,7 +92,7 @@ export class View extends ViewEventHandler {
private _renderAnimationFrame: IDisposable;
constructor(
commandService: ICommandService,
commandDelegate: ICommandDelegate,
configuration: Configuration,
themeService: IThemeService,
model: IViewModel,
......@@ -105,7 +104,7 @@ export class View extends ViewEventHandler {
this._renderAnimationFrame = null;
this.outgoingEvents = new ViewOutgoingEvents(model);
let viewController = new ViewController(configuration, model, execCoreEditorCommandFunc, this.outgoingEvents, commandService);
let viewController = new ViewController(configuration, model, execCoreEditorCommandFunc, this.outgoingEvents, commandDelegate);
// The event dispatcher will always go through _renderOnce before dispatching any events
this.eventDispatcher = new ViewEventDispatcher((callback: () => void) => this._renderOnce(callback));
......
......@@ -33,6 +33,7 @@ import { Color } from 'vs/base/common/color';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { ClassName } from 'vs/editor/common/model/intervalTree';
import { ITextModel, IModelDecorationOptions } from 'vs/editor/common/model';
import { ICommandDelegate } from '../view/viewController';
export abstract class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.ICodeEditor {
......@@ -86,13 +87,14 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
constructor(
domElement: HTMLElement,
options: IEditorOptions,
isSimpleWidget: boolean,
@IInstantiationService instantiationService: IInstantiationService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@ICommandService commandService: ICommandService,
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService
) {
super(domElement, options, instantiationService, contextKeyService);
super(domElement, options, isSimpleWidget, instantiationService, contextKeyService);
this._codeEditorService = codeEditorService;
this._commandService = commandService;
this._themeService = themeService;
......@@ -358,8 +360,62 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
}
protected _createView(): void {
let commandDelegate: ICommandDelegate;
if (this.isSimpleWidget) {
commandDelegate = {
paste: (source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[]) => {
this.cursor.trigger(source, editorCommon.Handler.Paste, { text, pasteOnNewLine, multicursorText });
},
type: (source: string, text: string) => {
this.cursor.trigger(source, editorCommon.Handler.Type, { text });
},
replacePreviousChar: (source: string, text: string, replaceCharCnt: number) => {
this.cursor.trigger(source, editorCommon.Handler.ReplacePreviousChar, { text, replaceCharCnt });
},
compositionStart: (source: string) => {
this.cursor.trigger(source, editorCommon.Handler.CompositionStart, undefined);
},
compositionEnd: (source: string) => {
this.cursor.trigger(source, editorCommon.Handler.CompositionEnd, undefined);
},
cut: (source: string) => {
this.cursor.trigger(source, editorCommon.Handler.Cut, undefined);
}
};
} else {
commandDelegate = {
paste: (source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[]) => {
this._commandService.executeCommand(editorCommon.Handler.Paste, {
text: text,
pasteOnNewLine: pasteOnNewLine,
multicursorText: multicursorText
});
},
type: (source: string, text: string) => {
this._commandService.executeCommand(editorCommon.Handler.Type, {
text: text
});
},
replacePreviousChar: (source: string, text: string, replaceCharCnt: number) => {
this._commandService.executeCommand(editorCommon.Handler.ReplacePreviousChar, {
text: text,
replaceCharCnt: replaceCharCnt
});
},
compositionStart: (source: string) => {
this._commandService.executeCommand(editorCommon.Handler.CompositionStart, {});
},
compositionEnd: (source: string) => {
this._commandService.executeCommand(editorCommon.Handler.CompositionEnd, {});
},
cut: (source: string) => {
this._commandService.executeCommand(editorCommon.Handler.Cut, {});
}
};
}
this._view = new View(
this._commandService,
commandDelegate,
this._configuration,
this._themeService,
this.viewModel,
......
......@@ -93,6 +93,7 @@ export abstract class CommonCodeEditor extends Disposable {
protected readonly domElement: IContextKeyServiceTarget;
protected readonly id: number;
protected readonly _configuration: CommonEditorConfiguration;
protected readonly isSimpleWidget: boolean;
protected _contributions: { [key: string]: editorCommon.IEditorContribution; };
protected _actions: { [key: string]: editorCommon.IEditorAction; };
......@@ -118,6 +119,7 @@ export abstract class CommonCodeEditor extends Disposable {
constructor(
domElement: IContextKeyServiceTarget,
options: editorOptions.IEditorOptions,
isSimpleWidget: boolean,
instantiationService: IInstantiationService,
contextKeyService: IContextKeyService
) {
......@@ -126,6 +128,7 @@ export abstract class CommonCodeEditor extends Disposable {
this.id = (++EDITOR_ID);
this._decorationTypeKeysToIds = {};
this._decorationTypeSubtypes = {};
this.isSimpleWidget = isSimpleWidget;
options = options || {};
this._configuration = this._register(this._createConfiguration(options));
......
......@@ -37,7 +37,7 @@ function createMockEditor(model: TextModel): TestCodeEditor {
[IStorageService, NullStorageService]
));
const editor = new TestCodeEditor(new MockScopeLocation(), {}, instantiationService, contextKeyService);
const editor = new TestCodeEditor(new MockScopeLocation(), {}, false, instantiationService, contextKeyService);
editor.setModel(model);
return editor;
}
......
......@@ -173,7 +173,7 @@ function _createTestCodeEditor(options: TestCodeEditorCreationOptions): TestCode
services.set(IContextKeyService, contextKeyService);
let instantiationService = new InstantiationService(services);
let editor = new TestCodeEditor(new MockScopeLocation(), options, instantiationService, contextKeyService);
let editor = new TestCodeEditor(new MockScopeLocation(), options, false, instantiationService, contextKeyService);
editor.setModel(options.model);
return editor;
}
......@@ -30,7 +30,7 @@ export class ReplInputEditor extends CodeEditorWidget {
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService
) {
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
super(domElement, options, true, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
}
protected _getContributions(): IEditorContributionCtor[] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册