[Question] "AllSelection" weird behaviours when the document contains a "non-text-node" at the end

I am using ProseMirror showing a Markdown file. The content is simple:

Some paragraph here.

<div style='font-family: "Comic Sans MS", "Comic Sans", cursive;'>
It is a pity, but markdown does **not** work in here for most markdown parsers.
[Marked] handles it pretty well.
</div>

The following command is how I wrote SelectAll command when pressing mod+A:

When pressing Mod+A. The above command gets executed. But the state.selection shows a weird selection as shown following:

Then when I press the key Delete, only the first character from the first paragraph gets deleted, instead of the entire document.

I doubt it is something wrong with my last node in my document, I have that node in my document (parsed as a HTML node):

If I run this, I get a selection that covers the document, and deleting it clears the document. You’ll have to show a minimal script that reproduces the problem.

import {EditorView} from "prosemirror-view"
import {EditorState, AllSelection} from "prosemirror-state"
import {schema} from "prosemirror-schema-basic"

let view = new EditorView(document.body, {state: EditorState.create({
  doc: schema.node("doc", null, [
    schema.node("paragraph", null, [schema.text("abc")]),
    schema.node("horizontal_rule")
  ])
})})

view.focus()
view.dispatch(view.state.tr.setSelection(new AllSelection(view.state.doc)))

I think I know where the problem is. It seems like my problem is caused by the default behaviour from the browser when pressing Ctrl+A. I execute the following code right after the keypress event:

handleKeyDown: event => {
    event.preventDefault();
    // executing commands...
}

This solves my problem.

handleKeyDown is supposed to return true whenever it executes any command, which will automatically cause preventDefault to be called (as well as prevent any further built-in handling in the library).

1 Like

Thank you for replying. I re-checked this problem in my project, I did forget to return a boolean in handleKeyDown. This solves my problem exactly.