Skip to content

Commit

Permalink
fix: toolbar style change will be invalid when inputting more than 2 …
Browse files Browse the repository at this point in the history
…characters at a time (#1890)
  • Loading branch information
crasowas authored May 23, 2024
1 parent 61c129c commit 6d99d40
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/src/widgets/quill/quill_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ class QuillController extends ChangeNotifier {
var shouldRetainDelta = toggledStyle.isNotEmpty &&
delta.isNotEmpty &&
delta.length <= 2 &&
delta.last.isInsert &&
// pasted text should not use toggledStyle
(data is! String || data.length < 2);
delta.last.isInsert;
if (shouldRetainDelta &&
toggledStyle.isNotEmpty &&
delta.length == 2 &&
Expand Down Expand Up @@ -518,13 +516,27 @@ class QuillController extends ChangeNotifier {
// See https://github.com/flutter/flutter/issues/11427
final plainText = await Clipboard.getData(Clipboard.kTextPlain);
if (plainText != null) {
replaceTextWithEmbeds(
selection.start,
selection.end - selection.start,
plainText.text!,
TextSelection.collapsed(
offset: selection.start + plainText.text!.length),
);
final lines = plainText.text!.split('\n');
for (var i = 0; i < lines.length; ++i) {
final line = lines[i];
if (line.isNotEmpty) {
replaceTextWithEmbeds(
selection.start,
selection.end - selection.start,
line,
TextSelection.collapsed(offset: selection.start + line.length),
);
}
if (i != lines.length - 1) {
document.insert(selection.extentOffset, '\n');
_updateSelection(
TextSelection.collapsed(
offset: selection.extentOffset + 1,
),
insertNewline: true,
);
}
}
updateEditor?.call();
return true;
}
Expand Down

0 comments on commit 6d99d40

Please sign in to comment.