Fix formatting exception (#1006)

pull/1007/head
Benjamin Quinn 2 years ago committed by GitHub
parent 897a0fbf9f
commit bb31a7901c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      lib/src/widgets/raw_editor.dart

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:math' as math; import 'dart:math' as math;
// ignore: unnecessary_import // ignore: unnecessary_import
import 'dart:typed_data'; import 'dart:typed_data';
@ -266,6 +267,7 @@ class RawEditorState extends EditorState
// Focus // Focus
bool _didAutoFocus = false; bool _didAutoFocus = false;
bool get _hasFocus => widget.focusNode.hasFocus; bool get _hasFocus => widget.focusNode.hasFocus;
// Theme // Theme
@ -275,6 +277,7 @@ class RawEditorState extends EditorState
@override @override
List<Tuple2<int, Style>> get pasteStyle => _pasteStyle; List<Tuple2<int, Style>> get pasteStyle => _pasteStyle;
List<Tuple2<int, Style>> _pasteStyle = <Tuple2<int, Style>>[]; List<Tuple2<int, Style>> _pasteStyle = <Tuple2<int, Style>>[];
@override @override
String get pastePlainText => _pastePlainText; String get pastePlainText => _pastePlainText;
String _pastePlainText = ''; String _pastePlainText = '';
@ -554,13 +557,13 @@ class RawEditorState extends EditorState
} }
void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) { void _updateSelectionForKeyPhrase(String phrase, Attribute attribute) {
controller.replaceText(controller.selection.baseOffset - phrase.length,
phrase.length, '\n', null);
_moveCursor(-phrase.length);
controller controller
..formatSelection(attribute) ..formatSelection(attribute)
..replaceText(controller.selection.baseOffset - phrase.length, // Remove the added newline.
phrase.length, '', null); ..replaceText(controller.selection.baseOffset + 1, 1, '', null);
// It is unclear why the selection moves forward the edit distance.
_moveCursor(-2);
} }
void _handleSelectionChanged( void _handleSelectionChanged(
@ -1678,6 +1681,7 @@ class _DocumentBoundary extends _TextBoundary {
@override @override
TextPosition getLeadingTextBoundaryAt(TextPosition position) => TextPosition getLeadingTextBoundaryAt(TextPosition position) =>
const TextPosition(offset: 0); const TextPosition(offset: 0);
@override @override
TextPosition getTrailingTextBoundaryAt(TextPosition position) { TextPosition getTrailingTextBoundaryAt(TextPosition position) {
return TextPosition( return TextPosition(

Loading…
Cancel
Save