Hello,
In a plugin, I try to get a pasted file (e.g. : a .mp3
from file explorer), but the test item.kind == "file"
is apparently never reached:
[...]
this.registerEvent(this.app.workspace.on('editor-paste', this.handlePaste.bind(this)));
[...]
async handlePaste(event: ClipboardEvent, editor: Editor, view: MarkdownView){
let clipBoardData = event.clipboardData;
let clipBoardItems = clipBoardData.items;
[...]
if(!clipBoardData.getData('text/plain')){
for(let i in clipBoardItems){
if(!clipBoardItems.hasOwnProperty(i))
continue;
let item = clipBoardItems[i];
if(item.kind == "file"){
// This is never reached !
[...]
}
}
}
}
It works only when pasting a screenshot taken using PrintScr, not when pasting files from file explorer.
When I console.log(clipBoardItems)
, I get DataTransferItemList {0: DataTransferItem, length: 1}
when pasting a screenshot taken using PrintScr, and DataTransferItemList {length: 0}
when pasting a file copied from file explorer.
It seems ClipboardEvent is not compatible with file explorer ? So I wonder how Obsidian does paste files from explorer ?