diff --git a/CHANGELOG.md b/CHANGELOG.md index 41f53175..10ba7fe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## 9.1.1 * Fix bug [#1636](https://github.com/singerdmx/flutter-quill/issues/1636) +* Fix a where you paste styled content (HTML) it always insert a new line at first even if the document is empty ## 9.1.0 * Fix the simple toolbar by add properties of `IconButton` and fix some buttons diff --git a/lib/src/models/documents/document.dart b/lib/src/models/documents/document.dart index 2945e755..fc55c9c1 100644 --- a/lib/src/models/documents/document.dart +++ b/lib/src/models/documents/document.dart @@ -405,7 +405,8 @@ class Document { void _loadDocument(Delta doc) { if (doc.isEmpty) { - throw ArgumentError.value(doc, 'Document Delta cannot be empty.'); + throw ArgumentError.value( + doc.toString(), 'Document Delta cannot be empty.'); } // print(doc.last.data.runtimeType); diff --git a/lib/src/widgets/raw_editor/raw_editor_state.dart b/lib/src/widgets/raw_editor/raw_editor_state.dart index 4162e533..401e6feb 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state.dart @@ -21,6 +21,7 @@ import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart' show KeyboardVisibilityController; import 'package:super_clipboard/super_clipboard.dart'; +import '../../../quill_delta.dart'; import '../../models/documents/attribute.dart'; import '../../models/documents/document.dart'; import '../../models/documents/nodes/block.dart'; @@ -214,11 +215,15 @@ class QuillRawEditorState extends EditorState return; } final deltaFromCliboard = Document.fromHtml(html); - final delta = deltaFromCliboard.compose(controller.document.toDelta()); + var newDelta = Delta(); + newDelta = newDelta.compose(deltaFromCliboard); + if (!controller.document.isEmpty()) { + newDelta = newDelta.compose(controller.document.toDelta()); + } controller ..setContents( - delta, + newDelta, ) ..updateSelection( TextSelection.collapsed(