Skip to content

Commit

Permalink
Fix undo/redo not working on other keyboard layouts (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp authored Feb 27, 2023
1 parent 45e3041 commit 999efb0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,19 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: P
}

function isUndo(event: KeyboardEvent) {
return isCtrl(event) && !event.shiftKey && event.code === 'KeyZ'
return isCtrl(event) && !event.shiftKey && getKeyCode(event) === "Z"
}

function isRedo(event: KeyboardEvent) {
return isCtrl(event) && event.shiftKey && event.code === 'KeyZ'
return isCtrl(event) && event.shiftKey && getKeyCode(event) === "Z";
}

function getKeyCode(event: KeyboardEvent): string | undefined{
let key = (event.key || event.keyCode || event.which);
if (!key) {
return undefined;
}
return ((typeof key === "string") ? key : String.fromCharCode(key)).toUpperCase();
}

function insert(text: string) {
Expand Down

0 comments on commit 999efb0

Please sign in to comment.