Skip to content

Commit 4b67026

Browse files
authored
Merge pull request #2936 from callumbooth/fix-2903
fixes #2903 - Rearrange layout of columns
2 parents 8b13ec4 + c355f81 commit 4b67026

File tree

6 files changed

+134
-31
lines changed

6 files changed

+134
-31
lines changed

browser/components/CodeEditor.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,18 +1240,19 @@ export default class CodeEditor extends React.Component {
12401240
}
12411241

12421242
render() {
1243-
const { className, fontSize } = this.props
1244-
const fontFamily = normalizeEditorFontFamily(this.props.fontFamily)
1245-
const width = this.props.width
1243+
const { className, fontSize, fontFamily, width, height } = this.props
1244+
const normalisedFontFamily = normalizeEditorFontFamily(fontFamily)
1245+
12461246
return (
12471247
<div
12481248
className={className == null ? 'CodeEditor' : `CodeEditor ${className}`}
12491249
ref='root'
12501250
tabIndex='-1'
12511251
style={{
1252-
fontFamily,
1253-
fontSize: fontSize,
1254-
width: width
1252+
fontFamily: normalisedFontFamily,
1253+
fontSize,
1254+
width,
1255+
height
12551256
}}
12561257
onDrop={e => this.handleDropImage(e)}
12571258
/>

browser/components/MarkdownSplitEditor.js

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class MarkdownSplitEditor extends React.Component {
1616
this.userScroll = true
1717
this.state = {
1818
isSliderFocused: false,
19-
codeEditorWidthInPercent: 50
19+
codeEditorWidthInPercent: 50,
20+
codeEditorHeightInPercent: 50
2021
}
2122
}
2223

@@ -114,22 +115,42 @@ class MarkdownSplitEditor extends React.Component {
114115
handleMouseMove(e) {
115116
if (this.state.isSliderFocused) {
116117
const rootRect = this.refs.root.getBoundingClientRect()
117-
const rootWidth = rootRect.width
118-
const offset = rootRect.left
119-
let newCodeEditorWidthInPercent = ((e.pageX - offset) / rootWidth) * 100
118+
if (this.props.isStacking) {
119+
const rootHeight = rootRect.height
120+
const offset = rootRect.top
121+
let newCodeEditorHeightInPercent =
122+
((e.pageY - offset) / rootHeight) * 100
120123

121-
// limit minSize to 10%, maxSize to 90%
122-
if (newCodeEditorWidthInPercent <= 10) {
123-
newCodeEditorWidthInPercent = 10
124-
}
124+
// limit minSize to 10%, maxSize to 90%
125+
if (newCodeEditorHeightInPercent <= 10) {
126+
newCodeEditorHeightInPercent = 10
127+
}
125128

126-
if (newCodeEditorWidthInPercent >= 90) {
127-
newCodeEditorWidthInPercent = 90
128-
}
129+
if (newCodeEditorHeightInPercent >= 90) {
130+
newCodeEditorHeightInPercent = 90
131+
}
132+
133+
this.setState({
134+
codeEditorHeightInPercent: newCodeEditorHeightInPercent
135+
})
136+
} else {
137+
const rootWidth = rootRect.width
138+
const offset = rootRect.left
139+
let newCodeEditorWidthInPercent = ((e.pageX - offset) / rootWidth) * 100
129140

130-
this.setState({
131-
codeEditorWidthInPercent: newCodeEditorWidthInPercent
132-
})
141+
// limit minSize to 10%, maxSize to 90%
142+
if (newCodeEditorWidthInPercent <= 10) {
143+
newCodeEditorWidthInPercent = 10
144+
}
145+
146+
if (newCodeEditorWidthInPercent >= 90) {
147+
newCodeEditorWidthInPercent = 90
148+
}
149+
150+
this.setState({
151+
codeEditorWidthInPercent: newCodeEditorWidthInPercent
152+
})
153+
}
133154
}
134155
}
135156

@@ -154,6 +175,7 @@ class MarkdownSplitEditor extends React.Component {
154175
storageKey,
155176
noteKey,
156177
linesHighlighted,
178+
isStacking,
157179
RTL
158180
} = this.props
159181
let storage
@@ -162,14 +184,62 @@ class MarkdownSplitEditor extends React.Component {
162184
} catch (e) {
163185
return <div />
164186
}
187+
188+
let editorStyle = {}
189+
let previewStyle = {}
190+
let sliderStyle = {}
191+
165192
let editorFontSize = parseInt(config.editor.fontSize, 10)
166193
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
194+
editorStyle.fontSize = editorFontSize
195+
167196
let editorIndentSize = parseInt(config.editor.indentSize, 10)
168-
if (!(editorFontSize > 0 && editorFontSize < 132)) editorIndentSize = 4
169-
const previewStyle = {}
170-
previewStyle.width = 100 - this.state.codeEditorWidthInPercent + '%'
197+
if (!(editorStyle.fontSize > 0 && editorStyle.fontSize < 132))
198+
editorIndentSize = 4
199+
editorStyle.indentSize = editorIndentSize
200+
201+
editorStyle = Object.assign(
202+
editorStyle,
203+
isStacking
204+
? {
205+
width: '100%',
206+
height: `${this.state.codeEditorHeightInPercent}%`
207+
}
208+
: {
209+
width: `${this.state.codeEditorWidthInPercent}%`,
210+
height: '100%'
211+
}
212+
)
213+
214+
previewStyle = Object.assign(
215+
previewStyle,
216+
isStacking
217+
? {
218+
width: '100%',
219+
height: `${100 - this.state.codeEditorHeightInPercent}%`
220+
}
221+
: {
222+
width: `${100 - this.state.codeEditorWidthInPercent}%`,
223+
height: '100%'
224+
}
225+
)
226+
227+
sliderStyle = Object.assign(
228+
sliderStyle,
229+
isStacking
230+
? {
231+
left: 0,
232+
top: `${this.state.codeEditorHeightInPercent}%`
233+
}
234+
: {
235+
left: `${this.state.codeEditorWidthInPercent}%`,
236+
top: 0
237+
}
238+
)
239+
171240
if (this.props.ignorePreviewPointerEvents || this.state.isSliderFocused)
172241
previewStyle.pointerEvents = 'none'
242+
173243
return (
174244
<div
175245
styleName='root'
@@ -179,20 +249,21 @@ class MarkdownSplitEditor extends React.Component {
179249
>
180250
<CodeEditor
181251
ref='code'
182-
width={this.state.codeEditorWidthInPercent + '%'}
252+
width={editorStyle.width}
253+
height={editorStyle.height}
183254
mode='Boost Flavored Markdown'
184255
value={value}
185256
theme={config.editor.theme}
186257
keyMap={config.editor.keyMap}
187258
fontFamily={config.editor.fontFamily}
188-
fontSize={editorFontSize}
259+
fontSize={editorStyle.fontSize}
189260
displayLineNumbers={config.editor.displayLineNumbers}
190261
lineWrapping
191262
matchingPairs={config.editor.matchingPairs}
192263
matchingTriples={config.editor.matchingTriples}
193264
explodingPairs={config.editor.explodingPairs}
194265
indentType={config.editor.indentType}
195-
indentSize={editorIndentSize}
266+
indentSize={editorStyle.indentSize}
196267
enableRulers={config.editor.enableRulers}
197268
rulers={config.editor.rulers}
198269
scrollPastEnd={config.editor.scrollPastEnd}
@@ -213,8 +284,8 @@ class MarkdownSplitEditor extends React.Component {
213284
RTL={RTL}
214285
/>
215286
<div
216-
styleName='slider'
217-
style={{ left: this.state.codeEditorWidthInPercent + '%' }}
287+
styleName={isStacking ? 'slider-hoz' : 'slider'}
288+
style={{ left: sliderStyle.left, top: sliderStyle.top }}
218289
onMouseDown={e => this.handleMouseDown(e)}
219290
>
220291
<div styleName='slider-hitbox' />

browser/components/MarkdownSplitEditor.styl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
height 100%
44
font-size 30px
55
display flex
6+
flex-wrap wrap
67
.slider
78
absolute top bottom
89
top -2px
@@ -15,6 +16,14 @@
1516
left -3px
1617
z-index 10
1718
cursor col-resize
19+
.slider-hoz
20+
absolute left right
21+
.slider-hitbox
22+
absolute left right
23+
width: 100%
24+
height 7px
25+
cursor row-resize
26+
1827

1928
apply-theme(theme)
2029
body[data-theme={theme}]

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ class MarkdownNoteDetail extends React.Component {
6060
this.toggleLockButton = this.handleToggleLockButton.bind(this)
6161
this.generateToc = this.handleGenerateToc.bind(this)
6262
this.handleUpdateContent = this.handleUpdateContent.bind(this)
63+
this.handleSwitchStackDirection = this.handleSwitchStackDirection.bind(this)
6364
}
6465

6566
focus() {
6667
this.refs.content.focus()
6768
}
6869

6970
componentDidMount() {
71+
ee.on('editor:orientation', this.handleSwitchStackDirection)
7072
ee.on('topbar:togglelockbutton', this.toggleLockButton)
7173
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
7274
ee.on('topbar:togglemodebutton', () => {
@@ -383,7 +385,7 @@ class MarkdownNoteDetail extends React.Component {
383385
handleSwitchMode(type) {
384386
// If in split mode, hide the lock button
385387
this.setState(
386-
{ editorType: type, isLockButtonShown: !(type === 'SPLIT') },
388+
{ editorType: type, isLockButtonShown: type !== 'SPLIT' },
387389
() => {
388390
this.focus()
389391
const newConfig = Object.assign({}, this.props.config)
@@ -393,6 +395,18 @@ class MarkdownNoteDetail extends React.Component {
393395
)
394396
}
395397

398+
handleSwitchStackDirection() {
399+
this.setState(
400+
prevState => ({ isStacking: !prevState.isStacking }),
401+
() => {
402+
this.focus()
403+
const newConfig = Object.assign({}, this.props.config)
404+
newConfig.ui.isStacking = this.state.isStacking
405+
ConfigManager.set(newConfig)
406+
}
407+
)
408+
}
409+
396410
handleSwitchDirection() {
397411
if (!this.props.config.editor.rtlEnabled) {
398412
return
@@ -429,7 +443,7 @@ class MarkdownNoteDetail extends React.Component {
429443

430444
renderEditor() {
431445
const { config, ignorePreviewPointerEvents } = this.props
432-
const { note } = this.state
446+
const { note, isStacking } = this.state
433447

434448
if (this.state.editorType === 'EDITOR_PREVIEW') {
435449
return (
@@ -455,6 +469,7 @@ class MarkdownNoteDetail extends React.Component {
455469
value={note.content}
456470
storageKey={note.storage}
457471
noteKey={note.key}
472+
isStacking={isStacking}
458473
linesHighlighted={note.linesHighlighted}
459474
onChange={this.handleUpdateContent}
460475
ignorePreviewPointerEvents={ignorePreviewPointerEvents}

browser/main/lib/ConfigManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export const DEFAULT_CONFIG = {
7171
disableDirectWrite: false,
7272
showScrollBar: true,
7373
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
74-
showMenuBar: false
74+
showMenuBar: false,
75+
isStacking: false
7576
},
7677
editor: {
7778
theme: 'base16-light',

lib/main-menu.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ const view = {
314314
mainWindow.webContents.send('editor:fullscreen')
315315
}
316316
},
317+
{
318+
label: 'Toggle Editor Orientation',
319+
click() {
320+
mainWindow.webContents.send('editor:orientation')
321+
}
322+
},
317323
{
318324
type: 'separator'
319325
},

0 commit comments

Comments
 (0)