Skip to content

Commit

Permalink
Fix clipboard image pasting (#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim-Nikolaev authored Nov 17, 2024
1 parent 278e15d commit c804c08
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/src/controller/quill_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,6 @@ class QuillController extends ChangeNotifier {
}
}

// Snapshot the input before using `await`.
// See https://github.com/flutter/flutter/issues/11427
final plainText = (await Clipboard.getData(Clipboard.kTextPlain))?.text;
if (plainText != null) {
final plainTextToPaste = await getTextToPaste(plainText);
if (pastePlainTextOrDelta(plainTextToPaste,
pastePlainText: _pastePlainText, pasteDelta: _pasteDelta)) {
updateEditor?.call();
return true;
}
}

final clipboardService = ClipboardServiceProvider.instance;

final onImagePaste = clipboardConfig?.onImagePaste;
Expand All @@ -609,6 +597,8 @@ class QuillController extends ChangeNotifier {
BlockEmbed.image(imageUrl),
null,
);
updateEditor?.call();
return true;
}
}
}
Expand All @@ -625,10 +615,26 @@ class QuillController extends ChangeNotifier {
BlockEmbed.image(gifUrl),
null,
);
updateEditor?.call();
return true;
}
}
}

// Only process plain text if no image/gif was pasted.
// Snapshot the input before using `await`.
// See https://github.com/flutter/flutter/issues/11427
final plainText = (await Clipboard.getData(Clipboard.kTextPlain))?.text;

if (plainText != null) {
final plainTextToPaste = await getTextToPaste(plainText);
if (pastePlainTextOrDelta(plainTextToPaste,
pastePlainText: _pastePlainText, pasteDelta: _pasteDelta)) {
updateEditor?.call();
return true;
}
}

final onUnprocessedPaste = clipboardConfig?.onUnprocessedPaste;
if (onUnprocessedPaste != null) {
if (await onUnprocessedPaste()) {
Expand Down

0 comments on commit c804c08

Please sign in to comment.