Skip to content

Commit 62f4570

Browse files
fix: remove cursor flicker in trailing block (#2839)
1 parent 7a89547 commit 62f4570

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

packages/core/src/editor/Block.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ BASIC STYLES
5252
.bn-trailing-block {
5353
cursor: text;
5454
height: 30px;
55+
user-select: none;
5556
}
5657

5758
/*

packages/core/src/extensions/TrailingNode/TrailingNode.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { Node as PMNode } from "prosemirror-model";
2-
import { Plugin, PluginKey, type Transaction } from "prosemirror-state";
2+
import {
3+
Plugin,
4+
PluginKey,
5+
Selection,
6+
type Transaction,
7+
} from "prosemirror-state";
38
import { Decoration, DecorationSet } from "prosemirror-view";
49
import {
510
createExtension,
@@ -127,6 +132,33 @@ export const TrailingNodeExtension = createExtension(
127132
},
128133
props: {
129134
decorations: (state) => PLUGIN_KEY.getState(state),
135+
// Prevents ProseMirror from trying to move the selection into the
136+
// trailing block, which causes the text caret to flicker in it
137+
// before returning to its previous position.
138+
handleKeyDown: (view, event) => {
139+
if (event.key !== "ArrowRight" && event.key !== "ArrowDown") {
140+
return false;
141+
}
142+
143+
const { selection } = view.state;
144+
if (!selection.empty) {
145+
return false;
146+
}
147+
148+
const docEnd = Selection.atEnd(view.state.doc);
149+
if (selection.$head.pos !== docEnd.$head.pos) {
150+
return false;
151+
}
152+
153+
if (
154+
!shouldShowTrailingWidget(view.state.doc, editor.isEditable)
155+
) {
156+
return false;
157+
}
158+
159+
event.preventDefault();
160+
return true;
161+
},
130162
},
131163
}),
132164
],

0 commit comments

Comments
 (0)