state different from editor.state in command #6198
Unanswered
abecirovic3
asked this question in
Questions & Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm implementing my own undo/redo commands because I want to execute some additional logic in them besides the standard undo/redo behavior.
But one thing I encountered today made me question if I've been doing something wrong for the last year working on my RTE.
Please take a look at my undo command
So, additionally to just calling undo I want to check if the current state of the editor is an "intermediate" state and do one more undo if so (as to why I'm doing it like that, it's a long story, couldn't really find a way to make it work with addToHistory false etc).
And after I tried it, the can().removeInlineAISuggestion() would always return false, so I started logging things and to my surprise
state.doc.descendants((node) => console.log(node))
would not log the same nodes aseditor.state.doc.descendants((node) => console.log(node))
if I try with
editor.can().removeInlineAISuggestion()
things work as expected. Now, of course, I can do it like that, but it made me wonder if my approach to writing commands is wrong.Take a look at the
removeInlineAISuggestion
commandMaybe I'm mixing apples and oranges, but is this expected that the state and editor.state differ, and is my approach in my custom commands (I use it everywhere) valid, for just destructuring the
state
field directly and not usingeditor
instance.Beta Was this translation helpful? Give feedback.
All reactions