Fix beforeinput: pass in view.state instead of view #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "beforeinput-view-state"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
undoandredoboth take inEditorStateas arguments instead ofEditorView.The code surprisingly doesn't throw an error because
pluginKey.getState(state)resolves tostate[this.key](which results innull); however,undoandredoalways returnsfalse, as!hist(wherehist = historyKey.getState(state)) is a true condition.Tried going through the problem demo in https://github.com/ProseMirror/prosemirror/issues/1196 with the code only passing in
EditorStatetoundoandredo; that alone doesn't fix the issue. Kinda makes sense because calling commands with onlyEditorStateas input doesn't make the editor do anything:And default behavior of the
beforeinputevent is not prevented (since we're inside ofhandleDOMEvents), so it goes through. Second commit addresses both of these concerns.--
Edit. One thing I'm unsure about is whether
prosemirror-historyshould always calle.preventDefault()forhistoryRedoandhistoryUndoevents regardless of the result ofundoandredo, because what would be the default behavior for those two events if theundoandredostacks are empty? Should it allow for default behavior, or should it result in a "no-op" by consuming the event but doing nothing?Thanks for catching that! I copy-pasted these from the corresponding CodeMirror 6 file and failed to remember that the command interface is slightly different in ProseMirror.
I've pushed a slightly different patch. Not entirely sure about always preventing the default behavior, but that might actually be a good idea.
It seems the 'redo' entry in the context menu is just never going to be enabled when you preventDefault undo events. But I agree that we do need to preventDefault them always, because otherwise you get broken results when activating undo when the history is empty. Attached patch does this.
Pull request closed