File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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/*
Original file line number Diff line number Diff line change 11import 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" ;
38import { Decoration , DecorationSet } from "prosemirror-view" ;
49import {
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 ] ,
You can’t perform that action at this time.
0 commit comments