Explorar o código

feat: select all

Vincent Chan %!s(int64=2) %!d(string=hai) anos
pai
achega
c42f9001c4

+ 0 - 1
frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart

@@ -1,5 +1,4 @@
 import 'package:flowy_editor/flowy_editor.dart';
-import 'package:flowy_editor/src/service/keyboard_service.dart';
 import 'package:flowy_editor/src/infra/html_converter.dart';
 import 'package:flowy_editor/src/document/node_iterator.dart';
 import 'package:flutter/material.dart';

+ 2 - 0
frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/default_key_event_handlers.dart

@@ -7,6 +7,7 @@ import 'package:flowy_editor/src/service/internal_key_event_handlers/redo_undo_h
 import 'package:flowy_editor/src/service/internal_key_event_handlers/slash_handler.dart';
 import 'package:flowy_editor/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart';
 import 'package:flowy_editor/src/service/internal_key_event_handlers/whitespace_handler.dart';
+import 'package:flowy_editor/src/service/internal_key_event_handlers/select_all_handler.dart';
 import 'package:flowy_editor/src/service/keyboard_service.dart';
 
 List<FlowyKeyEventHandler> defaultKeyEventHandlers = [
@@ -19,4 +20,5 @@ List<FlowyKeyEventHandler> defaultKeyEventHandlers = [
   enterWithoutShiftInTextNodesHandler,
   updateTextStyleByCommandXHandler,
   whiteSpaceHandler,
+  selectAllHandler,
 ];

+ 26 - 0
frontend/app_flowy/packages/flowy_editor/lib/src/service/internal_key_event_handlers/select_all_handler.dart

@@ -0,0 +1,26 @@
+import 'package:flowy_editor/flowy_editor.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+KeyEventResult _selectAll(EditorState editorState) {
+  if (editorState.document.root.children.isEmpty) {
+    return KeyEventResult.handled;
+  }
+  final firstNode = editorState.document.root.children.first;
+  final lastNode = editorState.document.root.children.last;
+  var offset = 0;
+  if (lastNode is TextNode) {
+    offset = lastNode.delta.length;
+  }
+  editorState.updateCursorSelection(Selection(
+      start: Position(path: firstNode.path, offset: 0),
+      end: Position(path: lastNode.path, offset: offset)));
+  return KeyEventResult.handled;
+}
+
+FlowyKeyEventHandler selectAllHandler = (editorState, event) {
+  if (event.isMetaPressed && event.logicalKey == LogicalKeyboardKey.keyA) {
+    return _selectAll(editorState);
+  }
+  return KeyEventResult.ignored;
+};