Skip to content

Commit f5ef92b

Browse files
committed
fix: paste Excel/spreadsheet copies as text instead of image (#2960)
The image-paste handlers scanned the clipboard for an image file item and acted on it without checking for co-present text. Excel/Word/spreadsheet copies place BOTH a rendered bitmap and text/plain on the clipboard, so the image always won and cells pasted as an uploaded image. Prefer text when text/plain is present; only treat a paste as an image when the clipboard is image-only (screenshots, copy-image, Finder file copies have no text/plain). Fixes the CodeMirror markdown editor and the mdviewer live-preview paste paths.
1 parent d19df7e commit f5ef92b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src-mdviewer/src/components/editor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,14 @@ function handleImagePaste(e, contentEl) {
711711
if (!items) {
712712
return false;
713713
}
714+
// Spreadsheet/word-processor copies (e.g. Excel cells) place BOTH a rendered
715+
// bitmap AND plain text on the clipboard. Genuine image copies (screenshots,
716+
// copy-image) carry no text/plain. Prefer text when present so such copies
717+
// paste as text, not an uploaded image. See issue #2960.
718+
const pastedText = e.clipboardData.getData && e.clipboardData.getData("text/plain");
719+
if (pastedText && pastedText.length > 0) {
720+
return false;
721+
}
714722
for (let i = 0; i < items.length; i++) {
715723
if (items[i].kind === "file" && ALLOWED_IMAGE_TYPES.includes(items[i].type)) {
716724
e.preventDefault();

src/editor/EditorCommandHandlers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,16 @@ define(function (require, exports, module) {
12991299
return false;
13001300
}
13011301

1302+
// Spreadsheet/word-processor copies (e.g. Excel cells) place BOTH a rendered
1303+
// bitmap AND plain text on the clipboard. Genuine image copies (screenshots,
1304+
// copy-image from a browser/file manager) carry no text/plain. When text is
1305+
// present, prefer the normal text paste instead of uploading the bitmap so
1306+
// Excel cells paste as text, not an image. See issue #2960.
1307+
const pastedText = event.clipboardData.getData && event.clipboardData.getData("text/plain");
1308+
if (pastedText && pastedText.length > 0) {
1309+
return false;
1310+
}
1311+
13021312
// Only handle in markdown files
13031313
const doc = editor.document;
13041314
if (!doc || !doc.file) {

0 commit comments

Comments
 (0)