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

One-click to edit

This commit is contained in:
Rokt33r
2016-01-04 01:45:45 +09:00
parent 47169e19aa
commit fdea9a68a1
4 changed files with 144 additions and 40 deletions

View File

@@ -7,8 +7,14 @@ const electron = require('electron')
const shell = electron.shell
function handleAnchorClick (e) {
shell.openExternal(e.target.href)
e.preventDefault()
e.stopPropagation()
shell.openExternal(e.target.href)
}
function stopPropagation (e) {
e.preventDefault()
e.stopPropagation()
}
export default class MarkdownPreview extends React.Component {
@@ -29,18 +35,22 @@ export default class MarkdownPreview extends React.Component {
}
addListener () {
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a')
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a:not(.lineAnchor)')
for (var i = 0; i < anchors.length; i++) {
anchors[i].addEventListener('click', handleAnchorClick)
anchors[i].addEventListener('mousedown', stopPropagation)
anchors[i].addEventListener('mouseup', stopPropagation)
}
}
removeListener () {
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a')
var anchors = ReactDOM.findDOMNode(this).querySelectorAll('a:not(.lineAnchor)')
for (var i = 0; i < anchors.length; i++) {
anchors[i].removeEventListener('click', handleAnchorClick)
anchors[i].removeEventListener('mousedown', stopPropagation)
anchors[i].removeEventListener('mouseup', stopPropagation)
}
}
@@ -56,13 +66,39 @@ export default class MarkdownPreview extends React.Component {
}
}
handleMouseDown (e) {
if (this.props.onMouseDown) {
this.props.onMouseDown(e)
}
}
handleMouseUp (e) {
if (this.props.onMouseUp) {
this.props.onMouseUp(e)
}
}
handleMouseMove (e) {
if (this.props.onMouseMove) {
this.props.onMouseMove(e)
}
}
render () {
let isEmpty = this.props.content.trim().length === 0
let content = isEmpty
? '(Empty content)'
: this.props.content
return (
<div onDoubleClick={e => this.handleDoubleClick(e)} className={'MarkdownPreview' + (this.props.className != null ? ' ' + this.props.className : '') + (isEmpty ? ' empty' : '')} dangerouslySetInnerHTML={{__html: ' ' + markdown(content)}}/>
<div
className={'MarkdownPreview' + (this.props.className != null ? ' ' + this.props.className : '') + (isEmpty ? ' empty' : '')}
onClick={e => this.handleClick(e)}
onDoubleClick={e => this.handleDoubleClick(e)}
onMouseDown={e => this.handleMouseDown(e)}
onMouseMove={e => this.handleMouseMove(e)}
onMouseUp={e => this.handleMouseUp(e)}
dangerouslySetInnerHTML={{__html: ' ' + markdown(content)}}
/>
)
}
}
@@ -70,6 +106,9 @@ export default class MarkdownPreview extends React.Component {
MarkdownPreview.propTypes = {
onClick: PropTypes.func,
onDoubleClick: PropTypes.func,
onMouseUp: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseMove: PropTypes.func,
className: PropTypes.string,
content: PropTypes.string
}