@@ -7,8 +7,14 @@ const electron = require('electron')
77const shell = electron . shell
88
99function handleAnchorClick ( e ) {
10+ e . preventDefault ( )
11+ e . stopPropagation ( )
1012 shell . openExternal ( e . target . href )
13+ }
14+
15+ function stopPropagation ( e ) {
1116 e . preventDefault ( )
17+ e . stopPropagation ( )
1218}
1319
1420export default class MarkdownPreview extends React . Component {
@@ -29,18 +35,22 @@ export default class MarkdownPreview extends React.Component {
2935 }
3036
3137 addListener ( ) {
32- var anchors = ReactDOM . findDOMNode ( this ) . querySelectorAll ( 'a' )
38+ var anchors = ReactDOM . findDOMNode ( this ) . querySelectorAll ( 'a:not(.lineAnchor) ' )
3339
3440 for ( var i = 0 ; i < anchors . length ; i ++ ) {
3541 anchors [ i ] . addEventListener ( 'click' , handleAnchorClick )
42+ anchors [ i ] . addEventListener ( 'mousedown' , stopPropagation )
43+ anchors [ i ] . addEventListener ( 'mouseup' , stopPropagation )
3644 }
3745 }
3846
3947 removeListener ( ) {
40- var anchors = ReactDOM . findDOMNode ( this ) . querySelectorAll ( 'a' )
48+ var anchors = ReactDOM . findDOMNode ( this ) . querySelectorAll ( 'a:not(.lineAnchor) ' )
4149
4250 for ( var i = 0 ; i < anchors . length ; i ++ ) {
4351 anchors [ i ] . removeEventListener ( 'click' , handleAnchorClick )
52+ anchors [ i ] . removeEventListener ( 'mousedown' , stopPropagation )
53+ anchors [ i ] . removeEventListener ( 'mouseup' , stopPropagation )
4454 }
4555 }
4656
@@ -56,20 +66,49 @@ export default class MarkdownPreview extends React.Component {
5666 }
5767 }
5868
69+ handleMouseDown ( e ) {
70+ if ( this . props . onMouseDown ) {
71+ this . props . onMouseDown ( e )
72+ }
73+ }
74+
75+ handleMouseUp ( e ) {
76+ if ( this . props . onMouseUp ) {
77+ this . props . onMouseUp ( e )
78+ }
79+ }
80+
81+ handleMouseMove ( e ) {
82+ if ( this . props . onMouseMove ) {
83+ this . props . onMouseMove ( e )
84+ }
85+ }
86+
5987 render ( ) {
6088 let isEmpty = this . props . content . trim ( ) . length === 0
6189 let content = isEmpty
6290 ? '(Empty content)'
6391 : this . props . content
6492 return (
65- < div onDoubleClick = { e => this . handleDoubleClick ( e ) } className = { 'MarkdownPreview' + ( this . props . className != null ? ' ' + this . props . className : '' ) + ( isEmpty ? ' empty' : '' ) } dangerouslySetInnerHTML = { { __html : ' ' + markdown ( content ) } } />
93+ < div
94+ className = { 'MarkdownPreview' + ( this . props . className != null ? ' ' + this . props . className : '' ) + ( isEmpty ? ' empty' : '' ) }
95+ onClick = { e => this . handleClick ( e ) }
96+ onDoubleClick = { e => this . handleDoubleClick ( e ) }
97+ onMouseDown = { e => this . handleMouseDown ( e ) }
98+ onMouseMove = { e => this . handleMouseMove ( e ) }
99+ onMouseUp = { e => this . handleMouseUp ( e ) }
100+ dangerouslySetInnerHTML = { { __html : ' ' + markdown ( content ) } }
101+ />
66102 )
67103 }
68104}
69105
70106MarkdownPreview . propTypes = {
71107 onClick : PropTypes . func ,
72108 onDoubleClick : PropTypes . func ,
109+ onMouseUp : PropTypes . func ,
110+ onMouseDown : PropTypes . func ,
111+ onMouseMove : PropTypes . func ,
73112 className : PropTypes . string ,
74113 content : PropTypes . string
75114}
0 commit comments