mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Fix by review
refs: https://github.com/BoostIO/Boostnote/pull/250#pullrequestreview-17801164
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import CodeMirror from 'codemirror'
|
import CodeMirror from 'codemirror'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||||
|
|
||||||
@@ -163,15 +164,16 @@ export default class CodeEditor extends React.Component {
|
|||||||
this.editor.setCursor(cursor)
|
this.editor.setCursor(cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDrop (e) {
|
handleDropImage (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let path = e.dataTransfer.files[0].path
|
let imagePath = e.dataTransfer.files[0].path
|
||||||
let filename = path.match(".+/(.+?)\.[a-z]+([\?#;].*)?$")[1]
|
let filename = path.basename(imagePath)
|
||||||
let imageMd = ""
|
let imageMd = ``
|
||||||
this.insertImage(this.editor.getInputField(), imageMd)
|
this.insertImage(imageMd)
|
||||||
}
|
}
|
||||||
|
|
||||||
insertImage (textarea, imageMd) {
|
insertImage (imageMd) {
|
||||||
|
const textarea = this.editor.getInputField()
|
||||||
textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd)
|
textarea.value = textarea.value.substr(0, textarea.selectionStart) + imageMd + textarea.value.substr(textarea.selectionEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +194,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
fontFamily: fontFamily.join(', '),
|
fontFamily: fontFamily.join(', '),
|
||||||
fontSize: fontSize
|
fontSize: fontSize
|
||||||
}}
|
}}
|
||||||
onDrop={(e) => this.handleDrop(e)}
|
onDrop={(e) => this.handleDropImage(e)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user