Skip to content

Commit

Permalink
Don't process key strokes which occur during key composion on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Dec 8, 2018
1 parent 65efe86 commit 88c8977
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
5 changes: 5 additions & 0 deletions extraterm/src/render_process/emulator/Term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 21 additions & 21 deletions extraterm/src/render_process/keybindings/KeyBindingsManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions extraterm/src/typings/extra_lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/term-api/src/TermApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface MinimalKeyboardEvent {
metaKey: boolean;
shiftKey: boolean;
key: string;
isComposing: boolean;
}


Expand Down

0 comments on commit 88c8977

Please sign in to comment.