mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: selection state mismatch
This commit is contained in:
parent
eac54aefd7
commit
afe11a4f91
@ -21,6 +21,11 @@ class ApplyOptions {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CursorUpdateReason {
|
||||||
|
uiEvent,
|
||||||
|
others,
|
||||||
|
}
|
||||||
|
|
||||||
class EditorState {
|
class EditorState {
|
||||||
final StateTree document;
|
final StateTree document;
|
||||||
|
|
||||||
@ -37,11 +42,10 @@ class EditorState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// add the set reason in the future, don't use setter
|
/// 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
|
// broadcast to other users here
|
||||||
if (cursorSelection == null) {
|
if (reason != CursorUpdateReason.uiEvent) {
|
||||||
service.selectionService.clearSelection();
|
|
||||||
} else {
|
|
||||||
service.selectionService.updateSelection(cursorSelection);
|
service.selectionService.updateSelection(cursorSelection);
|
||||||
}
|
}
|
||||||
_cursorSelection = cursorSelection;
|
_cursorSelection = cursorSelection;
|
||||||
|
@ -52,7 +52,7 @@ abstract class FlowySelectionService {
|
|||||||
/// The editor will update selection area and toolbar area
|
/// The editor will update selection area and toolbar area
|
||||||
/// if the [selection] is not collapsed,
|
/// if the [selection] is not collapsed,
|
||||||
/// otherwise, will update the cursor area.
|
/// 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.
|
/// Clears the selection area, cursor area and the popup list area.
|
||||||
void clearSelection();
|
void clearSelection();
|
||||||
@ -180,21 +180,24 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void updateSelection(Selection selection) {
|
void updateSelection(Selection? selection) {
|
||||||
selectionRects.clear();
|
selectionRects.clear();
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
|
||||||
if (selection.isCollapsed) {
|
if (selection != null) {
|
||||||
/// updates cursor area.
|
if (selection.isCollapsed) {
|
||||||
debugPrint('updating cursor');
|
/// updates cursor area.
|
||||||
_updateCursorAreas(selection.start);
|
debugPrint('updating cursor');
|
||||||
} else {
|
_updateCursorAreas(selection.start);
|
||||||
// updates selection area.
|
} else {
|
||||||
debugPrint('updating selection');
|
// updates selection area.
|
||||||
_updateSelectionAreas(selection);
|
debugPrint('updating selection');
|
||||||
|
_updateSelectionAreas(selection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSelection.value = selection;
|
currentSelection.value = selection;
|
||||||
|
editorState.updateCursorSelection(selection, CursorUpdateReason.uiEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user