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

[SuperEditor][Web] Prevent Cmd + Z and Ctrl + Z shortcuts from bubbling up (Resolves #2060) #2065

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor][Web] Prevent Cmd + Z and Ctrl + Z shortcuts from bubbling up. Resolves #2060

On Web, deleting a portion of a paragraph and then pressing the undo shortcut crashes the editor with the following exception:

══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
The following assertion was thrown during method call TextInputClient.updateEditingStateWithDeltas:
Assertion failed:
file:///Users/angelosilvestre/dev/flutter/packages/flutter/lib/src/services/text_editing_delta.dart:129:14
_debugTextRangeIsValid(newSelection, oldText)
"The selection range: TextSelection(baseOffset: 30, extentOffset: 104, isDirectional: false) is not
within the bounds of text: . Super Editor is a toolkit to of length: 30"

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3        assertFailed
packages/flutter/src/services/text_editing_delta.dart 129:58                      fromJSON
packages/flutter/src/services/text_input.dart 1900:30                             <fn>
packages/flutter/src/services/text_input.dart 1900:51                             _handleTextInputInvocation
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/flutter/src/services/text_input.dart 1809:45                             [_handleTextInputInvocation]
packages/flutter/src/services/text_input.dart 1794:20                             _loudlyHandleTextInputInvocation
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/flutter/src/services/text_input.dart 1792:51                             [_loudlyHandleTextInputInvocation]
packages/flutter/src/services/platform_channel.dart 571:55                        _handleAsMethodCall
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/flutter/src/services/platform_channel.dart 568:40                        [_handleAsMethodCall]
packages/flutter/src/services/platform_channel.dart 564:34                        <fn>
packages/flutter/src/services/binding.dart 576:35                                 <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
packages/flutter/src/services/binding.dart 573:98                                 <fn>
lib/_engine/engine/platform_dispatcher.dart 1436:5                                invoke2
lib/ui/channel_buffers.dart 25:12                                                 invoke
lib/ui/channel_buffers.dart 65:7                                                  push
lib/ui/channel_buffers.dart 131:16                                                push
lib/_engine/engine/platform_dispatcher.dart 468:10                                invokeOnPlatformMessage
lib/_engine/engine/text_editing/text_editing.dart 2256:30                         updateEditingStateWithDelta
lib/_engine/engine/text_editing/text_editing.dart 2363:11                         <fn>
lib/_engine/engine/text_editing/text_editing.dart 1450:7                          handleChange
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 426:37  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 431:39  dcall

call:
  MethodCall(TextInputClient.updateEditingStateWithDeltas, [1, {deltas: [{oldText: . Super Editor is
  a toolkit to, deltaText: , deltaStart: -1, deltaEnd: -1, selectionBase: 30, selectionExtent: 104,
  composingBase: -1, composingExtent: -1}]}])
════════════════════════════════════════════════════════════════════════════════════════════════════

The issue is that Flutter Web uses the browser HTML input to handle the text input and this input responds to the undo shortcut.

This PR prevents the Cmd + Z and Ctrl + Z shortcuts from bubbling up, so they are not handled by the HTML input.

To be able to effectively test this, I think we would need integration tests.

Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@matthew-carroll matthew-carroll merged commit 048c761 into main Jun 1, 2024
11 checks passed
@matthew-carroll matthew-carroll deleted the 2060_prevent-cmd-z-from-bubbling-up branch June 1, 2024 01:09
github-actions bot pushed a commit that referenced this pull request Jun 1, 2024
quaaantumdev pushed a commit to quaaantumdev/super_editor that referenced this pull request Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web] CMD+Z causing exception and blocking the editor
2 participants