Create struct for individual styles

offsetvalue
pull/1128/head
Adil Hanney 2 years ago
parent a122ee7dc3
commit 3c55db11dc
  1. 3
      lib/flutter_quill.dart
  2. 3
      lib/src/models/documents/document.dart
  3. 9
      lib/src/models/documents/nodes/line.dart
  4. 5
      lib/src/models/structs/offset_value.dart
  5. 4
      lib/src/widgets/controller.dart
  6. 3
      lib/src/widgets/editor.dart
  7. 5
      lib/src/widgets/raw_editor.dart
  8. 6
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart

@ -10,6 +10,9 @@ export 'src/models/documents/nodes/node.dart';
export 'src/models/documents/style.dart'; export 'src/models/documents/style.dart';
export 'src/models/quill_delta.dart'; export 'src/models/quill_delta.dart';
export 'src/models/structs/doc_change.dart'; export 'src/models/structs/doc_change.dart';
export 'src/models/structs/image_url.dart';
export 'src/models/structs/offset_value.dart';
export 'src/models/structs/optional_size.dart';
export 'src/models/structs/vertical_spacing.dart'; export 'src/models/structs/vertical_spacing.dart';
export 'src/models/themes/quill_custom_button.dart'; export 'src/models/themes/quill_custom_button.dart';
export 'src/models/themes/quill_dialog_theme.dart'; export 'src/models/themes/quill_dialog_theme.dart';

@ -3,6 +3,7 @@ import 'dart:async';
import '../quill_delta.dart'; import '../quill_delta.dart';
import '../rules/rule.dart'; import '../rules/rule.dart';
import '../structs/doc_change.dart'; import '../structs/doc_change.dart';
import '../structs/offset_value.dart';
import 'attribute.dart'; import 'attribute.dart';
import 'history.dart'; import 'history.dart';
import 'nodes/block.dart'; import 'nodes/block.dart';
@ -156,7 +157,7 @@ class Document {
} }
/// Returns all styles for each node within selection /// Returns all styles for each node within selection
List<Tuple2<int, Style>> collectAllIndividualStyles(int index, int len) { List<OffsetValue<Style>> collectAllIndividualStyles(int index, int len) {
final res = queryChild(index); final res = queryChild(index);
return (res.node as Line).collectAllIndividualStyles(res.offset, len); return (res.node as Line).collectAllIndividualStyles(res.offset, len);
} }

@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import '../../quill_delta.dart'; import '../../quill_delta.dart';
import '../../structs/offset_value.dart';
import '../attribute.dart'; import '../attribute.dart';
import '../style.dart'; import '../style.dart';
import 'block.dart'; import 'block.dart';
@ -390,10 +391,10 @@ class Line extends Container<Leaf?> {
/// Returns each node segment's offset in selection /// Returns each node segment's offset in selection
/// with its corresponding style as a list /// with its corresponding style as a list
List<Tuple2<int, Style>> collectAllIndividualStyles(int offset, int len, List<OffsetValue<Style>> collectAllIndividualStyles(int offset, int len,
{int beg = 0}) { {int beg = 0}) {
final local = math.min(length - offset, len); final local = math.min(length - offset, len);
final result = <Tuple2<int, Style>>[]; final result = <OffsetValue<Style>>[];
final data = queryChild(offset, true); final data = queryChild(offset, true);
var node = data.node as Leaf?; var node = data.node as Leaf?;
@ -401,12 +402,12 @@ class Line extends Container<Leaf?> {
var pos = 0; var pos = 0;
if (node is Text) { if (node is Text) {
pos = node.length - data.offset; pos = node.length - data.offset;
result.add(Tuple2(beg, node.style)); result.add(OffsetValue(beg, node.style));
} }
while (!node!.isLast && pos < local) { while (!node!.isLast && pos < local) {
node = node.next as Leaf; node = node.next as Leaf;
if (node is Text) { if (node is Text) {
result.add(Tuple2(pos + beg, node.style)); result.add(OffsetValue(pos + beg, node.style));
pos += node.length; pos += node.length;
} }
} }

@ -0,0 +1,5 @@
class OffsetValue<T> {
OffsetValue(this.offset, this.value);
final int offset;
final T value;
}

@ -10,6 +10,8 @@ import '../models/documents/nodes/leaf.dart';
import '../models/documents/style.dart'; import '../models/documents/style.dart';
import '../models/quill_delta.dart'; import '../models/quill_delta.dart';
import '../models/structs/doc_change.dart'; import '../models/structs/doc_change.dart';
import '../models/structs/image_url.dart';
import '../models/structs/offset_value.dart';
import '../utils/delta.dart'; import '../utils/delta.dart';
typedef ReplaceTextCallback = bool Function(int index, int len, Object? data); typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
@ -118,7 +120,7 @@ class QuillController extends ChangeNotifier {
} }
/// Returns all styles for each node within selection /// Returns all styles for each node within selection
List<Tuple2<int, Style>> getAllIndividualSelectionStyles() { List<OffsetValue<Style>> getAllIndividualSelectionStyles() {
final styles = document.collectAllIndividualStyles( final styles = document.collectAllIndividualStyles(
selection.start, selection.end - selection.start); selection.start, selection.end - selection.start);
return styles; return styles;

@ -15,6 +15,7 @@ import '../models/documents/nodes/container.dart' as container_node;
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 '../models/documents/style.dart';
import '../models/structs/offset_value.dart';
import '../utils/platform.dart'; import '../utils/platform.dart';
import 'box.dart'; import 'box.dart';
import 'controller.dart'; import 'controller.dart';
@ -37,7 +38,7 @@ abstract class EditorState extends State<RawEditor>
EditorTextSelectionOverlay? get selectionOverlay; EditorTextSelectionOverlay? get selectionOverlay;
List<Tuple2<int, Style>> get pasteStyle; List<OffsetValue<Style>> get pasteStyle;
String get pastePlainText; String get pastePlainText;

@ -13,6 +13,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:pasteboard/pasteboard.dart'; import 'package:pasteboard/pasteboard.dart';
import '../../flutter_quill.dart';
import '../models/documents/attribute.dart'; import '../models/documents/attribute.dart';
import '../models/documents/document.dart'; import '../models/documents/document.dart';
import '../models/documents/nodes/block.dart'; import '../models/documents/nodes/block.dart';
@ -288,8 +289,8 @@ class RawEditorState extends EditorState
// for pasting style // for pasting style
@override @override
List<Tuple2<int, Style>> get pasteStyle => _pasteStyle; List<OffsetValue<Style>> get pasteStyle => _pasteStyle;
List<Tuple2<int, Style>> _pasteStyle = <Tuple2<int, Style>>[]; List<OffsetValue<Style>> _pasteStyle = <OffsetValue<Style>>[];
@override @override
String get pastePlainText => _pastePlainText; String get pastePlainText => _pastePlainText;

@ -38,13 +38,13 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
if (insertedText == pastePlainText && pastePlainText != '') { if (insertedText == pastePlainText && pastePlainText != '') {
final pos = start; final pos = start;
for (var i = 0; i < pasteStyle.length; i++) { for (var i = 0; i < pasteStyle.length; i++) {
final offset = pasteStyle[i].item1; final offset = pasteStyle[i].offset;
final style = pasteStyle[i].item2; final style = pasteStyle[i].value;
widget.controller.formatTextStyle( widget.controller.formatTextStyle(
pos + offset, pos + offset,
i == pasteStyle.length - 1 i == pasteStyle.length - 1
? pastePlainText.length - offset ? pastePlainText.length - offset
: pasteStyle[i + 1].item1, : pasteStyle[i + 1].offset,
style); style);
} }
} }

Loading…
Cancel
Save