mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-11-10 10:18:57 +03:00
feat: select all
This commit is contained in:
parent
4794203e74
commit
c42f9001c4
@ -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';
|
||||
|
@ -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,
|
||||
];
|
||||
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user