Skip to content

Commit

Permalink
feat(core): image drop
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Mar 27, 2020
1 parent 69bd75f commit 0087d58
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/bytemd/src/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@
// console.log(items[i]);
if (!items[i].type.startsWith('image/')) continue;
e.preventDefault();
const url = await fileHandler(items[i].getAsFile());
const text = cm.getSelection();
cm.replaceSelection(`![${text}](${url})`);
cm.focus();
return;
}
});
cm.on('drop', async (_, e) => {
const { items } = e.dataTransfer;
for (let i = 0; i < items.length; i++) {
if (!items[i].type.startsWith('image/')) continue;
e.preventDefault();
const url = await fileHandler(items[i].getAsFile());
const text = cm.getSelection();
Expand Down

0 comments on commit 0087d58

Please sign in to comment.