-
Notifications
You must be signed in to change notification settings - Fork 285
Fix/issue 2593 cursor resets to end of paragraph after paste #2814
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
base: main
Are you sure you want to change the base?
Fix/issue 2593 cursor resets to end of paragraph after paste #2814
Conversation
…mple text (without newlines) in the middle of a paragraph
…ulting in correct selection
|
Adding to this: The two failing tests are both unrelated. |
| // The user only pasted content without any newlines in it. Place the | ||
| // caret in the existing node at the end of the pasted text. This is | ||
| // guaranteed to be a TextNode. | ||
| documentPositionAfterPaste = DocumentPosition( | ||
| nodeId: _pastePosition.nodeId, | ||
| nodePosition: TextNodePosition( | ||
| offset: | ||
| pasteTextOffset + (_parsedContent!.first as TextNode).text.length, | ||
| ), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we only support pasting TextNodes now, but I believe it would be better to explicitly check if the node is a TextNode before entering this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it's about the pasted node, yes? Alright, I changed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's about _parsedContent!.first.
super_editor/lib/src/default_editor/common_editor_operations.dart
Outdated
Show resolved
Hide resolved
| expect(selection, isNotNull); | ||
| expect(selection!.isCollapsed, isTrue); | ||
| expect((selection.base.nodePosition as TextNodePosition).offset, 24); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manually checking different properties I believe it would me more consistent with the repo's style if you use the selectionEquivalentTo method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I should get acquainted to those, thanks, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to push it? It doesn't seem it was changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, pushed to my fork, now synced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @JostSchenck. Thanks for the PR. I left a few comments.
… single-node content; slight reformatting to repo standard line length; learnt about selectionEquivalentTo matcher.
…paste' of https://github.com/JostSchenck/super_editor into fix/issue-2593-cursor-resets-to-end-of-paragraph-after-paste
…paste' of https://github.com/JostSchenck/super_editor into fix/issue-2593-cursor-resets-to-end-of-paragraph-after-paste
| await tester.typeImeText( | ||
| " "); // <- manually add a space because Markdown strips it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change and the following changes seem to be made by the auto formatter. Could you please revert it to remove noise from the PR?
This fixes #2593 . Currently, the code silently assumes that when text is pasted, it covers complete nodes, and always places the caret at the end. However, when only some text without paragraphs is pasted into the middle of a paragraph, the user expects the caret to be placed at the end of the inserted text.