Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clipboard image pasting #2384

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading