Merge pull request #819 from AppFlowy-IO/fix/selection-state-mismatch-2

fix: selection state mismatch
This commit is contained in:
Vincent Chan 2022-08-11 14:28:06 +08:00 committed by GitHub
commit 9c97a0b635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 14 deletions

View File

@ -21,6 +21,11 @@ class ApplyOptions {
});
}
enum CursorUpdateReason {
uiEvent,
others,
}
class EditorState {
final StateTree document;
@ -37,11 +42,10 @@ class EditorState {
}
/// add the set reason in the future, don't use setter
updateCursorSelection(Selection? cursorSelection) {
updateCursorSelection(Selection? cursorSelection,
[CursorUpdateReason reason = CursorUpdateReason.others]) {
// broadcast to other users here
if (cursorSelection == null) {
service.selectionService.clearSelection();
} else {
if (reason != CursorUpdateReason.uiEvent) {
service.selectionService.updateSelection(cursorSelection);
}
_cursorSelection = cursorSelection;

View File

@ -52,7 +52,7 @@ abstract class FlowySelectionService {
/// The editor will update selection area and toolbar area
/// if the [selection] is not collapsed,
/// otherwise, will update the cursor area.
void updateSelection(Selection selection);
void updateSelection(Selection? selection);
/// Clears the selection area, cursor area and the popup list area.
void clearSelection();
@ -180,10 +180,11 @@ class _FlowySelectionState extends State<FlowySelection>
}
@override
void updateSelection(Selection selection) {
void updateSelection(Selection? selection) {
selectionRects.clear();
clearSelection();
if (selection != null) {
if (selection.isCollapsed) {
/// updates cursor area.
debugPrint('updating cursor');
@ -193,8 +194,10 @@ class _FlowySelectionState extends State<FlowySelection>
debugPrint('updating selection');
_updateSelectionAreas(selection);
}
}
currentSelection.value = selection;
editorState.updateCursorSelection(selection, CursorUpdateReason.uiEvent);
}
@override