-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
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 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.
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. |
Yeah there's also that exportDOM issue, which would not fix the history interactions but would help with other bugs. |
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 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, |
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'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:
- Type the start of a word in the autocomplete dictionary
- Press return
- 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
const textNode = $createTextNode(lastSuggestion) | ||
.setFormat(prevNodeFormat) | ||
.setStyle(`font-size: ${toolbarState.fontSize}`); | ||
autocompleteNode.replace(textNode); | ||
textNode.selectNext(); |
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 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.
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 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?
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 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.
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 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.
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 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.
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? |
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 think addressing the history related issues would be fine in another PR. As you've mentioned, they are not regressions.
Hi @etrepum , is this ready to be merged? |
Description
This PR aims to fix the formatting of the suggested text before and after insertion. The
AutocompleteNode
was previously implemented by extending theDecoratorNode
, which has no format property. As a result, it has been reimplemented by extending theTextNode
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.