Skip to content

Commit bb31a79

Browse files
authored
Fix formatting exception (singerdmx#1006)
1 parent 897a0fb commit bb31a79

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/src/widgets/raw_editor.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22
import 'dart:convert';
33
import 'dart:math' as math;
4+
45
// ignore: unnecessary_import
56
import 'dart:typed_data';
67

@@ -266,6 +267,7 @@ class RawEditorState extends EditorState
266267

267268
// Focus
268269
bool _didAutoFocus = false;
270+
269271
bool get _hasFocus => widget.focusNode.hasFocus;
270272

271273
// Theme
@@ -275,6 +277,7 @@ class RawEditorState extends EditorState
275277
@override
276278
List<Tuple2<int, Style>> get pasteStyle => _pasteStyle;
277279
List<Tuple2<int, Style>> _pasteStyle = <Tuple2<int, Style>>[];
280+
278281
@override
279282
String get pastePlainText => _pastePlainText;
280283
String _pastePlainText = '';
@@ -554,13 +557,13 @@ class RawEditorState extends EditorState
554557
}
555558

556559
void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) {
560+
controller.replaceText(controller.selection.baseOffset - phrase.length,
561+
phrase.length, '\n', null);
562+
_moveCursor(-phrase.length);
557563
controller
558564
..formatSelection(attribute)
559-
..replaceText(controller.selection.baseOffset - phrase.length,
560-
phrase.length, '', null);
561-
562-
// It is unclear why the selection moves forward the edit distance.
563-
_moveCursor(-2);
565+
// Remove the added newline.
566+
..replaceText(controller.selection.baseOffset + 1, 1, '', null);
564567
}
565568

566569
void _handleSelectionChanged(
@@ -1678,6 +1681,7 @@ class _DocumentBoundary extends _TextBoundary {
16781681
@override
16791682
TextPosition getLeadingTextBoundaryAt(TextPosition position) =>
16801683
const TextPosition(offset: 0);
1684+
16811685
@override
16821686
TextPosition getTrailingTextBoundaryAt(TextPosition position) {
16831687
return TextPosition(

0 commit comments

Comments
 (0)