add inserting indents for lines for selected text

pull/1188/head
Bohdan Uhrynovskyi 2 years ago
parent d83cc0cf4c
commit ade9b5ee00
  1. 22
      lib/src/widgets/raw_editor.dart

@ -675,17 +675,16 @@ class RawEditorState extends EditorState
if (event is! RawKeyDownEvent) { if (event is! RawKeyDownEvent) {
return KeyEventResult.ignored; return KeyEventResult.ignored;
} }
// Handle indenting blocks when pressing the tab key.
if (event.logicalKey == LogicalKeyboardKey.tab) {
return _handleTabKey(event);
}
// Don't handle key if there is an active selection. // Don't handle key if there is an active selection.
if (controller.selection.baseOffset != controller.selection.extentOffset) { if (controller.selection.baseOffset != controller.selection.extentOffset) {
return KeyEventResult.ignored; return KeyEventResult.ignored;
} }
// Handle indenting blocks when pressing the tab key.
if (event.logicalKey == LogicalKeyboardKey.tab) {
return _handleTabKey(event);
}
// Handle inserting lists when space is pressed following // Handle inserting lists when space is pressed following
// a list initiating phrase. // a list initiating phrase.
if (event.logicalKey == LogicalKeyboardKey.space) { if (event.logicalKey == LogicalKeyboardKey.space) {
@ -736,6 +735,19 @@ class RawEditorState extends EditorState
return KeyEventResult.handled; return KeyEventResult.handled;
} }
if (controller.selection.baseOffset != controller.selection.extentOffset) {
if (child.node == null || child.node!.parent == null) {
return KeyEventResult.handled;
}
final parentBlock = child.node!.parent!;
if (parentBlock.style.containsKey(Attribute.ol.key) ||
parentBlock.style.containsKey(Attribute.ul.key) ||
parentBlock.style.containsKey(Attribute.checked.key)) {
controller.indentSelection(!event.isShiftPressed);
}
return KeyEventResult.handled;
}
if (child.node == null) { if (child.node == null) {
return insertTabCharacter(); return insertTabCharacter();
} }

Loading…
Cancel
Save