diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index e480bc57..f49f52ef 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:math' as math; + // ignore: unnecessary_import import 'dart:typed_data'; @@ -17,9 +18,9 @@ import '../models/documents/attribute.dart'; import '../models/documents/document.dart'; import '../models/documents/nodes/block.dart'; import '../models/documents/nodes/embeddable.dart'; +import '../models/documents/nodes/leaf.dart' as leaf; import '../models/documents/nodes/line.dart'; import '../models/documents/nodes/node.dart'; -import '../models/documents/nodes/leaf.dart' as leaf; import '../models/documents/style.dart'; import '../utils/cast.dart'; import '../utils/delta.dart'; @@ -266,6 +267,7 @@ class RawEditorState extends EditorState // Focus bool _didAutoFocus = false; + bool get _hasFocus => widget.focusNode.hasFocus; // Theme @@ -275,6 +277,7 @@ class RawEditorState extends EditorState @override List> get pasteStyle => _pasteStyle; List> _pasteStyle = >[]; + @override String get pastePlainText => _pastePlainText; String _pastePlainText = ''; @@ -553,13 +556,13 @@ class RawEditorState extends EditorState } void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) { + controller.replaceText(controller.selection.baseOffset - phrase.length, + phrase.length, '\n', null); + _moveCursor(-phrase.length); controller ..formatSelection(attribute) - ..replaceText(controller.selection.baseOffset - phrase.length, - phrase.length, '', null); - - // It is unclear why the selection moves forward the edit distance. - _moveCursor(-2); + // Remove the added newline. + ..replaceText(controller.selection.baseOffset + 1, 1, '', null); } void _handleSelectionChanged( @@ -1677,6 +1680,7 @@ class _DocumentBoundary extends _TextBoundary { @override TextPosition getLeadingTextBoundaryAt(TextPosition position) => const TextPosition(offset: 0); + @override TextPosition getTrailingTextBoundaryAt(TextPosition position) { return TextPosition(