Fix paste text mess up style and Add support copy/cut block text. (#1321)

* 1. Fix paste text mess up style.
2. Add support copy/cut block text.

* Remove '../../../flutter_quill.dart'
pull/1324/head
He Hong 2 years ago committed by GitHub
parent 517f264140
commit 8aca48274f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 25
      lib/src/models/documents/nodes/line.dart
  3. 3
      lib/src/models/documents/style.dart
  4. 16
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart
  5. 2
      pubspec.yaml

@ -1,3 +1,7 @@
# [7.2.17]
- Fix paste text mess up style.
- Add support copy/cut block text.
# [7.2.16] # [7.2.16]
- Allow for custom context menu. - Allow for custom context menu.

@ -405,25 +405,32 @@ class Line extends Container<Leaf?> {
var node = data.node as Leaf?; var node = data.node as Leaf?;
if (node != null) { if (node != null) {
var pos = 0; var pos = 0;
if (node is Text || node.value is Embeddable) { pos = node.length - data.offset;
pos = node.length - data.offset; if (node is Text && node.style.isNotEmpty) {
result.add(OffsetValue( result.add(OffsetValue(beg, node.style, node.length));
beg, node is Text ? node.style : node.value as Embeddable)); } else if (node.value is Embeddable) {
result.add(OffsetValue(beg, node.value as Embeddable, node.length));
} }
while (!node!.isLast && pos < local) { while (!node!.isLast && pos < local) {
node = node.next as Leaf; node = node.next as Leaf;
if (node is Text || node.value is Embeddable) { if (node is Text && node.style.isNotEmpty) {
result.add(OffsetValue( result.add(OffsetValue(pos + beg, node.style, node.length));
pos + beg, node is Text ? node.style : node.value as Embeddable)); } else if (node.value is Embeddable) {
pos += node.length; result.add(
OffsetValue(pos + beg, node.value as Embeddable, node.length));
} }
pos += node.length;
} }
} }
if (style.isNotEmpty) {
result.add(OffsetValue(beg, style));
}
final remaining = len - local; final remaining = len - local;
if (remaining > 0 && nextLine != null) { if (remaining > 0 && nextLine != null) {
final rest = nextLine! final rest = nextLine!
.collectAllIndividualStylesAndEmbed(0, remaining, beg: local); .collectAllIndividualStylesAndEmbed(0, remaining, beg: local + beg);
result.addAll(rest); result.addAll(rest);
} }

@ -42,6 +42,9 @@ class Style {
bool get isInline => isNotEmpty && values.every((item) => item.isInline); bool get isInline => isNotEmpty && values.every((item) => item.isInline);
bool get isBlock =>
isNotEmpty && values.every((item) => item.scope == AttributeScope.BLOCK);
bool get isIgnored => bool get isIgnored =>
isNotEmpty && values.every((item) => item.scope == AttributeScope.IGNORE); isNotEmpty && values.every((item) => item.scope == AttributeScope.IGNORE);

@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
import '../../models/documents/document.dart'; import '../../models/documents/document.dart';
import '../../models/documents/nodes/embeddable.dart'; import '../../models/documents/nodes/embeddable.dart';
import '../../models/documents/nodes/leaf.dart'; import '../../models/documents/nodes/leaf.dart';
import '../../models/documents/style.dart';
import '../../utils/delta.dart'; import '../../utils/delta.dart';
import '../editor.dart'; import '../editor.dart';
@ -51,12 +52,15 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
if (styleAndEmbed is Embeddable) { if (styleAndEmbed is Embeddable) {
widget.controller.replaceText(pos + offset, 0, styleAndEmbed, null); widget.controller.replaceText(pos + offset, 0, styleAndEmbed, null);
} else { } else {
widget.controller.formatTextStyle( final style = styleAndEmbed as Style;
pos + offset, if (style.isInline) {
i == pasteStyleAndEmbed.length - 1 widget.controller.formatTextStyle(
? pastePlainText.length - offset pos + offset, pasteStyleAndEmbed[i].length!, style);
: pasteStyleAndEmbed[i + 1].offset, } else if (style.isBlock) {
styleAndEmbed); style.values.forEach((attribute) {
widget.controller.document.format(pos + offset, 0, attribute);
});
}
} }
} }
} }

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

Loading…
Cancel
Save