From 2f84d7e54e7bbc3e0216224d340efcad742e1fac Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 8 Aug 2022 16:17:17 +0800 Subject: [PATCH] fix: fix crash when selecting the last node --- .../lib/service/selection_service.dart | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart index 8baa54c26f..95c158f3ee 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart @@ -313,13 +313,9 @@ class _FlowySelectionState extends State panStartOffsetWithScrollDyGap.translate(0, panStartScrollDy! - dy); } - final sortedNodes = - editorState.document.root.children.toList(growable: false); - final first = _lowerBound( - sortedNodes, panStartOffsetWithScrollDyGap, 0, sortedNodes.length) - .selectable; - final last = _upperBound(sortedNodes, panEndOffset!, 0, sortedNodes.length) - .selectable; + final first = + _lowerBoundInDocument(panStartOffsetWithScrollDyGap).selectable; + final last = _upperBoundInDocument(panEndOffset!).selectable; // compute the selection in range. if (first != null && last != null) { @@ -518,13 +514,13 @@ class _FlowySelectionState extends State Node _lowerBoundInDocument(Offset offset) { final sortedNodes = editorState.document.root.children.toList(growable: false); - return _lowerBound(sortedNodes, offset, 0, sortedNodes.length); + return _lowerBound(sortedNodes, offset, 0, sortedNodes.length - 1); } Node _upperBoundInDocument(Offset offset) { final sortedNodes = editorState.document.root.children.toList(growable: false); - return _upperBound(sortedNodes, offset, 0, sortedNodes.length); + return _upperBound(sortedNodes, offset, 0, sortedNodes.length - 1); } /// TODO: Supports multi-level nesting,