Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src-mdviewer/src/components/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,14 @@ function handleImagePaste(e, contentEl) {
if (!items) {
return false;
}
// Spreadsheet/word-processor copies (e.g. Excel cells) place BOTH a rendered
// bitmap AND plain text on the clipboard. Genuine image copies (screenshots,
// copy-image) carry no text/plain. Prefer text when present so such copies
// paste as text, not an uploaded image. See issue #2960.
const pastedText = e.clipboardData.getData && e.clipboardData.getData("text/plain");
if (pastedText && pastedText.length > 0) {
return false;
}
for (let i = 0; i < items.length; i++) {
if (items[i].kind === "file" && ALLOWED_IMAGE_TYPES.includes(items[i].type)) {
e.preventDefault();
Expand Down
10 changes: 10 additions & 0 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,16 @@
return false;
}

// Spreadsheet/word-processor copies (e.g. Excel cells) place BOTH a rendered
// bitmap AND plain text on the clipboard. Genuine image copies (screenshots,
// copy-image from a browser/file manager) carry no text/plain. When text is
// present, prefer the normal text paste instead of uploading the bitmap so
// Excel cells paste as text, not an image. See issue #2960.
const pastedText = event.clipboardData.getData && event.clipboardData.getData("text/plain");

Check warning on line 1307 in src/editor/EditorCommandHandlers.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ-QDO2CLPtZEj4XDlez&open=AZ-QDO2CLPtZEj4XDlez&pullRequest=3033
if (pastedText && pastedText.length > 0) {
return false;
}

// Only handle in markdown files
const doc = editor.document;
if (!doc || !doc.file) {
Expand Down
Loading