diff --git a/CHANGELOG.md b/CHANGELOG.md index 88394da2..f636b52d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# [3.7.1] +* Change Embed toPlainText to be empty string. + # [3.7.0] * Replace Toolbar showHistory group with individual showRedo and showUndo. diff --git a/lib/src/models/documents/nodes/container.dart b/lib/src/models/documents/nodes/container.dart index 40d3ba9e..031e064f 100644 --- a/lib/src/models/documents/nodes/container.dart +++ b/lib/src/models/documents/nodes/container.dart @@ -157,4 +157,10 @@ class ChildQuery { /// character in the document as the original offset passed to /// [Container.queryChild] method. final int offset; + + /// Returns `true` if there is no child node found, e.g. [node] is `null`. + bool get isEmpty => node == null; + + /// Returns `true` [node] is not `null`. + bool get isNotEmpty => node != null; } diff --git a/lib/src/models/documents/nodes/leaf.dart b/lib/src/models/documents/nodes/leaf.dart index feab276c..7fffa60a 100644 --- a/lib/src/models/documents/nodes/leaf.dart +++ b/lib/src/models/documents/nodes/leaf.dart @@ -254,8 +254,10 @@ class Embed extends Leaf { @override Embeddable get value => super.value as Embeddable; - // Embed nodes are represented as unicode object replacement character in - // plain text. + // Embed nodes are represented as empty string in plain text. @override - String toPlainText() => kObjectReplacementCharacter; + String toPlainText() => ''; + + @override + String toString() => kObjectReplacementCharacter; } diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 4982c801..01a39db3 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -3,7 +3,6 @@ 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'; @@ -20,28 +19,9 @@ 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, 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(); + diff.start, diff.deleted.length, diff.inserted, value.selection); } @override diff --git a/pubspec.yaml b/pubspec.yaml index 65a6b7bd..7b7e31fc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor supporting mobile and web (Demo App @ bulletjournal.us) -version: 3.7.0 +version: 3.7.1 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill