Fixes #8133: Expose overwritable commands compositionStart and compositionEnd

This commit is contained in:
Alex Dima 2016-07-15 16:59:01 +03:00
parent 8b7906000e
commit 70a083d54b
6 changed files with 33 additions and 11 deletions

View file

@ -272,6 +272,8 @@ export class KeyboardHandler extends ViewEventHandler implements IDisposable {
// Show the textarea
StyleMutator.setHeight(this.textArea.actual, this._context.configuration.editor.lineHeight);
dom.addClass(this.viewHelper.viewDomNode, 'ime-input');
this.viewController.compositionStart('keyboard');
}));
this._toDispose.push(this.textAreaHandler.onCompositionUpdate((e) => {
@ -291,6 +293,8 @@ export class KeyboardHandler extends ViewEventHandler implements IDisposable {
dom.removeClass(this.viewHelper.viewDomNode, 'ime-input');
this.visibleRange = null;
this.viewController.compositionEnd('keyboard');
}));
this._toDispose.push(GlobalScreenReaderNVDA.onChange((value) => {
this.textAreaHandler.setStrategy(this._getStrategy());

View file

@ -122,6 +122,8 @@ export interface IViewController {
paste(source:string, text:string, pasteOnNewLine:boolean): 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;
emitKeyDown(e:IKeyboardEvent): void;

View file

@ -56,6 +56,14 @@ export class ViewController implements IViewController {
});
}
public compositionStart(source: string): void {
this.commandService.executeCommand(editorCommon.Handler.CompositionStart, {});
}
public compositionEnd(source: string): void {
this.commandService.executeCommand(editorCommon.Handler.CompositionEnd, {});
}
public cut(source:string): void {
this.commandService.executeCommand(editorCommon.Handler.Cut, {});
}

View file

@ -11,6 +11,7 @@ import {IKeybindings, KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {ICommandDescriptor, KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {ICommandHandler} from 'vs/platform/commands/common/commands';
const H = editorCommon.Handler;
@ -69,10 +70,10 @@ function registerCoreCommand(handlerId: string, kb: IKeybindings, weight: number
KeybindingsRegistry.registerCommandDesc(desc);
}
function registerCoreDispatchCommand2(handlerId: string) {
function registerOverwritableCommand(handlerId:string, handler:ICommandHandler): void {
let desc: ICommandDescriptor = {
id: handlerId,
handler: triggerEditorHandler.bind(null, handlerId),
handler: handler,
weight: KeybindingsRegistry.WEIGHT.editorCore(),
when: null,
primary: 0
@ -81,21 +82,24 @@ function registerCoreDispatchCommand2(handlerId: string) {
let desc2: ICommandDescriptor = {
id: 'default:' + handlerId,
handler: (accessor: ServicesAccessor, args: any) => {
withCodeEditorFromCommandHandler(handlerId, accessor, (editor) => {
editor.trigger('keyboard', handlerId, args);
});
},
handler: handler,
weight: KeybindingsRegistry.WEIGHT.editorCore(),
when: null,
primary: 0
};
KeybindingsRegistry.registerCommandDesc(desc2);
}
registerCoreDispatchCommand2(H.Type);
registerCoreDispatchCommand2(H.ReplacePreviousChar);
registerCoreDispatchCommand2(H.Paste);
registerCoreDispatchCommand2(H.Cut);
function registerCoreDispatchCommand(handlerId: string): void {
registerOverwritableCommand(handlerId, triggerEditorHandler.bind(null, handlerId));
}
registerCoreDispatchCommand(H.Type);
registerCoreDispatchCommand(H.ReplacePreviousChar);
registerCoreDispatchCommand(H.Paste);
registerCoreDispatchCommand(H.Cut);
registerOverwritableCommand(H.CompositionStart, () => {});
registerOverwritableCommand(H.CompositionEnd, () => {});
function getMacWordNavigationKB(shift:boolean, key:KeyCode): number {
// For macs, word navigation is based on the alt modifier

View file

@ -4243,6 +4243,8 @@ export var Handler = {
Type: 'type',
ReplacePreviousChar: 'replacePreviousChar',
CompositionStart: 'compositionStart',
CompositionEnd: 'compositionEnd',
Paste: 'paste',
Tab: 'tab',

2
src/vs/monaco.d.ts vendored
View file

@ -3245,6 +3245,8 @@ declare module monaco.editor {
JumpToBracket: string;
Type: string;
ReplacePreviousChar: string;
CompositionStart: string;
CompositionEnd: string;
Paste: string;
Tab: string;
Indent: string;