From 301e7ec6b7009a3e695fd3a6f87a43adc47b2f18 Mon Sep 17 00:00:00 2001 From: Matthew Lipski Date: Thu, 4 Jun 2026 18:25:08 +0200 Subject: [PATCH] Fixed trailing block flickering text cursor on arrow right/down --- packages/core/src/editor/Block.css | 1 + .../extensions/TrailingNode/TrailingNode.ts | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/core/src/editor/Block.css b/packages/core/src/editor/Block.css index 2c96511a2f..547e009d6f 100644 --- a/packages/core/src/editor/Block.css +++ b/packages/core/src/editor/Block.css @@ -52,6 +52,7 @@ BASIC STYLES .bn-trailing-block { cursor: text; height: 30px; + user-select: none; } /* diff --git a/packages/core/src/extensions/TrailingNode/TrailingNode.ts b/packages/core/src/extensions/TrailingNode/TrailingNode.ts index 59f95d2bed..d7bcfe002c 100644 --- a/packages/core/src/extensions/TrailingNode/TrailingNode.ts +++ b/packages/core/src/extensions/TrailingNode/TrailingNode.ts @@ -1,5 +1,10 @@ import type { Node as PMNode } from "prosemirror-model"; -import { Plugin, PluginKey, type Transaction } from "prosemirror-state"; +import { + Plugin, + PluginKey, + Selection, + type Transaction, +} from "prosemirror-state"; import { Decoration, DecorationSet } from "prosemirror-view"; import { createExtension, @@ -127,6 +132,33 @@ export const TrailingNodeExtension = createExtension( }, props: { decorations: (state) => PLUGIN_KEY.getState(state), + // Prevents ProseMirror from trying to move the selection into the + // trailing block, which causes the text caret to flicker in it + // before returning to its previous position. + handleKeyDown: (view, event) => { + if (event.key !== "ArrowRight" && event.key !== "ArrowDown") { + return false; + } + + const { selection } = view.state; + if (!selection.empty) { + return false; + } + + const docEnd = Selection.atEnd(view.state.doc); + if (selection.$head.pos !== docEnd.$head.pos) { + return false; + } + + if ( + !shouldShowTrailingWidget(view.state.doc, editor.isEditable) + ) { + return false; + } + + event.preventDefault(); + return true; + }, }, }), ],