Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract isUndo, isRedo into UndoRedo model #1205

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/app/core/models/undoredo.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ export class UndoRedo<T> {
this.intervalTime = intervalTime;
}

public static isUndo(event: KeyboardEvent) {
// prevents undo from firing when ctrl shift z is pressed
if (navigator.platform.indexOf('Mac') === 0) {
return event.metaKey && event.code === 'KeyZ' && !event.shiftKey;
}
return event.ctrlKey && event.code === 'KeyZ' && !event.shiftKey;
}

public static isRedo(event: KeyboardEvent) {
if (navigator.platform.indexOf('Mac') === 0) {
return event.metaKey && event.shiftKey && event.code === 'KeyZ';
}
return (event.ctrlKey && event.shiftKey && event.code === 'KeyZ') || (event.ctrlKey && event.code === 'KeyY');
}

/**
* Function to be called right before a change is made / stores the latest last state
* preferably to be called with "beforeinput" event
Expand Down
19 changes: 2 additions & 17 deletions src/app/shared/comment-editor/comment-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class CommentEditorComponent implements OnInit {
}

onKeyPress(event: KeyboardEvent) {
if (this.isUndo(event)) {
if (UndoRedo.isUndo(event)) {
event.preventDefault();
this.undo();
return;
} else if (this.isRedo(event)) {
} else if (UndoRedo.isRedo(event)) {
this.redo();
event.preventDefault();
return;
Expand Down Expand Up @@ -347,21 +347,6 @@ export class CommentEditorComponent implements OnInit {
return event.ctrlKey;
}

private isUndo(event: KeyboardEvent) {
// prevents undo from firing when ctrl shift z is pressed
if (navigator.platform.indexOf('Mac') === 0) {
return event.metaKey && event.code === 'KeyZ' && !event.shiftKey;
}
return event.ctrlKey && event.code === 'KeyZ' && !event.shiftKey;
}

private isRedo(event: KeyboardEvent) {
if (navigator.platform.indexOf('Mac') === 0) {
return event.metaKey && event.shiftKey && event.code === 'KeyZ';
}
return (event.ctrlKey && event.shiftKey && event.code === 'KeyZ') || (event.ctrlKey && event.code === 'KeyY');
}

private insertOrRemoveCharsFromHighlightedText(char) {
const selectionStart = this.commentTextArea.nativeElement.selectionStart;
const selectionEnd = this.commentTextArea.nativeElement.selectionEnd;
Expand Down
Loading