mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: refresh the selection when the metrics changed.
This commit is contained in:
parent
155b675dbe
commit
84eed9e340
@ -43,21 +43,21 @@ class NodeWidgetBuilder<T extends Node> {
|
|||||||
'Node validate failure, node = { type: ${node.type}, attributes: ${node.attributes} }');
|
'Node validate failure, node = { type: ${node.type}, attributes: ${node.attributes} }');
|
||||||
}
|
}
|
||||||
|
|
||||||
return _buildNodeChangeNotifier(buildContext);
|
return _build(buildContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNodeChangeNotifier(BuildContext buildContext) {
|
Widget _build(BuildContext buildContext) {
|
||||||
return ChangeNotifierProvider.value(
|
|
||||||
value: node,
|
|
||||||
builder: (_, __) => Consumer<T>(
|
|
||||||
builder: ((context, value, child) {
|
|
||||||
debugPrint('Node changed, and rebuilding...');
|
|
||||||
return CompositedTransformTarget(
|
return CompositedTransformTarget(
|
||||||
link: node.layerLink,
|
link: node.layerLink,
|
||||||
child: build(context),
|
child: ChangeNotifierProvider.value(
|
||||||
);
|
value: node,
|
||||||
|
builder: (context, child) => Consumer<T>(
|
||||||
|
builder: ((context, value, child) {
|
||||||
|
debugPrint('Node is rebuilding...');
|
||||||
|
return build(context);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class CursorWidget extends StatefulWidget {
|
|||||||
this.blinkingInterval = 0.5,
|
this.blinkingInterval = 0.5,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final double blinkingInterval;
|
final double blinkingInterval; // milliseconds
|
||||||
final Color color;
|
final Color color;
|
||||||
final Rect rect;
|
final Rect rect;
|
||||||
final LayerLink layerLink;
|
final LayerLink layerLink;
|
||||||
|
@ -96,7 +96,7 @@ class FlowySelection extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FlowySelectionState extends State<FlowySelection>
|
class _FlowySelectionState extends State<FlowySelection>
|
||||||
with FlowySelectionService {
|
with FlowySelectionService, WidgetsBindingObserver {
|
||||||
final _cursorKey = GlobalKey(debugLabel: 'cursor');
|
final _cursorKey = GlobalKey(debugLabel: 'cursor');
|
||||||
|
|
||||||
final List<OverlayEntry> _selectionOverlays = [];
|
final List<OverlayEntry> _selectionOverlays = [];
|
||||||
@ -122,6 +122,28 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
List<Node> getNodesInSelection(Selection selection) =>
|
List<Node> getNodesInSelection(Selection selection) =>
|
||||||
_selectedNodesInSelection(editorState.document.root, selection);
|
_selectedNodesInSelection(editorState.document.root, selection);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeMetrics() {
|
||||||
|
super.didChangeMetrics();
|
||||||
|
|
||||||
|
// Need to refresh the selection when the metrics changed.
|
||||||
|
if (currentSelection != null) {
|
||||||
|
updateSelection(currentSelection!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RawGestureDetector(
|
return RawGestureDetector(
|
||||||
@ -140,8 +162,8 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
TapGestureRecognizer:
|
TapGestureRecognizer:
|
||||||
GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
|
GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
|
||||||
() => TapGestureRecognizer(),
|
() => TapGestureRecognizer(),
|
||||||
(recongizer) {
|
(recognizer) {
|
||||||
recongizer.onTapDown = _onTapDown;
|
recognizer.onTapDown = _onTapDown;
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -155,8 +177,10 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
|
|
||||||
// cursor
|
// cursor
|
||||||
if (selection.isCollapsed) {
|
if (selection.isCollapsed) {
|
||||||
|
debugPrint('Update cursor');
|
||||||
_updateCursor(selection.start);
|
_updateCursor(selection.start);
|
||||||
} else {
|
} else {
|
||||||
|
debugPrint('Update selection');
|
||||||
_updateSelection(selection);
|
_updateSelection(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,9 +195,9 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
if (end != null) {
|
if (end != null) {
|
||||||
return computeNodesInRange(editorState.document.root, start, end);
|
return computeNodesInRange(editorState.document.root, start, end);
|
||||||
} else {
|
} else {
|
||||||
final reuslt = computeNodeInOffset(editorState.document.root, start);
|
final result = computeNodeInOffset(editorState.document.root, start);
|
||||||
if (reuslt != null) {
|
if (result != null) {
|
||||||
return [reuslt];
|
return [result];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
@ -307,7 +331,7 @@ class _FlowySelectionState extends State<FlowySelection>
|
|||||||
_cursorOverlays
|
_cursorOverlays
|
||||||
..forEach((overlay) => overlay.remove())
|
..forEach((overlay) => overlay.remove())
|
||||||
..clear();
|
..clear();
|
||||||
// clear floating shortcusts
|
// clear floating shortcuts
|
||||||
editorState.service.floatingShortcutServiceKey.currentState
|
editorState.service.floatingShortcutServiceKey.currentState
|
||||||
?.unwrapOrNull<FlowyFloatingShortcutService>()
|
?.unwrapOrNull<FlowyFloatingShortcutService>()
|
||||||
?.hide();
|
?.hide();
|
||||||
|
Loading…
Reference in New Issue
Block a user