mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: migrate to the latest api
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 block
|
||||
transaction
|
||||
@ -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;
|
||||
|
Reference in New Issue
Block a user