Skip to content

Commit

Permalink
feat: paste list children nodes (#863)
Browse files Browse the repository at this point in the history
* feat: paste list children nodes

also export copy paste extension so we can use it in AppFlowy

* fix: unnecessary import
  • Loading branch information
zoli authored Aug 10, 2024
1 parent 0317779 commit bcc5a53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/src/editor/editor_component/editor_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export 'service/scroll_service.dart';
export 'service/scroll_service_widget.dart';
export 'service/selection_service.dart';
export 'service/selection_service_widget.dart';
export 'service/shortcuts/command/copy_paste_extension.dart';
// shortcuts
export 'service/shortcut_events.dart';
export 'style/default_text_span_decorator_for_attribute.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import 'package:appflowy_editor/appflowy_editor.dart';

final _listTypes = [
BulletedListBlockKeys.type,
TodoListBlockKeys.type,
NumberedListBlockKeys.type,
];

extension EditorCopyPaste on EditorState {
Future<void> pasteSingleLineNode(Node insertedNode) async {
final selection = await deleteSelectionIfNeeded();
Expand Down Expand Up @@ -31,6 +37,9 @@ extension EditorCopyPaste on EditorState {
} else if (insertedDelta != null) {
// if the node is not empty, insert the delta from inserted node after the selection.
transaction.insertTextDelta(node, selection.endIndex, insertedDelta);
if (_listTypes.contains(node.type) && insertedNode.children.isNotEmpty) {
transaction.insertNodes(node.path + [0], insertedNode.children);
}
}
await apply(transaction);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/command/copy_paste_extension.dart';
import 'package:flutter/material.dart';

final List<CommandShortcutEvent> pasteCommands = [
Expand Down

0 comments on commit bcc5a53

Please sign in to comment.