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
chore: migrate to the latest api
Lucas.Xude4f47b2a130
diff --git a/frontend/appflowy_flutter/integration_test/document/document_with_toggle_list_test.dart b/frontend/appflowy_flutter/integration_test/document/document_with_toggle_list_test.dartindex 58ac0c0fb6..50b84ed521 100644--- a/frontend/appflowy_flutter/integration_test/document/document_with_toggle_list_test.dart+++ b/frontend/appflowy_flutter/integration_test/document/document_with_toggle_list_test.dart@@ -93,9 +93,8 @@ void main() {// Press the enter keyawait tester.editor.updateSelection(- Selection.collapse(- [0],- 'Hello '.length,+ Selection.collapsed(+ Position(path: [0], offset: 'Hello '.length),),);await tester.ime.insertCharacter('\n');@@ -129,9 +128,8 @@ void main() {// Press the enter keyawait tester.editor.updateSelection(- Selection.collapse(- [0],- 'Hello '.length,+ Selection.collapsed(+ Position(path: [0], offset: 'Hello '.length),),);await tester.ime.insertCharacter('\n');@@ -170,9 +168,8 @@ void main() {await tester.tapButton(toggleListIcon);await tester.editor.updateSelection(- Selection.collapse(- [0],- 0,+ Selection.collapsed(+ Position(path: [0], offset: 0),),);await tester.ime.insertCharacter('\n');@@ -202,9 +199,8 @@ void main() {expectToggleListOpened();await tester.editor.updateSelection(- Selection.collapse(- [0],- 0,+ Selection.collapsed(+ Position(path: [0], offset: 0),),);await tester.simulateKeyEvent(diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/doc_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/doc_bloc.dartindex 5fac227521..b80dab7f4b 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/doc_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/doc_bloc.dart@@ -1,22 +1,30 @@+import 'dart:async';++import 'package:appflowy/plugins/document/application/doc_service.dart';import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';import 'package:appflowy/plugins/document/application/editor_transaction_adapter.dart';import 'package:appflowy/plugins/trash/application/trash_service.dart';import 'package:appflowy/user/application/user_service.dart';import 'package:appflowy/util/json_print.dart';-import 'package:appflowy/workspace/application/view/view_listener.dart';import 'package:appflowy/workspace/application/doc/doc_listener.dart';-import 'package:appflowy/plugins/document/application/doc_service.dart';+import 'package:appflowy/workspace/application/view/view_listener.dart';import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart';-import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pbserver.dart';-import 'package:appflowy_editor/appflowy_editor.dart'- show EditorState, LogLevel, TransactionTime, Selection, paragraphNode;import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pbserver.dart';+import 'package:appflowy_editor/appflowy_editor.dart'+ show+ EditorState,+ LogLevel,+ TransactionTime,+ Selection,+ Position,+ paragraphNode;+import 'package:dartz/dartz.dart';import 'package:flutter/foundation.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:freezed_annotation/freezed_annotation.dart';-import 'package:dartz/dartz.dart';-import 'dart:async';+part 'doc_bloc.freezed.dart';class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {@@ -198,7 +206,9 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {if (document.root.children.isEmpty) {final transaction = editorState.transaction;transaction.insertNode([0], paragraphNode());- transaction.afterSelection = Selection.collapse([0], 0);+ transaction.afterSelection = Selection.collapsed(+ Position(path: [0], offset: 0),+ );await editorState.apply(transaction);}}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex 2d58daef5a..5bced06640 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -386,14 +386,24 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {(bool, Selection?) _computeAutoFocusParameters() {if (widget.editorState.document.isEmpty) {- return (true, Selection.collapse([0], 0));+ return (+ true,+ Selection.collapsed(+ Position(path: [0], offset: 0),+ ),+ );}final nodes = widget.editorState.document.root.children.where((element) => element.delta != null);final isAllEmpty =nodes.isNotEmpty && nodes.every((element) => element.delta!.isEmpty);if (isAllEmpty) {- return (true, Selection.collapse(nodes.first.path, 0));+ return (+ true,+ Selection.collapsed(+ Position(path: nodes.first.path, offset: 0),+ )+ );}return const (false, null);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dartindex ecc02f7bd9..09b7458eea 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_add_button.dart@@ -58,9 +58,13 @@ class BlockAddButton extends StatelessWidget {final path = isAltPressed ? node.path : node.path.next;transaction.insertNode(path, paragraphNode());- transaction.afterSelection = Selection.collapse(path, 0);+ transaction.afterSelection = Selection.collapsed(+ Position(path: path, offset: 0),+ );} else {- transaction.afterSelection = Selection.collapse(node.path, 0);+ transaction.afterSelection = Selection.collapsed(+ Position(path: node.path, offset: 0),+ );}// show the slash menu.diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dartindex 1b2cffb842..3a51cc4656 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart@@ -231,9 +231,8 @@ class _CalloutBlockComponentWidgetState..updateNode(node, {CalloutBlockKeys.icon: emoji,})- ..afterSelection = Selection.collapse(- node.path,- node.delta?.length ?? 0,+ ..afterSelection = Selection.collapsed(+ Position(path: node.path, offset: node.delta?.length ?? 0),);await editorState.apply(transaction);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dartindex 84eefc5738..727606d0a0 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart@@ -286,9 +286,8 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>..updateNode(node, {CodeBlockKeys.language: language == 'auto' ? null : language,})- ..afterSelection = Selection.collapse(- node.path,- node.delta?.length ?? 0,+ ..afterSelection = Selection.collapsed(+ Position(path: node.path, offset: node.delta?.length ?? 0),);await editorState.apply(transaction);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_shortcut_event.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_shortcut_event.dartindex f8b59c0f67..08cd956d68 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_shortcut_event.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_shortcut_event.dart@@ -161,9 +161,8 @@ CommandShortcutEventHandler _insertNewParagraphNextToCodeBlockCommandHandler =},),)- ..afterSelection = Selection.collapse(- selection.end.path.next,- 0,+ ..afterSelection = Selection.collapsed(+ Position(path: selection.end.path.next, offset: 0),);editorState.apply(transaction);return KeyEventResult.handled;@@ -192,9 +191,11 @@ CommandShortcutEventHandler _tabToInsertSpacesInCodeBlockCommandHandler =index,spaces, // two spaces)- ..afterSelection = Selection.collapse(- selection.end.path,- selection.endIndex + spaces.length,+ ..afterSelection = Selection.collapsed(+ Position(+ path: selection.end.path,+ offset: selection.endIndex + spaces.length,+ ),);editorState.apply(transaction);break;@@ -228,9 +229,11 @@ CommandShortcutEventHandler _tabToDeleteSpacesInCodeBlockCommandHandler =index,spaces.length, // two spaces)- ..afterSelection = Selection.collapse(- selection.end.path,- selection.endIndex - spaces.length,+ ..afterSelection = Selection.collapsed(+ Position(+ path: selection.end.path,+ offset: selection.endIndex - spaces.length,+ ),);editorState.apply(transaction);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dartindex 73add3c6d0..d168e1b4a5 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart@@ -183,9 +183,8 @@ class OutlineItemWidget extends StatelessWidget {void updateBlockSelection(BuildContext context) async {final editorState = context.read<EditorState>();editorState.selectionType = SelectionType.block;- editorState.selection = Selection.collapse(- node.path,- node.delta?.length ?? 0,+ editorState.selection = Selection.collapsed(+ Position(path: node.path, offset: node.delta?.length ?? 0),);WidgetsBinding.instance.addPostFrameCallback((timeStamp) {editorState.selectionType = null;diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dartindex 2be838795a..df44033f50 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart@@ -57,7 +57,9 @@ CharacterShortcutEvent insertChildNodeInsideToggleList = CharacterShortcutEvent(paragraphNode(),)..deleteNode(node)- ..afterSelection = Selection.collapse(selection.start.path, 0);+ ..afterSelection = Selection.collapsed(+ Position(path: selection.start.path, offset: 0),+ );} else {// insert a toggle list block below the current toggle list blocktransaction@@ -66,7 +68,9 @@ CharacterShortcutEvent insertChildNodeInsideToggleList = CharacterShortcutEvent(selection.start.path.next,toggleListBlockNode(collapsed: true, delta: slicedDelta),)- ..afterSelection = Selection.collapse(selection.start.path.next, 0);+ ..afterSelection = Selection.collapsed(+ Position(path: selection.start.path.next, offset: 0),+ );}} else {// insert a paragraph block inside the current toggle list block@@ -76,7 +80,9 @@ CharacterShortcutEvent insertChildNodeInsideToggleList = CharacterShortcutEvent(selection.start.path + [0],paragraphNode(delta: slicedDelta),)- ..afterSelection = Selection.collapse(selection.start.path + [0], 0);+ ..afterSelection = Selection.collapsed(+ Position(path: selection.start.path + [0], offset: 0),+ );}await editorState.apply(transaction);return true;