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

[lexical-playground] Bug Fix: autocomplete format before and after insertion #6845

Merged
merged 13 commits into from
Nov 26, 2024

Conversation

bedre7
Copy link
Contributor

@bedre7 bedre7 commented Nov 18, 2024

Description

This PR aims to fix the formatting of the suggested text before and after insertion. The AutocompleteNode was previously implemented by extending the DecoratorNode, which has no format property. As a result, it has been reimplemented by extending the TextNode instead to fix the format of the text.

Closes #6816

Test plan

Existing test has been modified to meet the new requirements and a new test has been added.

Copy link

vercel bot commented Nov 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 5:47pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 5:47pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 18, 2024
Copy link

github-actions bot commented Nov 18, 2024

size-limit report 📦

Path Size
lexical - cjs 30.85 KB (0%)
lexical - esm 30.73 KB (0%)
@lexical/rich-text - cjs 39.58 KB (0%)
@lexical/rich-text - esm 32.67 KB (0%)
@lexical/plain-text - cjs 38.22 KB (0%)
@lexical/plain-text - esm 29.93 KB (0%)
@lexical/react - cjs 41.35 KB (0%)
@lexical/react - esm 34.03 KB (0%)

etrepum
etrepum previously approved these changes Nov 19, 2024
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This does seem like it's an improvement but there are some strange interactions with undo/redo. These don't appear to be regressions though, since there are also similar problems in the current playground, but if you want to go deeper that's probably worth exploring in another PR. I think the root cause is that the plugin requires transforms to run for correct operation but transforms don't run after undo/redo so something else has to happen here.

@ivailop7
Copy link
Collaborator

I believe we should have exportDOM exporting nothing, because if we don't have exportDOM, it will trigger the createDOM logic for clipboard and so on and we should never export the autocomplete suggestion in the exported html.

@etrepum
Copy link
Collaborator

etrepum commented Nov 19, 2024

Yeah there's also that exportDOM issue, which would not fix the history interactions but would help with other bugs.

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

It looks like in the full test suite it's failing some e2e tests, let's sort that out and the exportDOM issue before merging

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Nov 19, 2024
@bedre7
Copy link
Contributor Author

bedre7 commented Nov 20, 2024

It looks like in the full test suite it's failing some e2e tests, let's sort that out and the exportDOM issue before merging

Hi @etrepum, @ivailop7,
Thanks for your review and suggestions. I fixed most of the failing tests and the exportDOM issue, but there are still some failing flaky tests and 2 other tests which I couldn't figure out how they're related to my changes. Am I missing something?

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I'm still seeing some issues that makes it seem like the node transform and/or the node itself isn't implemented correctly. The repro steps for this are:

  1. Type the start of a word in the autocomplete dictionary
  2. Press return
  3. Undo (cmd-z on mac or ctrl-z elsewhere)

The autocomplete shows back up, in the wrong place, and you can add text to it (it should probably be in token mode, but also it shouldn't be there at all).

autocomplete-undo.mov

Comment on lines +203 to 207
const textNode = $createTextNode(lastSuggestion)
.setFormat(prevNodeFormat)
.setStyle(`font-size: ${toolbarState.fontSize}`);
autocompleteNode.replace(textNode);
textNode.selectNext();
Copy link
Collaborator

@etrepum etrepum Nov 21, 2024

Choose a reason for hiding this comment

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

I think perhaps a better strategy here would be to insert the text directly at the end of the previous node? What would happen if you just did something like:

autocompleteNode.selectPrevious().insertText(lastSuggestion);

Then you wouldn't need to worry about any of the style because it should instead modify the previous node instead of create a new node with the hope that they get merged together later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't comment on the line because it's not modified in the PR but above where it has if (node.__uuid === uuid && key !== autocompleteNodeKey) { that should probably use || instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't comment on the line because it's not modified in the PR but above where it has if (node.__uuid === uuid && key !== autocompleteNodeKey) { that should probably use || instead?

I just tried this, it clears the suggestion for all sessions in collab mode including the composing session, so it is never visible to anyone.

Copy link
Contributor Author

@bedre7 bedre7 Nov 22, 2024

Choose a reason for hiding this comment

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

I think perhaps a better strategy here would be to insert the text directly at the end of the previous node? What would happen if you just did something like:

autocompleteNode.selectPrevious().insertText(lastSuggestion);

Then you wouldn't need to worry about any of the style because it should instead modify the previous node instead of create a new node with the hope that they get merged together later.

That's a good point, It seems to fix the undo/redo bug, but it causes another bug: After undoing suggestion insertion, pressing tab won't insert the suggestion back; it inserts a tab and pushes the suggestion forward.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the solution to that is probably to have this plug-in listen to history commands directly, because its transforms are not going to run on undo but there might still be something that needs to happen.

@bedre7
Copy link
Contributor Author

bedre7 commented Nov 22, 2024

I'm still seeing some issues that makes it seem like the node transform and/or the node itself isn't implemented correctly. The repro steps for this are:

  1. Type the start of a word in the autocomplete dictionary
  2. Press return
  3. Undo (cmd-z on mac or ctrl-z elsewhere)

The autocomplete shows back up, in the wrong place, and you can add text to it (it should probably be in token mode, but also it shouldn't be there at all).

autocomplete-undo.mov

Thanks for pointing this out. I can reproduce a similar bug on the main branch, so I don't think it's a regression. What if I refactor this plugin and try to address the undo/redo bugs in another PR?

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think addressing the history related issues would be fine in another PR. As you've mentioned, they are not regressions.

@bedre7
Copy link
Contributor Author

bedre7 commented Nov 26, 2024

Hi @etrepum , is this ready to be merged?

@etrepum etrepum added this pull request to the merge queue Nov 26, 2024
Merged via the queue into facebook:main with commit ff10b1d Nov 26, 2024
56 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: AutocompletePlugin doesn't suggest and autocomplete in the same format as the prefix
4 participants