Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: refresh the selection when the metrics changed.
Lucas.Xu84eed9e3402f
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/render/node_widget_builder.dart b/frontend/app_flowy/packages/flowy_editor/lib/render/node_widget_builder.dartindex a3d35f9dad..06f364d67b 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/render/node_widget_builder.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/render/node_widget_builder.dart@@ -43,20 +43,20 @@ class NodeWidgetBuilder<T extends Node> {'Node validate failure, node = { type: ${node.type}, attributes: ${node.attributes} }');}- return _buildNodeChangeNotifier(buildContext);+ return _build(buildContext);}- Widget _buildNodeChangeNotifier(BuildContext buildContext) {- return ChangeNotifierProvider.value(- value: node,- builder: (_, __) => Consumer<T>(- builder: ((context, value, child) {- debugPrint('Node changed, and rebuilding...');- return CompositedTransformTarget(- link: node.layerLink,- child: build(context),- );- }),+ Widget _build(BuildContext buildContext) {+ return CompositedTransformTarget(+ link: node.layerLink,+ child: ChangeNotifierProvider.value(+ value: node,+ builder: (context, child) => Consumer<T>(+ builder: ((context, value, child) {+ debugPrint('Node is rebuilding...');+ return build(context);+ }),+ ),),);}diff --git a/frontend/app_flowy/packages/flowy_editor/lib/render/selection/cursor_widget.dart b/frontend/app_flowy/packages/flowy_editor/lib/render/selection/cursor_widget.dartindex 2ba42221f0..58d22bec85 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/render/selection/cursor_widget.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/render/selection/cursor_widget.dart@@ -11,7 +11,7 @@ class CursorWidget extends StatefulWidget {this.blinkingInterval = 0.5,}) : super(key: key);- final double blinkingInterval;+ final double blinkingInterval; // millisecondsfinal Color color;final Rect rect;final LayerLink layerLink;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.dartindex be3fde4062..52c0b84f2c 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@@ -96,7 +96,7 @@ class FlowySelection extends StatefulWidget {}class _FlowySelectionState extends State<FlowySelection>- with FlowySelectionService {+ with FlowySelectionService, WidgetsBindingObserver {final _cursorKey = GlobalKey(debugLabel: 'cursor');final List<OverlayEntry> _selectionOverlays = [];@@ -122,6 +122,28 @@ class _FlowySelectionState extends State<FlowySelection>List<Node> getNodesInSelection(Selection 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();+ }+@overrideWidget build(BuildContext context) {return RawGestureDetector(@@ -140,8 +162,8 @@ class _FlowySelectionState extends State<FlowySelection>TapGestureRecognizer:GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(() => TapGestureRecognizer(),- (recongizer) {- recongizer.onTapDown = _onTapDown;+ (recognizer) {+ recognizer.onTapDown = _onTapDown;},)},@@ -155,8 +177,10 @@ class _FlowySelectionState extends State<FlowySelection>// cursorif (selection.isCollapsed) {+ debugPrint('Update cursor');_updateCursor(selection.start);} else {+ debugPrint('Update selection');_updateSelection(selection);}}@@ -171,9 +195,9 @@ class _FlowySelectionState extends State<FlowySelection>if (end != null) {return computeNodesInRange(editorState.document.root, start, end);} else {- final reuslt = computeNodeInOffset(editorState.document.root, start);- if (reuslt != null) {- return [reuslt];+ final result = computeNodeInOffset(editorState.document.root, start);+ if (result != null) {+ return [result];}}return [];@@ -307,7 +331,7 @@ class _FlowySelectionState extends State<FlowySelection>_cursorOverlays..forEach((overlay) => overlay.remove())..clear();- // clear floating shortcusts+ // clear floating shortcutseditorState.service.floatingShortcutServiceKey.currentState?.unwrapOrNull<FlowyFloatingShortcutService>()?.hide();