|
@@ -11,6 +11,7 @@ final List<CommandShortcutEvent> codeBlockCommands = [
|
|
|
insertNewParagraphNextToCodeBlockCommand,
|
|
|
tabToInsertSpacesInCodeBlockCommand,
|
|
|
tabToDeleteSpacesInCodeBlockCommand,
|
|
|
+ selectAllInCodeBlockCommand,
|
|
|
];
|
|
|
|
|
|
/// press the enter key in code block to insert a new line in it.
|
|
@@ -84,6 +85,18 @@ final CommandShortcutEvent tabToDeleteSpacesInCodeBlockCommand =
|
|
|
handler: _tabToDeleteSpacesInCodeBlockCommandHandler,
|
|
|
);
|
|
|
|
|
|
+/// CTRL+A to select all content inside a Code Block, if cursor is inside one.
|
|
|
+///
|
|
|
+/// - support
|
|
|
+/// - desktop
|
|
|
+/// - web
|
|
|
+final CommandShortcutEvent selectAllInCodeBlockCommand = CommandShortcutEvent(
|
|
|
+ key: 'ctrl + a to select all content inside a code block',
|
|
|
+ command: 'ctrl+a',
|
|
|
+ macOSCommand: 'meta+a',
|
|
|
+ handler: _selectAllInCodeBlockCommandHandler,
|
|
|
+);
|
|
|
+
|
|
|
CharacterShortcutEventHandler _enterInCodeBlockCommandHandler =
|
|
|
(editorState) async {
|
|
|
final selection = editorState.selection;
|
|
@@ -227,3 +240,27 @@ CommandShortcutEventHandler _tabToDeleteSpacesInCodeBlockCommandHandler =
|
|
|
}
|
|
|
return KeyEventResult.handled;
|
|
|
};
|
|
|
+
|
|
|
+CommandShortcutEventHandler _selectAllInCodeBlockCommandHandler =
|
|
|
+ (editorState) {
|
|
|
+ final selection = editorState.selection;
|
|
|
+ if (selection == null || !selection.isSingle) {
|
|
|
+ return KeyEventResult.ignored;
|
|
|
+ }
|
|
|
+
|
|
|
+ final node = editorState.getNodeAtPath(selection.end.path);
|
|
|
+ final delta = node?.delta;
|
|
|
+ if (node == null || delta == null || node.type != CodeBlockKeys.type) {
|
|
|
+ return KeyEventResult.ignored;
|
|
|
+ }
|
|
|
+
|
|
|
+ editorState.service.selectionService.updateSelection(
|
|
|
+ Selection.single(
|
|
|
+ path: node.path,
|
|
|
+ startOffset: 0,
|
|
|
+ endOffset: delta.length,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ return KeyEventResult.handled;
|
|
|
+};
|