From the description of the module, it seems that gapcursors are allowed at the beginning and end of the topmost document:
This is a plugin that adds a type of selection for focusing places that don’t allow regular selection (such as positions that have a leaf block node, table, or the end of the document both before and after them).
However in the prosemirror basic setup, when the only content is a codeblock, the cursor is trapped within that node: pressing the arrow keys results in selections at beginning or end of only the codeblock, not of the parent document as well.
What is the correct behavior of prosemirror-gapcursor
in this scenario? Are gapcursors at the beginning and end of the document allowed?
Walking through the source code, the reason no gapcursor is created for the beginning and end of the document is because of line 53, where null is returned because there is no child before or after the codeblock, and because the the depth is 0 at the top most node.
for (let d = $pos.depth;; d--) {
let parent = $pos.node(d)
if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {
next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1)
break
} else if (d == 0) { // line 53
return null
}
pos += dir
let $cur = $pos.doc.resolve(pos)
if (GapCursor.valid($cur)) return $cur
}
A seemingly simple fix that would allow gapcursors at the beginning and end would be to modify prosemirror-gapcursor/src/gapcursor.js
to return $pos
instead of null
, but I haven’t tested this extensively. Edit: this works with codeblocks, but not with blockquotes perhaps because the former has as its content “text*” and the latter has “blocks+”.
} else if (d == 0) { // line 53
return $pos
}