Skip to content

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

Merged
merged 2 commits into from
Jan 21, 2017
Merged

Dropping images into CodeEditor #250

merged 2 commits into from
Jan 21, 2017

Conversation

asmsuechan
Copy link
Contributor

@asmsuechan asmsuechan commented Jan 18, 2017

Hi, I enabled to drop images into CodeEditor like this:
c9b06a9475a795acdd70320159b5a5f1

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

handleDrop (e) {
e.preventDefault()
let path = e.dataTransfer.files[0].path
let filename = path.match(".+/(.+?)\.[a-z]+([\?#;].*)?$")[1]
Copy link
Contributor Author

@asmsuechan asmsuechan Jan 18, 2017

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)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so!

@asmsuechan asmsuechan changed the title Add image dropper dropping images into CodeEditor Jan 18, 2017
@asmsuechan asmsuechan changed the title dropping images into CodeEditor Dropping images into CodeEditor Jan 18, 2017
@asmsuechan
Copy link
Contributor Author

related: #80

@sota1235 sota1235 self-assigned this Jan 21, 2017
}

insertImage (textarea, imageMd) {
textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd)
Copy link
Contributor

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) {
Copy link
Contributor

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 = "![" + filename + "](" + path + ")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use template literal 🙇

@sota1235 sota1235 assigned asmsuechan and unassigned sota1235 Jan 21, 2017
let imageMd = "![" + filename + "](" + path + ")"
this.insertImage(this.editor.getInputField(), imageMd)
let imagePath = e.dataTransfer.files[0].path
let filename = path.basename(imagePath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 😱

@sota1235
Copy link
Contributor

Looks good to me!

@sota1235 sota1235 merged commit 9b17a8f into BoostIO:master Jan 21, 2017
@asmsuechan asmsuechan deleted the add-drop-image branch January 21, 2017 07:29
@sota1235 sota1235 mentioned this pull request Jan 21, 2017
@ahhsia
Copy link

ahhsia commented Aug 15, 2017

Can't seem to get drap and drop images to work under Linux (RHEL7.4 to be specific)
Works on mac Sierra OS however.
Any idea why the linux box doesn't want to do drag and drop?

@mikelu
Copy link

mikelu commented Aug 17, 2017

it seems that image has been handled (stored in image folder) but the link hasn't

@ahhsia
Copy link

ahhsia commented Aug 17, 2017

Looks like it. I have the images folder but it doesn't drop a link in the actual note.

@msbentley
Copy link

+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)

@asmsuechan
Copy link
Contributor Author

asmsuechan commented Aug 19, 2017

Please make sure whether the caret is active.

@asmsuechan
Copy link
Contributor Author

I noticed the caret is completely inactive on ubuntu, so I'll fix it.

@asmsuechan
Copy link
Contributor Author

And Fixed.

@ehhc ehhc mentioned this pull request Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants