Skip to content

Commit eefecde

Browse files
authored
Merge pull request #2062 from zhouxiaoxiaoxujian/bug-1977
Add new future resize editor & Preview Panes by dragging.(#1977)
2 parents 002dc9b + 84e670e commit eefecde

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

browser/components/CodeEditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export default class CodeEditor extends React.Component {
499499
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
500500
? [fontFamily].concat(defaultEditorFontFamily)
501501
: defaultEditorFontFamily
502+
const width = this.props.width
502503
return (
503504
<div
504505
className={className == null
@@ -509,7 +510,8 @@ export default class CodeEditor extends React.Component {
509510
tabIndex='-1'
510511
style={{
511512
fontFamily: fontFamily.join(', '),
512-
fontSize: fontSize
513+
fontSize: fontSize,
514+
width: width
513515
}}
514516
onDrop={(e) => this.handleDropImage(e)}
515517
/>

browser/components/MarkdownSplitEditor.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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'

browser/components/MarkdownSplitEditor.styl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
height 100%
44
font-size 30px
55
display flex
6-
.codeEditor
7-
width 50%
8-
.preview
9-
width 50%
6+
.slider
7+
absolute top bottom
8+
top -2px
9+
width 0
10+
z-index 0
11+
.slider-hitbox
12+
absolute top bottom left right
13+
width 7px
14+
left -3px
15+
z-index 10
16+
cursor col-resize

browser/lib/markdown2.js

Whitespace-only changes.

0 commit comments

Comments
 (0)