提交 e9b79682 编写于 作者: A Alex Dima

Dispatch typing, replace previous char, pasting and cutting through keybinding service

上级 7e9e05bb
......@@ -10,41 +10,49 @@ import {Position} from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {Configuration} from 'vs/editor/browser/config/configuration';
import {IEditorMouseEvent, IViewController, IMouseDispatchData} from 'vs/editor/browser/editorBrowser';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
export class ViewController implements IViewController {
private viewModel:editorCommon.IViewModel;
private configuration:Configuration;
private outgoingEventBus:IEventEmitter;
constructor(viewModel:editorCommon.IViewModel, configuration:Configuration, outgoingEventBus:IEventEmitter) {
private keybindingService:IKeybindingService;
constructor(
viewModel:editorCommon.IViewModel,
configuration:Configuration,
outgoingEventBus:IEventEmitter,
keybindingService:IKeybindingService
) {
this.viewModel = viewModel;
this.configuration = configuration;
this.outgoingEventBus = outgoingEventBus;
this.keybindingService = keybindingService;
}
public paste(source:string, text:string, pasteOnNewLine:boolean): void {
this.configuration.handlerDispatcher.trigger(source, editorCommon.Handler.Paste, {
this.keybindingService.executeCommand(editorCommon.Handler.DispatchPaste, {
text: text,
pasteOnNewLine: pasteOnNewLine,
});
}
public type(source:string, text:string): void {
this.configuration.handlerDispatcher.trigger(source, editorCommon.Handler.Type, {
this.keybindingService.executeCommand(editorCommon.Handler.DispatchType, {
text: text
});
}
public replacePreviousChar(source: string, text: string, replaceCharCnt:number): void {
this.configuration.handlerDispatcher.trigger(source, editorCommon.Handler.ReplacePreviousChar, {
this.keybindingService.executeCommand(editorCommon.Handler.DispatchReplacePreviousChar, {
text: text,
replaceCharCnt: replaceCharCnt
});
}
public cut(source:string): void {
this.configuration.handlerDispatcher.trigger(source, editorCommon.Handler.Cut, null);
this.keybindingService.executeCommand(editorCommon.Handler.DispatchCut, {});
}
private _validateViewColumn(viewPosition:editorCommon.IEditorPosition): editorCommon.IEditorPosition {
......
......@@ -90,7 +90,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
this._renderAnimationFrame = null;
this.outgoingEventBus = new EventEmitter();
var viewController = new ViewController(model, configuration, this.outgoingEventBus);
var viewController = new ViewController(model, configuration, this.outgoingEventBus, keybindingService);
this.listenersToRemove = [];
this.listenersToDispose = [];
......
......@@ -12,6 +12,8 @@ import {ICommandDescriptor, KeybindingsRegistry} from 'vs/platform/keybinding/co
import * as editorCommon from 'vs/editor/common/editorCommon';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
const H = editorCommon.Handler;
export function findFocusedEditor(commandId: string, accessor: ServicesAccessor, args: any, complain: boolean): editorCommon.ICommonCodeEditor {
var codeEditorService = accessor.get(ICodeEditorService);
var editorId = args.context.editorId;
......@@ -60,7 +62,7 @@ function triggerEditorHandler(handlerId: string, accessor: ServicesAccessor, arg
});
}
function registerCoreCommand(handlerId: string, kb: IKeybindings, weight: number = KeybindingsRegistry.WEIGHT.editorCore(), context?: KbExpr) {
function registerCoreCommand(handlerId: string, kb: IKeybindings, weight: number = KeybindingsRegistry.WEIGHT.editorCore(), context?: KbExpr): void {
var desc: ICommandDescriptor = {
id: handlerId,
handler: triggerEditorHandler.bind(null, handlerId),
......@@ -75,6 +77,21 @@ function registerCoreCommand(handlerId: string, kb: IKeybindings, weight: number
KeybindingsRegistry.registerCommandDesc(desc);
}
function registerCoreDispatchCommand(dispatchId: string, handlerId: string) {
var desc: ICommandDescriptor = {
id: dispatchId,
handler: triggerEditorHandler.bind(null, handlerId),
weight: KeybindingsRegistry.WEIGHT.editorCore(),
context: null,
primary: 0
};
KeybindingsRegistry.registerCommandDesc(desc);
}
registerCoreDispatchCommand(H.DispatchType, H.Type);
registerCoreDispatchCommand(H.DispatchReplacePreviousChar, H.ReplacePreviousChar);
registerCoreDispatchCommand(H.DispatchPaste, H.Paste);
registerCoreDispatchCommand(H.DispatchCut, H.Cut);
function getMacWordNavigationKB(shift:boolean, key:KeyCode): number {
// For macs, word navigation is based on the alt modifier
if (shift) {
......@@ -93,8 +110,6 @@ function getWordNavigationKB(shift:boolean, key:KeyCode): number {
}
}
var H = editorCommon.Handler;
// https://support.apple.com/en-gb/HT201236
// [ADDED] Control-H Delete the character to the left of the insertion point. Or use Delete.
// [ADDED] Control-D Delete the character to the right of the insertion point. Or use Fn-Delete.
......
......@@ -3356,8 +3356,11 @@ export var Handler = {
JumpToBracket: 'jumpToBracket',
DispatchType: 'dispatchType',
Type: 'type',
DispatchReplacePreviousChar:'dispatchReplacePreviousChar',
ReplacePreviousChar: 'replacePreviousChar',
DispatchPaste: 'dispatchPaste',
Paste: 'paste',
Tab: 'tab',
......@@ -3375,6 +3378,7 @@ export var Handler = {
RemoveSecondaryCursors: 'removeSecondaryCursors',
CancelSelection: 'cancelSelection',
DispatchCut: 'dispatchCut',
Cut: 'cut',
Undo: 'undo',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册