Skip to content

Commit bf7ca50

Browse files
authored
Fix drop priorities for notebooks (microsoft#182209)
For copy paste, I added logic to prefer using the text content if there's both `image/*` and `text/*` content in the clipboard This however I also incorrectly applied this logic when dropping. In those cases, we instead want to prefer the image data (at least we do in the case of dragging and dropping from VS Code's explorer)
1 parent 27d61a6 commit bf7ca50

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

extensions/ipynb/src/notebookImagePaste.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class DropOrPasteEditProvider implements vscode.DocumentPasteEditProvider, vscod
4949

5050
private readonly id = 'insertAttachment';
5151

52+
private readonly defaultPriority = 5;
53+
5254
async provideDocumentPasteEdits(
5355
document: vscode.TextDocument,
5456
_ranges: readonly vscode.Range[],
@@ -66,7 +68,7 @@ class DropOrPasteEditProvider implements vscode.DocumentPasteEditProvider, vscod
6668
}
6769

6870
const pasteEdit = new vscode.DocumentPasteEdit(insert.insertText, this.id, vscode.l10n.t('Insert Image as Attachment'));
69-
pasteEdit.priority = this.getPriority(dataTransfer);
71+
pasteEdit.priority = this.getPastePriority(dataTransfer);
7072
pasteEdit.additionalEdit = insert.additionalEdit;
7173
return pasteEdit;
7274
}
@@ -84,20 +86,20 @@ class DropOrPasteEditProvider implements vscode.DocumentPasteEditProvider, vscod
8486

8587
const dropEdit = new vscode.DocumentDropEdit(insert.insertText);
8688
dropEdit.id = this.id;
87-
dropEdit.priority = this.getPriority(dataTransfer);
89+
dropEdit.priority = this.defaultPriority;
8890
dropEdit.additionalEdit = insert.additionalEdit;
8991
dropEdit.label = vscode.l10n.t('Insert Image as Attachment');
9092
return dropEdit;
9193
}
9294

93-
private getPriority(dataTransfer: vscode.DataTransfer): number {
95+
private getPastePriority(dataTransfer: vscode.DataTransfer): number {
9496
if (dataTransfer.get('text/plain')) {
9597
// Deprioritize in favor of normal text content
9698
return -5;
9799
}
98100

99101
// Otherwise boost priority so attachments are preferred
100-
return 5;
102+
return this.defaultPriority;
101103
}
102104

103105
private async createInsertImageAttachmentEdit(

0 commit comments

Comments
 (0)