From 3f1101e48b40ba330fb9d915dd7ceafc28c61b07 Mon Sep 17 00:00:00 2001 From: frmatthew Date: Wed, 5 Jan 2022 22:27:02 -0800 Subject: [PATCH] Selection completion customizable via callback --- lib/src/widgets/controller.dart | 7 +++---- lib/src/widgets/raw_editor.dart | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/widgets/controller.dart b/lib/src/widgets/controller.dart index 67d47d77..4c12cfe7 100644 --- a/lib/src/widgets/controller.dart +++ b/lib/src/widgets/controller.dart @@ -20,6 +20,7 @@ class QuillController extends ChangeNotifier { bool keepStyleOnNewLine = false, this.onReplaceText, this.onDelete, + this.onSelectionCompleted, }) : _selection = selection, _keepStyleOnNewLine = keepStyleOnNewLine; @@ -48,6 +49,8 @@ class QuillController extends ChangeNotifier { /// Custom delete handler DeleteCallback? onDelete; + void Function()? onSelectionCompleted; + /// Store any styles attribute that got toggled by the tap of a button /// and that has not been applied yet. /// It gets reset after each format action within the [document]. @@ -242,10 +245,6 @@ class QuillController extends ChangeNotifier { notifyListeners(); } - // callback sub classes can override to implement actions when a selection is - // completed. - void selectionCompleted() {} - void compose(Delta delta, TextSelection textSelection, ChangeSource source) { if (delta.isNotEmpty) { document.compose(delta, source); diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index e1e41b1f..20431258 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -377,7 +377,7 @@ class RawEditorState extends EditorState } void _handleSelectionCompleted() { - widget.controller.selectionCompleted(); + widget.controller.onSelectionCompleted?.call(); } /// Updates the checkbox positioned at [offset] in document