mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Merge pull request #293 from asmsuechan/copy-image-on-dropped-into-CodeEditor
Add dataApi.copyImage for copying image to boostnote storage on an image dropped into CodeEditor
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
|
||||
import _ from 'lodash'
|
||||
import CodeMirror from 'codemirror'
|
||||
import path from 'path'
|
||||
import copyImage from 'browser/main/lib/dataApi/copyImage'
|
||||
|
||||
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||
|
||||
@@ -184,13 +185,16 @@ export default class CodeEditor extends React.Component {
|
||||
e.preventDefault()
|
||||
const imagePath = e.dataTransfer.files[0].path
|
||||
const filename = path.basename(imagePath)
|
||||
const imageMd = `})`
|
||||
this.insertImage(imageMd)
|
||||
|
||||
copyImage(imagePath, this.props.storageKey).then((imagePathInTheStorage) => {
|
||||
const imageMd = ``
|
||||
this.insertImageMd(imageMd)
|
||||
})
|
||||
}
|
||||
|
||||
insertImage (imageMd) {
|
||||
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
|
||||
cm.setValue(cm.getValue() + imageMd)
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
@@ -203,7 +203,7 @@ class MarkdownEditor extends React.Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
let { className, value, config } = this.props
|
||||
let { className, value, config, storageKey } = this.props
|
||||
|
||||
let editorFontSize = parseInt(config.editor.fontSize, 10)
|
||||
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
|
||||
@@ -236,6 +236,7 @@ class MarkdownEditor extends React.Component {
|
||||
fontSize={editorFontSize}
|
||||
indentType={config.editor.indentType}
|
||||
indentSize={editorIndentSize}
|
||||
storageKey={storageKey}
|
||||
onChange={(e) => this.handleChange(e)}
|
||||
onBlur={(e) => this.handleBlur(e)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user