@@ -14,6 +14,10 @@ class MarkdownSplitEditor extends React.Component {
1414 this . focus = ( ) => this . refs . code . focus ( )
1515 this . reload = ( ) => this . refs . code . reload ( )
1616 this . userScroll = true
17+ this . state = {
18+ isSliderFocused : false ,
19+ codeEditorWidthInPercent : 50
20+ }
1721 }
1822
1923 handleOnChange ( ) {
@@ -87,6 +91,42 @@ class MarkdownSplitEditor extends React.Component {
8791 }
8892 }
8993
94+ handleMouseMove ( e ) {
95+ if ( this . state . isSliderFocused ) {
96+ const rootRect = this . refs . root . getBoundingClientRect ( )
97+ const rootWidth = rootRect . width
98+ const offset = rootRect . left
99+ let newCodeEditorWidthInPercent = ( e . pageX - offset ) / rootWidth * 100
100+
101+ // limit minSize to 10%, maxSize to 90%
102+ if ( newCodeEditorWidthInPercent <= 10 ) {
103+ newCodeEditorWidthInPercent = 10
104+ }
105+
106+ if ( newCodeEditorWidthInPercent >= 90 ) {
107+ newCodeEditorWidthInPercent = 90
108+ }
109+
110+ this . setState ( {
111+ codeEditorWidthInPercent : newCodeEditorWidthInPercent
112+ } )
113+ }
114+ }
115+
116+ handleMouseUp ( e ) {
117+ e . preventDefault ( )
118+ this . setState ( {
119+ isSliderFocused : false
120+ } )
121+ }
122+
123+ handleMouseDown ( e ) {
124+ e . preventDefault ( )
125+ this . setState ( {
126+ isSliderFocused : true
127+ } )
128+ }
129+
90130 render ( ) {
91131 const { config, value, storageKey, noteKey} = this . props
92132 const storage = findStorage ( storageKey )
@@ -95,12 +135,16 @@ class MarkdownSplitEditor extends React.Component {
95135 let editorIndentSize = parseInt ( config . editor . indentSize , 10 )
96136 if ( ! ( editorFontSize > 0 && editorFontSize < 132 ) ) editorIndentSize = 4
97137 const previewStyle = { }
98- if ( this . props . ignorePreviewPointerEvents ) previewStyle . pointerEvents = 'none'
138+ previewStyle . width = ( 100 - this . state . codeEditorWidthInPercent ) + '%'
139+ if ( this . props . ignorePreviewPointerEvents || this . state . isSliderFocused ) previewStyle . pointerEvents = 'none'
99140 return (
100- < div styleName = 'root' >
141+ < div styleName = 'root' ref = 'root'
142+ onMouseMove = { e => this . handleMouseMove ( e ) }
143+ onMouseUp = { e => this . handleMouseUp ( e ) } >
101144 < CodeEditor
102145 styleName = 'codeEditor'
103146 ref = 'code'
147+ width = { this . state . codeEditorWidthInPercent + '%' }
104148 mode = 'GitHub Flavored Markdown'
105149 value = { value }
106150 theme = { config . editor . theme }
@@ -119,6 +163,9 @@ class MarkdownSplitEditor extends React.Component {
119163 onChange = { this . handleOnChange . bind ( this ) }
120164 onScroll = { this . handleScroll . bind ( this ) }
121165 />
166+ < div styleName = 'slider' style = { { left : this . state . codeEditorWidthInPercent + '%' } } onMouseDown = { e => this . handleMouseDown ( e ) } >
167+ < div styleName = 'slider-hitbox' />
168+ </ div >
122169 < MarkdownPreview
123170 style = { previewStyle }
124171 styleName = 'preview'
0 commit comments