Skip to content

Commit

Permalink
fix: the menu dismissed after selecting block style (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jan 11, 2024
1 parent f053a1e commit 3d373be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class _MobileSelectionServiceWidgetState
final List<SelectionGestureInterceptor> _interceptors = [];
final ValueNotifier<Offset?> _lastPanOffset = ValueNotifier(null);

// the selection from editorState will be updated directly, but the cursor
// or selection area depends on the layout of the text, so we need to update
// the selection after the layout.
final PropertyValueNotifier<Selection?> selectionNotifierAfterLayout =
PropertyValueNotifier<Selection?>(null);

/// Pan
Offset? _panStartOffset;
double? _panStartScrollDy;
Expand All @@ -102,6 +108,7 @@ class _MobileSelectionServiceWidgetState
void dispose() {
clearSelection();
WidgetsBinding.instance.removeObserver(this);
selectionNotifierAfterLayout.dispose();
editorState.selectionNotifier.removeListener(_updateSelection);

super.dispose();
Expand Down Expand Up @@ -149,7 +156,7 @@ class _MobileSelectionServiceWidgetState

Widget _buildCollapsedHandle() {
return ValueListenableBuilder(
valueListenable: editorState.selectionNotifier,
valueListenable: selectionNotifierAfterLayout,
builder: (context, selection, _) {
if (selection == null ||
!selection.isCollapsed ||
Expand Down Expand Up @@ -199,7 +206,7 @@ class _MobileSelectionServiceWidgetState
}

return ValueListenableBuilder(
valueListenable: editorState.selectionNotifier,
valueListenable: selectionNotifierAfterLayout,
builder: (context, selection, _) {
if (selection == null || selection.isCollapsed) {
return const SizedBox.shrink();
Expand Down Expand Up @@ -341,6 +348,11 @@ class _MobileSelectionServiceWidgetState

void _updateSelection() {
final selection = editorState.selection;

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
selectionNotifierAfterLayout.value = selection;
});

if (currentSelection.value != selection) {
clearSelection();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class _BlocksMenuState extends State<_BlocksMenu> {
HeadingBlockKeys.level: list.level,
},
),
selectionExtraInfo: {
selectionExtraInfoDoNotAttachTextService: true,
},
);
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class _HeadingMenuState extends State<_HeadingMenu> {
ParagraphBlockKeys.delta: (node.delta ?? Delta()).toJson(),
},
),
selectionExtraInfo: {
selectionExtraInfoDoNotAttachTextService: true,
},
);
});
},
Expand Down

0 comments on commit 3d373be

Please sign in to comment.