-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Dropping images into CodeEditor #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
handleDrop (e) { | ||
e.preventDefault() | ||
let path = e.dataTransfer.files[0].path | ||
let filename = path.match(".+/(.+?)\.[a-z]+([\?#;].*)?$")[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I use path
(liblary)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so!
related: #80 |
} | ||
|
||
insertImage (textarea, imageMd) { | ||
textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who don't you call this.editor.getInputField()
in this method?
@@ -163,6 +163,18 @@ export default class CodeEditor extends React.Component { | |||
this.editor.setCursor(cursor) | |||
} | |||
|
|||
handleDrop (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think handleDropImage
is better. Because supporting image only.
e.preventDefault() | ||
let path = e.dataTransfer.files[0].path | ||
let filename = path.match(".+/(.+?)\.[a-z]+([\?#;].*)?$")[1] | ||
let imageMd = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use template literal 🙇
let imageMd = "" | ||
this.insertImage(this.editor.getInputField(), imageMd) | ||
let imagePath = e.dataTransfer.files[0].path | ||
let filename = path.basename(imagePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel let filename = path.split("/").pop()
is good enough actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it works on macOS. But on windows, path delimiters may be backslash.
I think this way is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I forget Mr windows 😱
Looks good to me! |
Can't seem to get drap and drop images to work under Linux (RHEL7.4 to be specific) |
it seems that image has been handled (stored in image folder) but the link hasn't |
Looks like it. I have the images folder but it doesn't drop a link in the actual note. |
+1 with the latest release (0.8.14) on ubuntu 17.04 (pictures is copied to the correct folder with a randomised name, but no link is inserted into the note) |
Please make sure whether the caret is active. |
I noticed the caret is completely inactive on ubuntu, so I'll fix it. |
And Fixed. |
Hi, I enabled to drop images into CodeEditor like this:

Next, to handle broken link, I should implement saving images into a directory for boostnote.