From c855879548dd0a551d812f97ceccd624c8044307 Mon Sep 17 00:00:00 2001 From: Morn Date: Tue, 1 Apr 2025 17:48:03 +0800 Subject: [PATCH] fix: do not recreate the toolbar when the selection is not null --- .../toolbar/desktop/floating_toolbar.dart | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/src/editor/toolbar/desktop/floating_toolbar.dart b/lib/src/editor/toolbar/desktop/floating_toolbar.dart index 970b9ec70..1d7a761b5 100644 --- a/lib/src/editor/toolbar/desktop/floating_toolbar.dart +++ b/lib/src/editor/toolbar/desktop/floating_toolbar.dart @@ -136,22 +136,23 @@ class _FloatingToolbarState extends State final selection = editorState.selection; final selectionType = editorState.selectionType; if (lastSelection == selection) return; - lastSelection = selection; - - if (selection == null || - selection.isCollapsed || - selectionType == SelectionType.block || - editorState.selectionExtraInfo?[selectionExtraInfoDisableToolbar] == - true) { - _clear(); - } else { - // uses debounce to avoid the computing the rects too frequently. - _showAfterDelay( - duration: const Duration(milliseconds: 200), - isMetricsChanged: hasMetricsChanged, - ); - if (hasMetricsChanged) hasMetricsChanged = false; + if (lastSelection == null || selection == null) { + if (selection == null || + selection.isCollapsed || + selectionType == SelectionType.block || + editorState.selectionExtraInfo?[selectionExtraInfoDisableToolbar] == + true) { + _clear(); + } else { + // uses debounce to avoid the computing the rects too frequently. + _showAfterDelay( + duration: const Duration(milliseconds: 200), + isMetricsChanged: hasMetricsChanged, + ); + if (hasMetricsChanged) hasMetricsChanged = false; + } } + lastSelection = selection; } void _onScrollPositionChanged() {