[3.7.2] Reverted Embed toPlainText change

pull/605/head
X Code 3 years ago
parent 7437c920c3
commit 755d7ed72d
  1. 3
      CHANGELOG.md
  2. 8
      lib/src/models/documents/nodes/leaf.dart
  3. 22
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart
  4. 2
      pubspec.yaml

@ -1,3 +1,6 @@
# [3.7.2]
* Reverted Embed toPlainText change.
# [3.7.1]
* Change Embed toPlainText to be empty string.

@ -254,10 +254,8 @@ class Embed extends Leaf {
@override
Embeddable get value => super.value as Embeddable;
// Embed nodes are represented as empty string in plain text.
// Embed nodes are represented as unicode object replacement character in
// plain text.
@override
String toPlainText() => '';
@override
String toString() => kObjectReplacementCharacter;
String toPlainText() => kObjectReplacementCharacter;
}

@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import '../../models/documents/nodes/leaf.dart';
import '../../utils/delta.dart';
import '../editor.dart';
@ -19,9 +20,28 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
final oldText = widget.controller.document.toPlainText();
final newText = value.text;
final diff = getDiff(oldText, newText, cursorPosition);
final insertedText = _adjustInsertedText(diff.inserted);
widget.controller.replaceText(
diff.start, diff.deleted.length, diff.inserted, value.selection);
diff.start, diff.deleted.length, insertedText, value.selection);
}
String _adjustInsertedText(String text) {
// For clip from editor, it may contain image, a.k.a 65532 or '\uFFFC'.
// For clip from browser, image is directly ignore.
// Here we skip image when pasting.
if (!text.codeUnits.contains(Embed.kObjectReplacementInt)) {
return text;
}
final sb = StringBuffer();
for (var i = 0; i < text.length; i++) {
if (text.codeUnitAt(i) == Embed.kObjectReplacementInt) {
continue;
}
sb.write(text[i]);
}
return sb.toString();
}
@override

@ -1,6 +1,6 @@
name: flutter_quill
description: A rich text editor supporting mobile and web (Demo App @ bulletjournal.us)
version: 3.7.1
version: 3.7.2
#author: bulletjournal
homepage: https://bulletjournal.us/home/index.html
repository: https://github.com/singerdmx/flutter-quill

Loading…
Cancel
Save