@@ -254,15 +254,7 @@ export class BubbleMenuView implements PluginView {
254
254
this . view . dom . addEventListener ( 'dragstart' , this . dragstartHandler )
255
255
this . editor . on ( 'focus' , this . focusHandler )
256
256
this . editor . on ( 'blur' , this . blurHandler )
257
- window . addEventListener ( 'resize' , ( ) => {
258
- if ( this . resizeDebounceTimer ) {
259
- clearTimeout ( this . resizeDebounceTimer )
260
- }
261
-
262
- this . resizeDebounceTimer = window . setTimeout ( ( ) => {
263
- this . updatePosition ( )
264
- } , this . resizeDelay )
265
- } )
257
+ window . addEventListener ( 'resize' , this . resizeHandler )
266
258
267
259
this . update ( view , view . state )
268
260
@@ -279,6 +271,21 @@ export class BubbleMenuView implements PluginView {
279
271
this . hide ( )
280
272
}
281
273
274
+ /**
275
+ * Handles the window resize event to update the position of the bubble menu.
276
+ * It uses a debounce mechanism to prevent excessive updates.
277
+ * The delay is defined by the `resizeDelay` property.
278
+ */
279
+ resizeHandler = ( ) => {
280
+ if ( this . resizeDebounceTimer ) {
281
+ clearTimeout ( this . resizeDebounceTimer )
282
+ }
283
+
284
+ this . resizeDebounceTimer = window . setTimeout ( ( ) => {
285
+ this . updatePosition ( )
286
+ } , this . resizeDelay )
287
+ }
288
+
282
289
focusHandler = ( ) => {
283
290
// we use `setTimeout` to make sure `selection` is already updated
284
291
setTimeout ( ( ) => this . update ( this . editor . view ) )
@@ -464,6 +471,7 @@ export class BubbleMenuView implements PluginView {
464
471
this . hide ( )
465
472
this . element . removeEventListener ( 'mousedown' , this . mousedownHandler , { capture : true } )
466
473
this . view . dom . removeEventListener ( 'dragstart' , this . dragstartHandler )
474
+ window . removeEventListener ( 'resize' , this . resizeHandler )
467
475
this . editor . off ( 'focus' , this . focusHandler )
468
476
this . editor . off ( 'blur' , this . blurHandler )
469
477
0 commit comments