Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new future resize editor & Preview Panes by dragging.(#1977) #2062

Merged
merged 5 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export default class CodeEditor extends React.Component {
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
? [fontFamily].concat(defaultEditorFontFamily)
: defaultEditorFontFamily
const width = this.props.width
return (
<div
className={className == null
Expand All @@ -509,7 +510,8 @@ export default class CodeEditor extends React.Component {
tabIndex='-1'
style={{
fontFamily: fontFamily.join(', '),
fontSize: fontSize
fontSize: fontSize,
width: width
}}
onDrop={(e) => this.handleDropImage(e)}
/>
Expand Down
51 changes: 49 additions & 2 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class MarkdownSplitEditor extends React.Component {
this.focus = () => this.refs.code.focus()
this.reload = () => this.refs.code.reload()
this.userScroll = true
this.state = {
isSliderFocused: false,
codeEditorWidthInPercent: 50
}
}

handleOnChange () {
Expand Down Expand Up @@ -87,6 +91,42 @@ class MarkdownSplitEditor extends React.Component {
}
}

handleMouseMove (e) {
if (this.state.isSliderFocused) {
const rootRect = this.refs.root.getBoundingClientRect()
const rootWidth = rootRect.width
const offset = rootRect.left
let newCodeEditorWidthInPercent = (e.pageX - offset) / rootWidth * 100

// limit minSize to 10%, maxSize to 90%
if (newCodeEditorWidthInPercent <= 10) {
newCodeEditorWidthInPercent = 10
}

if (newCodeEditorWidthInPercent >= 90) {
newCodeEditorWidthInPercent = 90
}

this.setState({
codeEditorWidthInPercent: newCodeEditorWidthInPercent
})
}
}

handleMouseUp (e) {
e.preventDefault()
this.setState({
isSliderFocused: false
})
}

handleMouseDown (e) {
e.preventDefault()
this.setState({
isSliderFocused: true
})
}

render () {
const {config, value, storageKey, noteKey} = this.props
const storage = findStorage(storageKey)
Expand All @@ -95,12 +135,16 @@ class MarkdownSplitEditor extends React.Component {
let editorIndentSize = parseInt(config.editor.indentSize, 10)
if (!(editorFontSize > 0 && editorFontSize < 132)) editorIndentSize = 4
const previewStyle = {}
if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none'
previewStyle.width = (100 - this.state.codeEditorWidthInPercent) + '%'
if (this.props.ignorePreviewPointerEvents || this.state.isSliderFocused) previewStyle.pointerEvents = 'none'
return (
<div styleName='root'>
<div styleName='root' ref='root'
onMouseMove={e => this.handleMouseMove(e)}
onMouseUp={e => this.handleMouseUp(e)}>
<CodeEditor
styleName='codeEditor'
ref='code'
width={this.state.codeEditorWidthInPercent + '%'}
mode='GitHub Flavored Markdown'
value={value}
theme={config.editor.theme}
Expand All @@ -119,6 +163,9 @@ class MarkdownSplitEditor extends React.Component {
onChange={this.handleOnChange.bind(this)}
onScroll={this.handleScroll.bind(this)}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName='slider-hitbox' />
</div>
<MarkdownPreview
style={previewStyle}
styleName='preview'
Expand Down
15 changes: 11 additions & 4 deletions browser/components/MarkdownSplitEditor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
height 100%
font-size 30px
display flex
.codeEditor
width 50%
.preview
width 50%
.slider
absolute top bottom
top -2px
width 0
z-index 0
.slider-hitbox
absolute top bottom left right
width 7px
left -3px
z-index 10
cursor col-resize
Empty file added browser/lib/markdown2.js
Empty file.