Incorrect behavior of NodeView demo http://prosemirror.net/examples/codemirror/ #83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Hi,
I was not sure what was the right place to report issues for the the Codemirror NodeView demo, but since source for it is here I've decided to do it here.
Here is the list of things I found to not behave according to (at least my) expectations:
If you place a cursor right after the editor view and hit backspace it moves text under the text editor into the editor itself. I am not entirely sure what would make sense here. I suspect one of the following:
backspaceonce again delete the whole editor view. I think even though this requires additional press onbackspaceit does provide user clear signal what's about to happen.NodeView, essentially do whatArrowLeftwould have done. I'm not sure if that behavior would be intuitive but I suspect less surprising.NodeViewand delete last character in it. I'm not really in favor of it, but that is certainly an option.I think it would also make sense to add
Ctrl-Backspacekeybinding to perform current behavior (move text after cursor into the editor view) and extendCtrl-Enterkeybinding to somewhat do what it already does but more closely mirrorCtrl-Backspacein otherCtrlmodifier would allow you to move text in & out of the editor view.If you place cursor right before the editor view and hit delete it appends editor content to the previous line removing editor if line of the cursor isn't empty, or it remove empty line the cursor is on and moves cursor into an editor.
Not going to list all the options here but would expect option to just mirror choice above. I also would expect that behavior to be the same regardless of whether line of cursor is empty or not.
If you delete all the content of the editor and keep pressing
backspacenothing happens. In fact only way to remove editor is to delete all the content then place cursor in front of the editor and press delete. Here's options I think would provide more intuitive behavior:NodeViewon first backspace / delete is a chosen solution, then there's nothing to do it would actually cover this.backspaceis pressed just deleteNodeView. Same fordeleteif editor content is empty it should probably just delete editor node.If you have text selected before the editor and keep extending selection with
Shift-ArrowRight/Shift-ArrowDownkeys nothing happens. On the other hand if you have text selected right after the editor and useShift-ArrowLeftit extends selection with in the editor but only per line basis andShift-ArrowUpdoes nothing. Also note that extending selection from with-in the editor to the outside of it does not work at all.NodeViewas atomic would make more sense here.If you have selection with-in the editor and you click outside of the editor text remains selected. Not saying it's incorrect but I wanted to point this out as well as it would help in the summary below.
Summary
I think my general observation is that there must be two different types of
NodeView:Atomic NodeView (kind of a Portal)
Such
NodeViewcould be treated be treated from the outside as a single characters, except when cursor moves across it (cursor is moved across it or user clicks it)NodeViewhook couldonEnter(dir)is invoked whichNodeViewcould cancel to take over theProseMirror's events and perform all the range manipulation internally. It can also possibly exit itself whenever that makes sense (like when cursor is moved passed it's own content orCtrl-Enteretc...)all the events are from the ProseMirror are delegated to it.
NodeViewcould also be responsible of triggering exiting itself (moving cursor past theNodeView).Inline NodeView (just a alternate rendering of text range)
I need to look into more details to write something up, but my intuition is that it might be useful to have a
NodeViewwhich does just a rendering of a text range, meaning that all of the actual event handling (cursor positioning, selection, etc...) is taken care of by aProseMirrorwhile the rendering of the state is delegated to thisNodeView.As I don't know nearly enough about ProseMirror I might be drawing wrong conclusions, but it seems to me there would be a value in some of the cursor handling out to the
NodeViewinterface so thatNodeViewimplementer does not need to handle all of the edge cases for entering / deletingNodeViewor care about details of keymap thatProseMirrorhas being setup with (for example I tend to usectrl-f/ctr-bfor navigation which works as expected inProseMirrorexcept it won't actually enter the the embedded editor as no mapping was setup).To do a trick like this in a production-quality way, yes, more scripting will be required than the minimum I did in the example. I do not think this warrants having multiple types of node views. I've set the code_block node to isolating in the example, which solves some of this. The other I feel can be handled by adding more custom key and event handlers.
Definitely struggling with number 5 from above. I can't pin down exactly the issue but I believe it has something to do with
forwardSelectionandsetSelection. I've removedforwardSelectionand I'm not noticing any drawbacks but I still get issues withsetSelectionwhich I definitely need.This is how CodeMirror works—it'll just style its selection differently when it's unfocused, not actually hide it. You could give it a blur handler that collapses the internal selection to work around it.