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] Fix selection change with CMD + RIGHT (Resolves #2304) #2327

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor][Web] Fix selection change with CMD + RIGHT. Resolves #2304

Steps to reproduce:

  1. Run the example app with Chrome
  2. Place cursor on the beginning of the line "To get started with your own editing experience, take the following steps:"
  3. Press CMD+Right arrow

Expected: Cursor is placed at the end of the line, Actual: Cursor is placed at the beginning of the word "steps"

This wrong offset is being reported by the selection change delta. On web, Flutter relies on html inputs to handle text input. When the user presses CMD + RIGHT, the browser moves the selection to where it thinks the end of the line is, and the Flutter code generates text deltas for us.

I haven't dug deep into this, but this seems our text layout and the browser text layout are different. For example, in the repro text, the browser thinks the line ends before "steps".

We started handling deltas for moving the caret with the arrow keys in #1269. I think I failed to document why we need to let the IME generate non-text deltas for this. However, I tested the issues reported in the original ticket (#1224) and I wasn't able to reproduce any of them.

This PR changes doNothingWithLeftRightArrowKeysAtMiddleOfTextOnWeb to avoid sending the key event back to the OS if CMD is pressed.

The ideal solution would be to investigate why our line breaks are different from the browser line breaks, but this will require a deeper investigation.

As a reference, in our "Regular Flutter TextField Demo", if we limit the width of the Flutter TextField to 400px, we can also see the caret moving to the wrong position.

@angelosilvestre
Copy link
Collaborator Author

Playing around a bit with the css flutter generates, it seems that the html input does end the line before "steps" (red is the html input text):

image

@matthew-carroll
Copy link
Contributor

This probably shouldn't be too surprising that this happens given that Flutter uses a different text layout implementation than the browser.

Can you file an issue with Flutter?

Also, did you test jumping by word to see if that's broken in a similar way?

@@ -635,6 +635,20 @@ ExecutionInstruction doNothingWithLeftRightArrowKeysAtMiddleOfTextOnWeb({
return ExecutionInstruction.continueExecution;
}

if ((CurrentPlatform.isApple && HardwareKeyboard.instance.isMetaPressed) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than have this blocking handler know about certain key combo exceptions, can you just move or replicate the relevant key combo above this one in the priority list, along with a comment about why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean to have a moveToStartOrEndOfLineWithArrowKeysOnWeb ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the specifics, because I don't know which handlers this one is currently blocking, but the name you mentioned seems to make sense. If we had such a handler higher up in priority, instead of blocking logic, would it still fix the issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a new handler for that.

@angelosilvestre
Copy link
Collaborator Author

Can you file an issue with Flutter?

I'll try to make a repo.

Also, did you test jumping by word to see if that's broken in a similar way?

Jumping by word looks fine.

if (!arrowKeys.contains(keyEvent.logicalKey)) {
return ExecutionInstruction.continueExecution;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check for any other control keys, like Option? A quick check of cmd+option+arrow shows that something else happens in my browser. It doesn't move my cursor. Instead, it seems to switch browser tabs...

Copy link
Collaborator Author

@angelosilvestre angelosilvestre Oct 12, 2024

Choose a reason for hiding this comment

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

I tried in chrome and pressing cmd + option + arrow doesn't hit this handler. The browser switches tabs as expected.

Maybe the browser is handling the shortcut before us and prevent the event?

@angelosilvestre
Copy link
Collaborator Author

Updated the PR to prevent moving between nodes with CMD + LEFT/RIGHT arrow as discussed in the original ticket.

@@ -1616,6 +1616,58 @@ This is a paragraph
),
);
});

testWidgetsOnApple('with CMD + LEFT ARROW at the beginning of a paragraph', (tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests verify that CMD + LEFT ARROW do nothing "at the beginning of the paragraph" and the right arrow does nothing "at the end of the paragraph".

I'm confused by this.

CMD + LEFT/RIGHT ARROW should do nothing on Linux ever. Not just at the beginning and end of lines.

It's on a Mac that they should do nothing at the beginning/end of lines.

Also, isn't this ticket about web? If so, shouldn't the new tests simulate web, and reference web?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CMD + LEFT/RIGHT ARROW should do nothing on Linux ever. Not just at the beginning and end of lines.

But we are not running on Linux, we are running on Apple Devices. I create a testWidgetsOnMacDesktopAndWeb that might be more appropriate here.

Also, isn't this ticket about web? If so, shouldn't the new tests simulate web, and reference web?

Yes, but in this comment Brian agreed that we should keep this behavior consistent for web and desktop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't these tests declared inside of a "Linux" group?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't notice that. Moved to "Mac and iOS >" group.

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

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.

[BUG] [MacOS + Web] - CMD+Left/Right arrow does not move selection correctly
2 participants