-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add dataApi.copyImage for copying image to boostnote storage on an image dropped into CodeEditor #293
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
Add dataApi.copyImage for copying image to boostnote storage on an image dropped into CodeEditor #293
Conversation
|
related: #286 |
|
I'm waiting to be merged #298. |
browser/components/CodeEditor.js
Outdated
| this.insertImage(imageMd) | ||
|
|
||
| copyImage(imagePath, this.props.storageKey).then((imagePathInTheStorage) => { | ||
| 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.
I changed this let to const in #298.
…age to boostnote storage on an image doropped into CodeEditor
| insertImage (imageMd) { | ||
| const textarea = this.editor.getInputField() | ||
| textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd) | ||
| insertImageMd (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.
Good Rename!
| const textarea = this.editor.getInputField() | ||
| textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd) | ||
| insertImageMd (imageMd) { | ||
| const cm = this.editor |
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.
What the mean of cm? If it is not popular wording, I want you to explain more detail.
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.
it's CodeMirror and used this name overall of Boostnote.
| if (!_.isArray(cachedStorageList)) throw new Error('Target storage doesn\'t exist.') | ||
|
|
||
| const storage = _.find(cachedStorageList, {key: storageKey}) | ||
| if (storage == null) throw new Error('Target storage doesn\'t exist.') |
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.
Can't you use ===?
And maybe, _.find returns undefined.
https://lodash.com/docs/4.17.4#find
So you need to write === undefined.
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.
Alright
| if (storage == null) throw new Error('Target storage doesn\'t exist.') | ||
| return storage | ||
| } catch (e) { | ||
| return Promise.reject(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.
Maybe you can write like below.
try {
// Try to get target storage
const targetStorage = 'brabra';
} catch (e) {
// You do not need to try creating 'images' directory
return Promise.reject(e);
}
return new Promise((resolve, reject) => {
// brabra
});
sota1235
left a comment
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 fix some points.
|
@sota1235 I fixed them. |
|
This is going to be a great feature that many people want! |
sota1235
left a comment
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.
LGTM
This PR enable that to copy an image when it is dropped into CodeEditor. It means the image is kept into boostnote storage:
~/Boostnote/images/imageName.png