Skip to content

Commit 423e6e6

Browse files
committed
Prevent createParagraphNear from firing for AllSelections
FIX: Improve behavior of enter when the entire document is selected. See https://discuss.prosemirror.net/t/unexpected-behavior-when-pressing-enter-after-select-all-doc-content/3485
1 parent 3dbb05b commit 423e6e6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/commands.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ export function exitCode(state, dispatch) {
260260
// If a block node is selected, create an empty paragraph before (if
261261
// it is its parent's first child) or after it.
262262
export function createParagraphNear(state, dispatch) {
263-
let {$from, $to} = state.selection
264-
if ($from.parent.inlineContent || $to.parent.inlineContent) return false
265-
let type = defaultBlockAt($from.parent.contentMatchAt($to.indexAfter()))
263+
let sel = state.selection, {$from, $to} = sel
264+
if (!(sel instanceof NodeSelection) || $from.parent.inlineContent) return false
265+
let type = defaultBlockAt($to.parent.contentMatchAt($to.indexAfter()))
266266
if (!type || !type.isTextblock) return false
267267
if (dispatch) {
268268
let side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos
@@ -308,7 +308,7 @@ export function splitBlock(state, dispatch) {
308308
if (dispatch) {
309309
let atEnd = $to.parentOffset == $to.parent.content.size
310310
let tr = state.tr
311-
if (state.selection instanceof TextSelection) tr.deleteSelection()
311+
if (state.selection instanceof TextSelection || state.selection instanceof AllSelection) tr.deleteSelection()
312312
let deflt = $from.depth == 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
313313
let types = atEnd && deflt ? [{type: deflt}] : null
314314
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)

0 commit comments

Comments
 (0)