@@ -134,7 +134,7 @@ export class ToolbarPlugin extends Plugin {
134
134
static shared = [ "getToolbarInfo" ] ;
135
135
resources = {
136
136
selectionchange_handlers : this . handleSelectionChange . bind ( this ) ,
137
- selection_leave_handlers : ( ) => this . overlay . close ( ) ,
137
+ selection_leave_handlers : ( ) => this . closeToolbar ( ) ,
138
138
step_added_handlers : ( ) => this . updateToolbar ( ) ,
139
139
user_commands : {
140
140
id : "expandToolbar" ,
@@ -210,7 +210,7 @@ export class ToolbarPlugin extends Plugin {
210
210
// Mouse interaction behavior:
211
211
// Close toolbar on mousedown and prevent it from opening until mouseup.
212
212
this . addDomListener ( this . editable , "mousedown" , ( ) => {
213
- this . overlay . close ( ) ;
213
+ this . closeToolbar ( ) ;
214
214
this . debouncedUpdateToolbar . cancel ( ) ;
215
215
this . onSelectionChangeActive = false ;
216
216
} ) ;
@@ -235,7 +235,7 @@ export class ToolbarPlugin extends Plugin {
235
235
// sequential keystrokes.
236
236
this . addDomListener ( this . editable , "keydown" , ( ev ) => {
237
237
if ( ev . key . startsWith ( "Arrow" ) ) {
238
- this . overlay . close ( ) ;
238
+ this . closeToolbar ( ) ;
239
239
this . onSelectionChangeActive = false ;
240
240
}
241
241
} ) ;
@@ -303,10 +303,14 @@ export class ToolbarPlugin extends Plugin {
303
303
}
304
304
305
305
updateToolbar ( selectionData = this . dependencies . selection . getSelectionData ( ) ) {
306
- this . updateToolbarVisibility ( selectionData ) ;
307
- if ( this . overlay . isOpen || this . config . disableFloatingToolbar ) {
308
- this . updateButtonsStates ( selectionData . editableSelection ) ;
306
+ this . updateNamespace ( ) ;
307
+ if ( ! this . config . disableFloatingToolbar ) {
308
+ this . updateToolbarVisibility ( selectionData ) ;
309
+ if ( ! this . overlay . isOpen ) {
310
+ return ;
311
+ }
309
312
}
313
+ this . updateButtonsStates ( selectionData . editableSelection ) ;
310
314
}
311
315
312
316
getFilterTraverseNodes ( ) {
@@ -316,21 +320,12 @@ export class ToolbarPlugin extends Plugin {
316
320
}
317
321
318
322
updateToolbarVisibility ( selectionData ) {
319
- this . updateNamespace ( ) ;
320
- if ( this . config . disableFloatingToolbar ) {
321
- return ;
322
- }
323
-
324
323
if ( this . shouldBeVisible ( selectionData ) ) {
325
324
// Open toolbar or update its position
326
325
const props = { toolbar : this . getToolbarInfo ( ) , class : "shadow rounded my-2" } ;
327
- if ( ! this . overlay . isOpen ) {
328
- // Open toolbar in compact mode
329
- this . isToolbarExpanded = false ;
330
- }
331
326
this . overlay . open ( { props } ) ;
332
327
} else if ( this . overlay . isOpen && ! this . shouldPreventClosing ( ) ) {
333
- this . overlay . close ( ) ;
328
+ this . closeToolbar ( ) ;
334
329
}
335
330
}
336
331
@@ -406,6 +401,11 @@ export class ToolbarPlugin extends Plugin {
406
401
}
407
402
this . updateSelection = null ;
408
403
}
404
+
405
+ closeToolbar ( ) {
406
+ this . overlay . close ( ) ;
407
+ this . isToolbarExpanded = false ;
408
+ }
409
409
}
410
410
411
411
class MobileToolbarOverlay {
0 commit comments