1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Merge pull request #2591 from daiyam/drop-image-preview

drag image into preview
This commit is contained in:
Junyoung Choi
2018-12-24 17:19:41 +09:00
committed by GitHub
2 changed files with 32 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import MarkdownPreview from 'browser/components/MarkdownPreview'
import eventEmitter from 'browser/main/lib/eventEmitter' import eventEmitter from 'browser/main/lib/eventEmitter'
import { findStorage } from 'browser/lib/findStorage' import { findStorage } from 'browser/lib/findStorage'
import ConfigManager from 'browser/main/lib/ConfigManager' import ConfigManager from 'browser/main/lib/ConfigManager'
import attachmentManagement from 'browser/main/lib/dataApi/attachmentManagement'
class MarkdownEditor extends React.Component { class MarkdownEditor extends React.Component {
constructor (props) { constructor (props) {
@@ -221,6 +222,28 @@ class MarkdownEditor extends React.Component {
this.refs.code.editor.replaceSelection(`${mdElement}${this.refs.code.editor.getSelection()}${mdElement}`) this.refs.code.editor.replaceSelection(`${mdElement}${this.refs.code.editor.getSelection()}${mdElement}`)
} }
handleDropImage (dropEvent) {
dropEvent.preventDefault()
const { storageKey, noteKey } = this.props
this.setState({
status: 'CODE'
}, () => {
this.refs.code.focus()
this.refs.code.editor.execCommand('goDocEnd')
this.refs.code.editor.execCommand('goLineEnd')
this.refs.code.editor.execCommand('newlineAndIndent')
attachmentManagement.handleAttachmentDrop(
this.refs.code,
storageKey,
noteKey,
dropEvent
)
})
}
handleKeyUp (e) { handleKeyUp (e) {
const keyPressed = this.state.keyPressed const keyPressed = this.state.keyPressed
keyPressed.delete(e.keyCode) keyPressed.delete(e.keyCode)
@@ -315,6 +338,7 @@ class MarkdownEditor extends React.Component {
customCSS={config.preview.customCSS} customCSS={config.preview.customCSS}
allowCustomCSS={config.preview.allowCustomCSS} allowCustomCSS={config.preview.allowCustomCSS}
lineThroughCheckbox={config.preview.lineThroughCheckbox} lineThroughCheckbox={config.preview.lineThroughCheckbox}
onDrop={(e) => this.handleDropImage(e)}
/> />
</div> </div>
) )

View File

@@ -210,7 +210,7 @@ export default class MarkdownPreview extends React.Component {
this.saveAsHtmlHandler = () => this.handleSaveAsHtml() this.saveAsHtmlHandler = () => this.handleSaveAsHtml()
this.printHandler = () => this.handlePrint() this.printHandler = () => this.handlePrint()
this.linkClickHandler = this.handlelinkClick.bind(this) this.linkClickHandler = this.handleLinkClick.bind(this)
this.initMarkdown = this.initMarkdown.bind(this) this.initMarkdown = this.initMarkdown.bind(this)
this.initMarkdown() this.initMarkdown()
} }
@@ -413,6 +413,8 @@ export default class MarkdownPreview extends React.Component {
} }
componentDidMount () { componentDidMount () {
const { onDrop } = this.props
this.refs.root.setAttribute('sandbox', 'allow-scripts') this.refs.root.setAttribute('sandbox', 'allow-scripts')
this.refs.root.contentWindow.document.body.addEventListener( this.refs.root.contentWindow.document.body.addEventListener(
'contextmenu', 'contextmenu',
@@ -450,7 +452,7 @@ export default class MarkdownPreview extends React.Component {
) )
this.refs.root.contentWindow.document.addEventListener( this.refs.root.contentWindow.document.addEventListener(
'drop', 'drop',
this.preventImageDroppedHandler onDrop || this.preventImageDroppedHandler
) )
this.refs.root.contentWindow.document.addEventListener( this.refs.root.contentWindow.document.addEventListener(
'dragover', 'dragover',
@@ -467,6 +469,8 @@ export default class MarkdownPreview extends React.Component {
} }
componentWillUnmount () { componentWillUnmount () {
const { onDrop } = this.props
this.refs.root.contentWindow.document.body.removeEventListener( this.refs.root.contentWindow.document.body.removeEventListener(
'contextmenu', 'contextmenu',
this.contextMenuHandler this.contextMenuHandler
@@ -485,7 +489,7 @@ export default class MarkdownPreview extends React.Component {
) )
this.refs.root.contentWindow.document.removeEventListener( this.refs.root.contentWindow.document.removeEventListener(
'drop', 'drop',
this.preventImageDroppedHandler onDrop || this.preventImageDroppedHandler
) )
this.refs.root.contentWindow.document.removeEventListener( this.refs.root.contentWindow.document.removeEventListener(
'dragover', 'dragover',
@@ -840,7 +844,7 @@ export default class MarkdownPreview extends React.Component {
return new window.Notification(title, options) return new window.Notification(title, options)
} }
handlelinkClick (e) { handleLinkClick (e) {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()