diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 6ad294ed..556e2f7b 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -747,14 +747,14 @@ export default class CodeEditor extends React.Component { } incrementLines (start, linesAdded, linesRemoved, editor) { - let highlightedLines = editor.options.linesHighlighted + const highlightedLines = editor.options.linesHighlighted const totalHighlightedLines = highlightedLines.length - let offset = linesAdded - linesRemoved + const offset = linesAdded - linesRemoved // Store new items to be added as we're changing the lines - let newLines = [] + const newLines = [] let i = totalHighlightedLines @@ -1128,10 +1128,12 @@ export default class CodeEditor extends React.Component { render () { const { className, - fontSize + fontSize, + width, + height } = this.props const fontFamily = normalizeEditorFontFamily(this.props.fontFamily) - const width = this.props.width + return (< div className={ className == null ? 'CodeEditor' : `CodeEditor ${className}` @@ -1142,7 +1144,8 @@ export default class CodeEditor extends React.Component { { fontFamily, fontSize: fontSize, - width: width + width: width, + height: height } } onDrop={ diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index a6819ce9..b3ece56a 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -321,7 +321,7 @@ export default class MarkdownPreview extends React.Component { allowCustomCSS, customCSS ) - let body = this.markdown.render(noteContent) + const body = this.markdown.render(noteContent) const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES] files.forEach(file => { if (global.process.platform === 'win32') { diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index 4477288a..0d71ab93 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -16,7 +16,8 @@ class MarkdownSplitEditor extends React.Component { this.userScroll = true this.state = { isSliderFocused: false, - codeEditorWidthInPercent: 50 + codeEditorWidthInPercent: 50, + codeEditorHeightInPercent: 50 } } @@ -102,22 +103,41 @@ 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 + if (this.props.isStacking) { + const rootHeight = rootRect.height + const offset = rootRect.top + let newCodeEditorHeightInPercent = (e.pageY - offset) / rootHeight * 100 - // limit minSize to 10%, maxSize to 90% - if (newCodeEditorWidthInPercent <= 10) { - newCodeEditorWidthInPercent = 10 + // limit minSize to 10%, maxSize to 90% + if (newCodeEditorHeightInPercent <= 10) { + newCodeEditorHeightInPercent = 10 + } + + if (newCodeEditorHeightInPercent >= 90) { + newCodeEditorHeightInPercent = 90 + } + + this.setState({ + codeEditorHeightInPercent: newCodeEditorHeightInPercent + }) + } else { + 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 + }) } - - if (newCodeEditorWidthInPercent >= 90) { - newCodeEditorWidthInPercent = 90 - } - - this.setState({ - codeEditorWidthInPercent: newCodeEditorWidthInPercent - }) } } @@ -136,15 +156,39 @@ class MarkdownSplitEditor extends React.Component { } render () { - const {config, value, storageKey, noteKey, linesHighlighted} = this.props + const {config, value, storageKey, noteKey, linesHighlighted, isStacking} = this.props const storage = findStorage(storageKey) + + const editorStyle = {} + const previewStyle = {} + const sliderStyle = {} + let editorFontSize = parseInt(config.editor.fontSize, 10) if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14 + editorStyle.fontSize = editorFontSize + let editorIndentSize = parseInt(config.editor.indentSize, 10) - if (!(editorFontSize > 0 && editorFontSize < 132)) editorIndentSize = 4 - const previewStyle = {} - previewStyle.width = (100 - this.state.codeEditorWidthInPercent) + '%' + if (!(editorStyle.fontSize > 0 && editorStyle.fontSize < 132)) editorIndentSize = 4 + editorStyle.indentSize = editorIndentSize + + if (isStacking) { + editorStyle.width = 100 + '%' + editorStyle.height = this.state.codeEditorHeightInPercent + '%' + previewStyle.width = 100 + '%' + previewStyle.height = (100 - this.state.codeEditorHeightInPercent) + '%' + sliderStyle.left = 0 + sliderStyle.top = this.state.codeEditorHeightInPercent + '%' + } else { + editorStyle.width = this.state.codeEditorWidthInPercent + '%' + editorStyle.height = 100 + '%' + previewStyle.width = (100 - this.state.codeEditorWidthInPercent) + '%' + previewStyle.height = 100 + '%' + sliderStyle.left = this.state.codeEditorWidthInPercent + '%' + sliderStyle.top = 0 + } + if (this.props.ignorePreviewPointerEvents || this.state.isSliderFocused) previewStyle.pointerEvents = 'none' + return (