diff --git a/extraterm/src/render_process/emulator/Term.ts b/extraterm/src/render_process/emulator/Term.ts index 5af856ca5..db9f69073 100644 --- a/extraterm/src/render_process/emulator/Term.ts +++ b/extraterm/src/render_process/emulator/Term.ts @@ -2190,6 +2190,11 @@ export class Emulator implements EmulatorApi { const isMac = platform === "darwin"; let key: string = null; + if (ev.isComposing) { + // Electron on macOS reports key events even when the IME menu is shown. + return null; + } + let altKey = ev.altKey; let ctrlKey = ev.ctrlKey; diff --git a/extraterm/src/render_process/keybindings/KeyBindingsManager.ts b/extraterm/src/render_process/keybindings/KeyBindingsManager.ts index 0343a7ad7..348a9d893 100644 --- a/extraterm/src/render_process/keybindings/KeyBindingsManager.ts +++ b/extraterm/src/render_process/keybindings/KeyBindingsManager.ts @@ -35,7 +35,8 @@ export class Keybinding implements TermMinimalKeyboardEvent { readonly configKey: string; readonly configKeyLowercase: string; private _humanReadableString: string = null; - + readonly isComposing: boolean = false; + constructor(options: KeybindingOptions) { this.altKey = options.altKey; this.ctrlKey = options.ctrlKey; diff --git a/extraterm/src/render_process/keybindings/KeyBindingsManagerTest.ts b/extraterm/src/render_process/keybindings/KeyBindingsManagerTest.ts index 61154214b..00a174970 100644 --- a/extraterm/src/render_process/keybindings/KeyBindingsManagerTest.ts +++ b/extraterm/src/render_process/keybindings/KeyBindingsManagerTest.ts @@ -62,27 +62,27 @@ export function testMapEventToCommand(test: nodeunit.Test): void { const cutsContexts = KeybindingsManager.loadKeybindingsFromObject(keyBindingsMap, "linux"); const editorKeybindings = cutsContexts.context("editor"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "o", keyCode: keyCode("o") }), "open"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: " ", keyCode: keyCode(" ") }), "togglemode"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "+", keyCode: keyCode("+") }), "zoom"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: true, ctrlKey: false, metaKey: true, shiftKey: true, key: "A", keyCode: keyCode("A",false) }), "all"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: " ", keyCode: keyCode(" ",false) }), "makespace"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: true, ctrlKey: false, metaKey: false, shiftKey: true, key: "S", keyCode: keyCode("S",false) }), "smeg"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: true, key: "W", keyCode: keyCode("W") }), "closewindow"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: true, key: "Z", keyCode: keyCode("Z",false) }), "sleep"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "PageUp", keyCode: keyCode("PageUp",false) }), "pageup"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "Home", keyCode: keyCode("Home",false) }), "gohome"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "Home", keyCode: keyCode("Home",false) }), "gohome"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: true, ctrlKey: false, metaKey: false, shiftKey: false, key: "Tab", keyCode: keyCode("Tab",false) }), "dedent"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "End", keyCode: keyCode("End",false) }), "finish"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowUp", keyCode: keyCode("ArrowUp",false) }), "up"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowDown", keyCode: keyCode("ArrowDown",false) }), "down"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "F2", keyCode: keyCode("F2",false) }), "rename"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: true, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowLeft", keyCode: keyCode("ArrowLeft",false) }), "select-left"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "Tab", keyCode: 9 }), "otherpane"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "c", keyCode: 67 }), "break"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: false, ctrlKey: true, metaKey: false, shiftKey: true, key: "C", keyCode: 67 }), "bigbreak"); - test.equal(editorKeybindings.mapEventToCommand({ altKey: true, ctrlKey: true, metaKey: false, shiftKey: false, key: ".", keyCode: 190 }), "moveTabRight"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "o", keyCode: keyCode("o") }), "open"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: " ", keyCode: keyCode(" ") }), "togglemode"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "+", keyCode: keyCode("+") }), "zoom"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: true, ctrlKey: false, metaKey: true, shiftKey: true, key: "A", keyCode: keyCode("A",false) }), "all"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: " ", keyCode: keyCode(" ",false) }), "makespace"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: true, ctrlKey: false, metaKey: false, shiftKey: true, key: "S", keyCode: keyCode("S",false) }), "smeg"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: true, key: "W", keyCode: keyCode("W") }), "closewindow"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: true, key: "Z", keyCode: keyCode("Z",false) }), "sleep"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "PageUp", keyCode: keyCode("PageUp",false) }), "pageup"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "Home", keyCode: keyCode("Home",false) }), "gohome"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "Home", keyCode: keyCode("Home",false) }), "gohome"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: true, ctrlKey: false, metaKey: false, shiftKey: false, key: "Tab", keyCode: keyCode("Tab",false) }), "dedent"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "End", keyCode: keyCode("End",false) }), "finish"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowUp", keyCode: keyCode("ArrowUp",false) }), "up"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowDown", keyCode: keyCode("ArrowDown",false) }), "down"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, key: "F2", keyCode: keyCode("F2",false) }), "rename"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: true, ctrlKey: false, metaKey: false, shiftKey: false, key: "ArrowLeft", keyCode: keyCode("ArrowLeft",false) }), "select-left"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "Tab", keyCode: 9 }), "otherpane"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: false, key: "c", keyCode: 67 }), "break"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: false, ctrlKey: true, metaKey: false, shiftKey: true, key: "C", keyCode: 67 }), "bigbreak"); + test.equal(editorKeybindings.mapEventToCommand({ isComposing: false, altKey: true, ctrlKey: true, metaKey: false, shiftKey: false, key: ".", keyCode: 190 }), "moveTabRight"); test.done(); } diff --git a/extraterm/src/typings/extra_lib.d.ts b/extraterm/src/typings/extra_lib.d.ts index 9941495ab..50de20a64 100644 --- a/extraterm/src/typings/extra_lib.d.ts +++ b/extraterm/src/typings/extra_lib.d.ts @@ -92,6 +92,10 @@ interface KeyboardEventInit { which?: number; } +interface KeyboardEvent { + isComposing: boolean; +} + interface Event { path: Node[]; // <- obsolete. Removed from later the Shadow DOM spec. encapsulated: boolean; diff --git a/packages/term-api/src/TermApi.ts b/packages/term-api/src/TermApi.ts index 5103cd08a..37ae3d5cf 100644 --- a/packages/term-api/src/TermApi.ts +++ b/packages/term-api/src/TermApi.ts @@ -173,6 +173,7 @@ export interface MinimalKeyboardEvent { metaKey: boolean; shiftKey: boolean; key: string; + isComposing: boolean; }