Skip to content

Commit

Permalink
fix detecting undo/redo
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Apr 4, 2020
1 parent 8d0a522 commit a0f316e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions codejar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class CodeJar {
}
}

handleUndoRedo(event: KeyboardEvent) {
private handleUndoRedo(event: KeyboardEvent) {
if (isUndo(event)) {
event.preventDefault()
this.at--
Expand All @@ -286,7 +286,7 @@ export class CodeJar {
}
}

recordHistory() {
private recordHistory() {
if (!this.focus) return

const html = this.editor.innerHTML
Expand Down Expand Up @@ -343,12 +343,16 @@ export class CodeJar {
}
}

function isCtrl(event: KeyboardEvent) {
return event.metaKey || event.ctrlKey
}

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

function isRedo(event: KeyboardEvent) {
return event.metaKey && event.shiftKey && event.code === "KeyZ"
return isCtrl(event) && event.shiftKey && event.code === "KeyZ"
}

type HistoryRecord = {
Expand Down

0 comments on commit a0f316e

Please sign in to comment.