@@ -196,7 +196,12 @@ export class SuggestionMenuProseMirrorPlugin<
196
196
} ,
197
197
198
198
// Apply changes to the plugin state from an editor transaction.
199
- apply ( transaction , prev , _oldState , newState ) : SuggestionPluginState {
199
+ apply : (
200
+ transaction ,
201
+ prev ,
202
+ _oldState ,
203
+ newState
204
+ ) : SuggestionPluginState => {
200
205
// TODO: More clearly define which transactions should be ignored.
201
206
if ( transaction . getMeta ( "orderedListIndexing" ) !== undefined ) {
202
207
return prev ;
@@ -215,12 +220,14 @@ export class SuggestionMenuProseMirrorPlugin<
215
220
ignoreQueryLength ?: boolean ;
216
221
} | null = transaction . getMeta ( suggestionMenuPluginKey ) ;
217
222
218
- // Only opens a menu of no menu is already open
219
223
if (
220
224
typeof suggestionPluginTransactionMeta === "object" &&
221
- suggestionPluginTransactionMeta !== null &&
222
- prev === undefined
225
+ suggestionPluginTransactionMeta !== null
223
226
) {
227
+ if ( prev ) {
228
+ // Close the previous menu if it exists
229
+ this . closeMenu ( ) ;
230
+ }
224
231
const trackedPosition = trackPosition (
225
232
editor ,
226
233
newState . selection . from -
@@ -262,7 +269,11 @@ export class SuggestionMenuProseMirrorPlugin<
262
269
transaction . getMeta ( "pointer" ) ||
263
270
// Moving the caret before the character which triggered the menu should hide it.
264
271
( prev . triggerCharacter !== undefined &&
265
- newState . selection . from < prev . queryStartPos ( ) )
272
+ newState . selection . from < prev . queryStartPos ( ) ) ||
273
+ // Moving the caret to a new block should hide the menu.
274
+ ! newState . selection . $from . sameParent (
275
+ newState . doc . resolve ( prev . queryStartPos ( ) )
276
+ )
266
277
) {
267
278
return undefined ;
268
279
}
@@ -281,14 +292,7 @@ export class SuggestionMenuProseMirrorPlugin<
281
292
282
293
props : {
283
294
handleTextInput ( view , _from , _to , text ) {
284
- const suggestionPluginState : SuggestionPluginState = (
285
- this as Plugin
286
- ) . getState ( view . state ) ;
287
-
288
- if (
289
- triggerCharacters . includes ( text ) &&
290
- suggestionPluginState === undefined
291
- ) {
295
+ if ( triggerCharacters . includes ( text ) ) {
292
296
view . dispatch (
293
297
view . state . tr
294
298
. insertText ( text )
0 commit comments