Home key handling

Has the home key default browser behavior? I didn’t find any keymap.

In my list home jumps to the end of previous list item:

  • first item
  • second | item

press home

  • first item |
  • second item

In the example editor home works in list item as expected.


Which browser does this happen in? I’m not seeing it in Chrome and Firefox.

Very strange. I tested the same text without pm just contenteditable and home works as expected on list item. Let me narrow down the problem.

In your example editor content of list items are inside a paragraph:

<li><p>first item</p></li>
<li><p>second item</p></li>

For my use case list items accepts only inline content as the paragraph influences the wysiwyg experience:

<li>first item</li>
<li>second item</li>

It looks like this causes the wrong cursor position for the home action. How can this happen if home should have the default browser behavior?

By the way the end key works as expected.

It seems to be a firefox problem. In chrome and edge home works as expected, I’m currently using firefox quantum 58.0.1.

I tracked down which event causes the strange jump:

view.dom.addEventListener(“focus”, () => this.poller.start(hasFocusAndSelection(this.view)))

Once I comment out this line home key works as expected.

That listens for DOM selection changes so that ProseMirror can keep its selection state in sync with the DOM selection.

There is another event added by poller.start (selectionchange) which causes a transaction. I tracked down this further and found once this.docView.update(state.doc, outerDeco, innerDeco, this) is executed home starts to fail.

But now I get lost, where is the code for this update function?

That’s in viewdesc.js, but it’s likely that the problem is in the selection update, not the document update (which that line handles).

You are right the problem occurs in selectionToDom at this line.

In chrome, which works well, it returns at this line but firefox does not. The content of lastSelection differs:



Now I know where it happens but still don’t know the cause of it. I might give up…

I still can’t reproduce this in Firefox 58 when I set list items to contain inline*. Can you set up a self-contained demo that shows the issue, for example by editing https://glitch.com/edit/#!/remix/prosemirror-demo-basic ?

Thank you very much for your patience! I did find the cause. Pressing “home” returns wrong result for native command getSelection(). Instead of the text node it gets back the li node. This happens for:

  1. firefox quantum (linux and windows tested)
  2. ‘li’ without ‘p’
  3. use of //cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css"!

I was not aware that css influences this behavior and I have no idea how this can.

To see the effect have a look at this simple jsfiddle code. Jumping can not be seen here (no pm code). Please test key ‘home’ for the first item it will return UL instead of #text.

For second item text is inside ‘p’ and key ‘home’ returns #text as it should. Key ‘end’ return for both items #text node.

You could try submitting a Gecko bug (or see if it has already been reported), since that definitely seems like a bug (home/end selection motion should happen within the current text block—moving to the list node when pressing home in an list item is just weird).

Yes, that’s for sure a ff bug, will submit a report if not done yet. Finally it’s just this small css stuff which took me hours of debugging:

ul { list-style-position: inside; }

Edit: I opened this bug report in bugzilla