1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Add image dropper

This commit is contained in:
asmsuechan
2017-01-19 01:05:30 +09:00
parent 7b326b99af
commit cda9d53c8e

View File

@@ -163,6 +163,18 @@ export default class CodeEditor extends React.Component {
this.editor.setCursor(cursor)
}
handleDrop (e) {
e.preventDefault()
let path = e.dataTransfer.files[0].path
let filename = path.match(".+/(.+?)\.[a-z]+([\?#;].*)?$")[1]
let imageMd = "![" + filename + "](" + path + ")"
this.insertImage(this.editor.getInputField(), imageMd)
}
insertImage (textarea, imageMd) {
textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd)
}
render () {
let { className, fontFamily, fontSize } = this.props
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
@@ -180,6 +192,7 @@ export default class CodeEditor extends React.Component {
fontFamily: fontFamily.join(', '),
fontSize: fontSize
}}
onDrop={(e) => this.handleDrop(e)}
/>
)
}