From 2334d79e3d7e0b5f6086473ec34e4e8cfd8e27c1 Mon Sep 17 00:00:00 2001 From: Douglas Ward Date: Wed, 24 Apr 2024 07:42:25 -0600 Subject: [PATCH] Move clipboard actions to QuillController --- lib/src/widgets/quill/quill_controller.dart | 209 ++++++++++++++---- lib/src/widgets/raw_editor/raw_editor.dart | 4 +- .../widgets/raw_editor/raw_editor_state.dart | 131 +---------- ...editor_state_selection_delegate_mixin.dart | 60 +---- 4 files changed, 181 insertions(+), 223 deletions(-) diff --git a/lib/src/widgets/quill/quill_controller.dart b/lib/src/widgets/quill/quill_controller.dart index 1a2634e4..4f07f139 100644 --- a/lib/src/widgets/quill/quill_controller.dart +++ b/lib/src/widgets/quill/quill_controller.dart @@ -2,10 +2,13 @@ import 'dart:math' as math; import 'package:flutter/services.dart' show ClipboardData, Clipboard; import 'package:flutter/widgets.dart'; +import 'package:html/parser.dart' as html_parser; import 'package:meta/meta.dart'; +import 'package:super_clipboard/super_clipboard.dart'; import '../../../quill_delta.dart'; import '../../models/documents/attribute.dart'; +import '../../models/documents/delta_x.dart'; import '../../models/documents/document.dart'; import '../../models/documents/nodes/embeddable.dart'; import '../../models/documents/nodes/leaf.dart'; @@ -14,6 +17,7 @@ import '../../models/structs/doc_change.dart'; import '../../models/structs/image_url.dart'; import '../../models/structs/offset_value.dart'; import '../../utils/delta.dart'; +import '../../utils/embeds.dart'; typedef ReplaceTextCallback = bool Function(int index, int len, Object? data); typedef DeleteCallback = void Function(int cursorPosition, bool forward); @@ -111,9 +115,7 @@ class QuillController extends ChangeNotifier { /// Only attributes applied to all characters within this range are /// included in the result. Style getSelectionStyle() { - return document - .collectStyle(selection.start, selection.end - selection.start) - .mergeAll(toggledStyle); + return document.collectStyle(selection.start, selection.end - selection.start).mergeAll(toggledStyle); } // Increases or decreases the indent of the current selection by 1. @@ -182,23 +184,19 @@ class QuillController extends ChangeNotifier { /// Returns all styles and Embed for each node within selection List getAllIndividualSelectionStylesAndEmbed() { - final stylesAndEmbed = document.collectAllIndividualStyleAndEmbed( - selection.start, selection.end - selection.start); + final stylesAndEmbed = document.collectAllIndividualStyleAndEmbed(selection.start, selection.end - selection.start); return stylesAndEmbed; } /// Returns plain text for each node within selection String getPlainText() { - final text = - document.getPlainText(selection.start, selection.end - selection.start); + final text = document.getPlainText(selection.start, selection.end - selection.start); return text; } /// Returns all styles for any character within the specified text range. List