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

Cherry Pick: [SuperEditor][Web] Prevent Cmd + Z and Ctrl + Z shortcuts from bubbling up (Resolves #2060) #2068

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
30 changes: 30 additions & 0 deletions super_editor/lib/src/default_editor/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,36 @@ ExecutionInstruction doNothingWithBackspaceOnWeb({
return ExecutionInstruction.continueExecution;
}

ExecutionInstruction doNothingWithCtrlOrCmdAndZOnWeb({
required SuperEditorContext editContext,
required KeyEvent keyEvent,
}) {
if (keyEvent is! KeyDownEvent && keyEvent is! KeyRepeatEvent) {
return ExecutionInstruction.continueExecution;
}

if (keyEvent.logicalKey != LogicalKeyboardKey.keyZ) {
return ExecutionInstruction.continueExecution;
}

if (CurrentPlatform.isApple && !HardwareKeyboard.instance.isMetaPressed) {
return ExecutionInstruction.continueExecution;
}

if (!CurrentPlatform.isApple && !HardwareKeyboard.instance.isControlPressed) {
return ExecutionInstruction.continueExecution;
}

if (CurrentPlatform.isWeb) {
// On web, pressing Cmd + Z on Mac or Ctrl + Z on Windows and Linux
// triggers the UNDO action of the HTML text input, which doesn't work for us.
// Prevent the browser from handling the shortcut.
return ExecutionInstruction.haltExecution;
}

return ExecutionInstruction.continueExecution;
}

ExecutionInstruction doNothingWithDeleteOnWeb({
required SuperEditorContext editContext,
required KeyEvent keyEvent,
Expand Down
1 change: 1 addition & 0 deletions super_editor/lib/src/default_editor/super_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ final defaultImeKeyboardActions = <DocumentKeyboardAction>[
cmdBToToggleBold,
cmdIToToggleItalics,
doNothingWithBackspaceOnWeb,
doNothingWithCtrlOrCmdAndZOnWeb,
backspaceToConvertTaskToParagraph,
backspaceToUnIndentListItem,
backspaceToClearParagraphBlockType,
Expand Down
Loading