Custom replaceText handler (#494)

* ukraine language support

* targetChild error temporary fix

* fix attributes compare

* font size parsing fix

* manual replace text handler
pull/496/head
Andy Trand 3 years ago committed by GitHub
parent 1b562c5b79
commit b59e360091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      lib/src/widgets/controller.dart

@ -10,11 +10,14 @@ import '../models/documents/style.dart';
import '../models/quill_delta.dart';
import '../utils/diff_delta.dart';
typedef ReplaceTextCallback = bool Function(int index, int len, Object? data);
class QuillController extends ChangeNotifier {
QuillController({
required this.document,
required TextSelection selection,
bool keepStyleOnNewLine = false,
this.onReplaceText,
}) : _selection = selection,
_keepStyleOnNewLine = keepStyleOnNewLine;
@ -36,6 +39,10 @@ class QuillController extends ChangeNotifier {
TextSelection get selection => _selection;
TextSelection _selection;
/// Manual [replaceText] handler
/// Return false to ignore the event
ReplaceTextCallback? onReplaceText;
/// 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].
@ -115,6 +122,10 @@ class QuillController extends ChangeNotifier {
{bool ignoreFocus = false}) {
assert(data is String || data is Embeddable);
if (onReplaceText != null && !onReplaceText!(index, len, data)) {
return;
}
Delta? delta;
if (len > 0 || data is! String || data.isNotEmpty) {
delta = document.replace(index, len, data);

Loading…
Cancel
Save