Skip to content

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.

Merge branch 'feat/flowy_editor' into feat/flowy_editor

Lucas.Xu730c85a0dad6
diff --cc frontend/app_flowy/packages/flowy_editor/example/lib/plugin/text_node_widget.dart
index 81c0df2f9c,2b66e3ea7f..dd504305ca
--- a/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/text_node_widget.dart
+++ b/frontend/app_flowy/packages/flowy_editor/example/lib/plugin/text_node_widget.dart
@@@ -131,68 -35,16 +129,72 @@@ class _TextNodeWidget extends StatefulW
State<_TextNodeWidget> createState() => __TextNodeWidgetState();
}
+String _textContentOfDelta(Delta delta) {
+ return delta.operations.fold("", (previousValue, element) {
+ if (element is TextInsert) {
+ return previousValue + element.content;
+ }
+ return previousValue;
+ });
+}
+
class __TextNodeWidgetState extends State<_TextNodeWidget>
- implements TextInputClient {
+ implements DeltaTextInputClient {
+ final _focusNode = FocusNode(debugLabel: "input");
TextNode get node => widget.node as TextNode;
EditorState get editorState => widget.editorState;
+
+ TextEditingValue get textEditingValue => TextEditingValue(
+ text: node.toRawString(),
+ );
+
TextInputConnection? _textInputConnection;
+ _backDeleteTextAtSelection(TextSelection? sel) {
+ if (sel == null) {
+ return;
+ }
+ if (sel.start == 0) {
+ return;
+ }
+
+ if (sel.isCollapsed) {
+ TransactionBuilder(editorState)
+ ..deleteText(node, sel.start - 1, 1)
+ ..commit();
+ } else {
+ TransactionBuilder(editorState)
+ ..deleteText(node, sel.start, sel.extentOffset - sel.baseOffset)
+ ..commit();
+ }
+
+ _setEditingStateFromGlobal();
+ }
+
+ _forwardDeleteTextAtSelection(TextSelection? sel) {
+ if (sel == null) {
+ return;
+ }
+
+ if (sel.isCollapsed) {
+ TransactionBuilder(editorState)
+ ..deleteText(node, sel.start, 1)
+ ..commit();
+ } else {
+ TransactionBuilder(editorState)
+ ..deleteText(node, sel.start, sel.extentOffset - sel.baseOffset)
+ ..commit();
+ }
+ _setEditingStateFromGlobal();
+ }
+
+ _setEditingStateFromGlobal() {
+ _textInputConnection?.setEditingState(TextEditingValue(
+ text: _textContentOfDelta(node.delta),
+ selection: _globalSelectionToLocal(node, editorState.cursorSelection) ??
+ const TextSelection.collapsed(offset: 0)));
+ }
+
@override
Widget build(BuildContext context) {
return Column(