Skip to content
13 changes: 7 additions & 6 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,18 +1240,19 @@ export default class CodeEditor extends React.Component {
}

render() {
const { className, fontSize } = this.props
const fontFamily = normalizeEditorFontFamily(this.props.fontFamily)
const width = this.props.width
const { className, fontSize, fontFamily, width, height } = this.props
const normalisedFontFamily = normalizeEditorFontFamily(fontFamily)

return (
<div
className={className == null ? 'CodeEditor' : `CodeEditor ${className}`}
ref='root'
tabIndex='-1'
style={{
fontFamily,
fontSize: fontSize,
width: width
fontFamily: normalisedFontFamily,
fontSize,
width,
height
}}
onDrop={e => this.handleDropImage(e)}
/>
Expand Down
115 changes: 93 additions & 22 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class MarkdownSplitEditor extends React.Component {
this.userScroll = true
this.state = {
isSliderFocused: false,
codeEditorWidthInPercent: 50
codeEditorWidthInPercent: 50,
codeEditorHeightInPercent: 50
}
}

Expand Down Expand Up @@ -114,22 +115,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
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 (newCodeEditorWidthInPercent >= 90) {
newCodeEditorWidthInPercent = 90
}
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

this.setState({
codeEditorWidthInPercent: newCodeEditorWidthInPercent
})
// limit minSize to 10%, maxSize to 90%
if (newCodeEditorWidthInPercent <= 10) {
newCodeEditorWidthInPercent = 10
}

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

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

Expand All @@ -154,6 +175,7 @@ class MarkdownSplitEditor extends React.Component {
storageKey,
noteKey,
linesHighlighted,
isStacking,
RTL
} = this.props
let storage
Expand All @@ -162,14 +184,62 @@ class MarkdownSplitEditor extends React.Component {
} catch (e) {
return <div />
}

let editorStyle = {}
let previewStyle = {}
let 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

editorStyle = Object.assign(
editorStyle,
isStacking
? {
width: '100%',
height: `${this.state.codeEditorHeightInPercent}%`
}
: {
width: `${this.state.codeEditorWidthInPercent}%`,
height: '100%'
}
)

previewStyle = Object.assign(
previewStyle,
isStacking
? {
width: '100%',
height: `${100 - this.state.codeEditorHeightInPercent}%`
}
: {
width: `${100 - this.state.codeEditorWidthInPercent}%`,
height: '100%'
}
)

sliderStyle = Object.assign(
sliderStyle,
isStacking
? {
left: 0,
top: `${this.state.codeEditorHeightInPercent}%`
}
: {
left: `${this.state.codeEditorWidthInPercent}%`,
top: 0
}
)

if (this.props.ignorePreviewPointerEvents || this.state.isSliderFocused)
previewStyle.pointerEvents = 'none'

return (
<div
styleName='root'
Expand All @@ -179,20 +249,21 @@ class MarkdownSplitEditor extends React.Component {
>
<CodeEditor
ref='code'
width={this.state.codeEditorWidthInPercent + '%'}
width={editorStyle.width}
height={editorStyle.height}
mode='Boost Flavored Markdown'
value={value}
theme={config.editor.theme}
keyMap={config.editor.keyMap}
fontFamily={config.editor.fontFamily}
fontSize={editorFontSize}
fontSize={editorStyle.fontSize}
displayLineNumbers={config.editor.displayLineNumbers}
lineWrapping
matchingPairs={config.editor.matchingPairs}
matchingTriples={config.editor.matchingTriples}
explodingPairs={config.editor.explodingPairs}
indentType={config.editor.indentType}
indentSize={editorIndentSize}
indentSize={editorStyle.indentSize}
enableRulers={config.editor.enableRulers}
rulers={config.editor.rulers}
scrollPastEnd={config.editor.scrollPastEnd}
Expand All @@ -213,8 +284,8 @@ class MarkdownSplitEditor extends React.Component {
RTL={RTL}
/>
<div
styleName='slider'
style={{ left: this.state.codeEditorWidthInPercent + '%' }}
styleName={isStacking ? 'slider-hoz' : 'slider'}
style={{ left: sliderStyle.left, top: sliderStyle.top }}
onMouseDown={e => this.handleMouseDown(e)}
>
<div styleName='slider-hitbox' />
Expand Down
9 changes: 9 additions & 0 deletions browser/components/MarkdownSplitEditor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
height 100%
font-size 30px
display flex
flex-wrap wrap
.slider
absolute top bottom
top -2px
Expand All @@ -15,6 +16,14 @@
left -3px
z-index 10
cursor col-resize
.slider-hoz
absolute left right
.slider-hitbox
absolute left right
width: 100%
height 7px
cursor row-resize


apply-theme(theme)
body[data-theme={theme}]
Expand Down
22 changes: 18 additions & 4 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@ class MarkdownNoteDetail extends React.Component {
isLockButtonShown: props.config.editor.type !== 'SPLIT',
isLocked: false,
editorType: props.config.editor.type,
switchPreview: props.config.editor.switchPreview,
RTL: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove this RTL key, this is for Right To Left feature, people who use this feature will be very angry 😄

switchPreview: props.config.editor.switchPreview
}

this.dispatchTimer = null

this.toggleLockButton = this.handleToggleLockButton.bind(this)
this.generateToc = this.handleGenerateToc.bind(this)
this.handleUpdateContent = this.handleUpdateContent.bind(this)
this.handleSwitchStackDirection = this.handleSwitchStackDirection.bind(this)
}

focus() {
this.refs.content.focus()
}

componentDidMount() {
ee.on('editor:orientation', this.handleSwitchStackDirection)
ee.on('topbar:togglelockbutton', this.toggleLockButton)
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
ee.on('topbar:togglemodebutton', () => {
Expand Down Expand Up @@ -383,7 +384,7 @@ class MarkdownNoteDetail extends React.Component {
handleSwitchMode(type) {
// If in split mode, hide the lock button
this.setState(
{ editorType: type, isLockButtonShown: !(type === 'SPLIT') },
{ editorType: type, isLockButtonShown: type !== 'SPLIT' },
() => {
this.focus()
const newConfig = Object.assign({}, this.props.config)
Expand All @@ -393,6 +394,18 @@ class MarkdownNoteDetail extends React.Component {
)
}

handleSwitchStackDirection() {
this.setState(
prevState => ({ isStacking: !prevState.isStacking }),
() => {
this.focus()
const newConfig = Object.assign({}, this.props.config)
newConfig.ui.isStacking = this.state.isStacking
ConfigManager.set(newConfig)
}
)
}

handleSwitchDirection() {
if (!this.props.config.editor.rtlEnabled) {
return
Expand Down Expand Up @@ -429,7 +442,7 @@ class MarkdownNoteDetail extends React.Component {

renderEditor() {
const { config, ignorePreviewPointerEvents } = this.props
const { note } = this.state
const { note, isStacking } = this.state

if (this.state.editorType === 'EDITOR_PREVIEW') {
return (
Expand All @@ -455,6 +468,7 @@ class MarkdownNoteDetail extends React.Component {
value={note.content}
storageKey={note.storage}
noteKey={note.key}
isStacking={isStacking}
linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
Expand Down
3 changes: 2 additions & 1 deletion browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const DEFAULT_CONFIG = {
disableDirectWrite: false,
showScrollBar: true,
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
showMenuBar: false
showMenuBar: false,
isStacking: false
},
editor: {
theme: 'base16-light',
Expand Down
6 changes: 6 additions & 0 deletions lib/main-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ const view = {
mainWindow.webContents.send('editor:fullscreen')
}
},
{
label: 'Toggle Editor Orientation',
click() {
mainWindow.webContents.send('editor:orientation')
}
},
{
type: 'separator'
},
Expand Down
36 changes: 36 additions & 0 deletions resources/icon/icon-panel-split-horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions resources/icon/icon-panel-split-vertical.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.