mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
Merge pull request #2936 from callumbooth/fix-2903
fixes #2903 - Rearrange layout of columns
This commit is contained in:
@@ -1240,18 +1240,19 @@ export default class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, fontSize } = this.props
|
const { className, fontSize, fontFamily, width, height } = this.props
|
||||||
const fontFamily = normalizeEditorFontFamily(this.props.fontFamily)
|
const normalisedFontFamily = normalizeEditorFontFamily(fontFamily)
|
||||||
const width = this.props.width
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={className == null ? 'CodeEditor' : `CodeEditor ${className}`}
|
className={className == null ? 'CodeEditor' : `CodeEditor ${className}`}
|
||||||
ref='root'
|
ref='root'
|
||||||
tabIndex='-1'
|
tabIndex='-1'
|
||||||
style={{
|
style={{
|
||||||
fontFamily,
|
fontFamily: normalisedFontFamily,
|
||||||
fontSize: fontSize,
|
fontSize,
|
||||||
width: width
|
width,
|
||||||
|
height
|
||||||
}}
|
}}
|
||||||
onDrop={e => this.handleDropImage(e)}
|
onDrop={e => this.handleDropImage(e)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
this.userScroll = true
|
this.userScroll = true
|
||||||
this.state = {
|
this.state = {
|
||||||
isSliderFocused: false,
|
isSliderFocused: false,
|
||||||
codeEditorWidthInPercent: 50
|
codeEditorWidthInPercent: 50,
|
||||||
|
codeEditorHeightInPercent: 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +115,25 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
handleMouseMove(e) {
|
handleMouseMove(e) {
|
||||||
if (this.state.isSliderFocused) {
|
if (this.state.isSliderFocused) {
|
||||||
const rootRect = this.refs.root.getBoundingClientRect()
|
const rootRect = this.refs.root.getBoundingClientRect()
|
||||||
|
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 (newCodeEditorHeightInPercent <= 10) {
|
||||||
|
newCodeEditorHeightInPercent = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newCodeEditorHeightInPercent >= 90) {
|
||||||
|
newCodeEditorHeightInPercent = 90
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
codeEditorHeightInPercent: newCodeEditorHeightInPercent
|
||||||
|
})
|
||||||
|
} else {
|
||||||
const rootWidth = rootRect.width
|
const rootWidth = rootRect.width
|
||||||
const offset = rootRect.left
|
const offset = rootRect.left
|
||||||
let newCodeEditorWidthInPercent = ((e.pageX - offset) / rootWidth) * 100
|
let newCodeEditorWidthInPercent = ((e.pageX - offset) / rootWidth) * 100
|
||||||
@@ -132,6 +152,7 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleMouseUp(e) {
|
handleMouseUp(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -154,6 +175,7 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
storageKey,
|
storageKey,
|
||||||
noteKey,
|
noteKey,
|
||||||
linesHighlighted,
|
linesHighlighted,
|
||||||
|
isStacking,
|
||||||
RTL
|
RTL
|
||||||
} = this.props
|
} = this.props
|
||||||
let storage
|
let storage
|
||||||
@@ -162,14 +184,62 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return <div />
|
return <div />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let editorStyle = {}
|
||||||
|
let previewStyle = {}
|
||||||
|
let sliderStyle = {}
|
||||||
|
|
||||||
let editorFontSize = parseInt(config.editor.fontSize, 10)
|
let editorFontSize = parseInt(config.editor.fontSize, 10)
|
||||||
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
|
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
|
||||||
|
editorStyle.fontSize = editorFontSize
|
||||||
|
|
||||||
let editorIndentSize = parseInt(config.editor.indentSize, 10)
|
let editorIndentSize = parseInt(config.editor.indentSize, 10)
|
||||||
if (!(editorFontSize > 0 && editorFontSize < 132)) editorIndentSize = 4
|
if (!(editorStyle.fontSize > 0 && editorStyle.fontSize < 132))
|
||||||
const previewStyle = {}
|
editorIndentSize = 4
|
||||||
previewStyle.width = 100 - this.state.codeEditorWidthInPercent + '%'
|
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)
|
if (this.props.ignorePreviewPointerEvents || this.state.isSliderFocused)
|
||||||
previewStyle.pointerEvents = 'none'
|
previewStyle.pointerEvents = 'none'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
styleName='root'
|
styleName='root'
|
||||||
@@ -179,20 +249,21 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
>
|
>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
ref='code'
|
ref='code'
|
||||||
width={this.state.codeEditorWidthInPercent + '%'}
|
width={editorStyle.width}
|
||||||
|
height={editorStyle.height}
|
||||||
mode='Boost Flavored Markdown'
|
mode='Boost Flavored Markdown'
|
||||||
value={value}
|
value={value}
|
||||||
theme={config.editor.theme}
|
theme={config.editor.theme}
|
||||||
keyMap={config.editor.keyMap}
|
keyMap={config.editor.keyMap}
|
||||||
fontFamily={config.editor.fontFamily}
|
fontFamily={config.editor.fontFamily}
|
||||||
fontSize={editorFontSize}
|
fontSize={editorStyle.fontSize}
|
||||||
displayLineNumbers={config.editor.displayLineNumbers}
|
displayLineNumbers={config.editor.displayLineNumbers}
|
||||||
lineWrapping
|
lineWrapping
|
||||||
matchingPairs={config.editor.matchingPairs}
|
matchingPairs={config.editor.matchingPairs}
|
||||||
matchingTriples={config.editor.matchingTriples}
|
matchingTriples={config.editor.matchingTriples}
|
||||||
explodingPairs={config.editor.explodingPairs}
|
explodingPairs={config.editor.explodingPairs}
|
||||||
indentType={config.editor.indentType}
|
indentType={config.editor.indentType}
|
||||||
indentSize={editorIndentSize}
|
indentSize={editorStyle.indentSize}
|
||||||
enableRulers={config.editor.enableRulers}
|
enableRulers={config.editor.enableRulers}
|
||||||
rulers={config.editor.rulers}
|
rulers={config.editor.rulers}
|
||||||
scrollPastEnd={config.editor.scrollPastEnd}
|
scrollPastEnd={config.editor.scrollPastEnd}
|
||||||
@@ -213,8 +284,8 @@ class MarkdownSplitEditor extends React.Component {
|
|||||||
RTL={RTL}
|
RTL={RTL}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
styleName='slider'
|
styleName={isStacking ? 'slider-hoz' : 'slider'}
|
||||||
style={{ left: this.state.codeEditorWidthInPercent + '%' }}
|
style={{ left: sliderStyle.left, top: sliderStyle.top }}
|
||||||
onMouseDown={e => this.handleMouseDown(e)}
|
onMouseDown={e => this.handleMouseDown(e)}
|
||||||
>
|
>
|
||||||
<div styleName='slider-hitbox' />
|
<div styleName='slider-hitbox' />
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
height 100%
|
height 100%
|
||||||
font-size 30px
|
font-size 30px
|
||||||
display flex
|
display flex
|
||||||
|
flex-wrap wrap
|
||||||
.slider
|
.slider
|
||||||
absolute top bottom
|
absolute top bottom
|
||||||
top -2px
|
top -2px
|
||||||
@@ -15,6 +16,14 @@
|
|||||||
left -3px
|
left -3px
|
||||||
z-index 10
|
z-index 10
|
||||||
cursor col-resize
|
cursor col-resize
|
||||||
|
.slider-hoz
|
||||||
|
absolute left right
|
||||||
|
.slider-hitbox
|
||||||
|
absolute left right
|
||||||
|
width: 100%
|
||||||
|
height 7px
|
||||||
|
cursor row-resize
|
||||||
|
|
||||||
|
|
||||||
apply-theme(theme)
|
apply-theme(theme)
|
||||||
body[data-theme={theme}]
|
body[data-theme={theme}]
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
this.toggleLockButton = this.handleToggleLockButton.bind(this)
|
this.toggleLockButton = this.handleToggleLockButton.bind(this)
|
||||||
this.generateToc = this.handleGenerateToc.bind(this)
|
this.generateToc = this.handleGenerateToc.bind(this)
|
||||||
this.handleUpdateContent = this.handleUpdateContent.bind(this)
|
this.handleUpdateContent = this.handleUpdateContent.bind(this)
|
||||||
|
this.handleSwitchStackDirection = this.handleSwitchStackDirection.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
@@ -67,6 +68,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
ee.on('editor:orientation', this.handleSwitchStackDirection)
|
||||||
ee.on('topbar:togglelockbutton', this.toggleLockButton)
|
ee.on('topbar:togglelockbutton', this.toggleLockButton)
|
||||||
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
|
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
|
||||||
ee.on('topbar:togglemodebutton', () => {
|
ee.on('topbar:togglemodebutton', () => {
|
||||||
@@ -383,7 +385,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
handleSwitchMode(type) {
|
handleSwitchMode(type) {
|
||||||
// If in split mode, hide the lock button
|
// If in split mode, hide the lock button
|
||||||
this.setState(
|
this.setState(
|
||||||
{ editorType: type, isLockButtonShown: !(type === 'SPLIT') },
|
{ editorType: type, isLockButtonShown: type !== 'SPLIT' },
|
||||||
() => {
|
() => {
|
||||||
this.focus()
|
this.focus()
|
||||||
const newConfig = Object.assign({}, this.props.config)
|
const newConfig = Object.assign({}, this.props.config)
|
||||||
@@ -393,6 +395,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() {
|
handleSwitchDirection() {
|
||||||
if (!this.props.config.editor.rtlEnabled) {
|
if (!this.props.config.editor.rtlEnabled) {
|
||||||
return
|
return
|
||||||
@@ -429,7 +443,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
|
|
||||||
renderEditor() {
|
renderEditor() {
|
||||||
const { config, ignorePreviewPointerEvents } = this.props
|
const { config, ignorePreviewPointerEvents } = this.props
|
||||||
const { note } = this.state
|
const { note, isStacking } = this.state
|
||||||
|
|
||||||
if (this.state.editorType === 'EDITOR_PREVIEW') {
|
if (this.state.editorType === 'EDITOR_PREVIEW') {
|
||||||
return (
|
return (
|
||||||
@@ -455,6 +469,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
value={note.content}
|
value={note.content}
|
||||||
storageKey={note.storage}
|
storageKey={note.storage}
|
||||||
noteKey={note.key}
|
noteKey={note.key}
|
||||||
|
isStacking={isStacking}
|
||||||
linesHighlighted={note.linesHighlighted}
|
linesHighlighted={note.linesHighlighted}
|
||||||
onChange={this.handleUpdateContent}
|
onChange={this.handleUpdateContent}
|
||||||
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ export const DEFAULT_CONFIG = {
|
|||||||
disableDirectWrite: false,
|
disableDirectWrite: false,
|
||||||
showScrollBar: true,
|
showScrollBar: true,
|
||||||
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
|
defaultNote: 'ALWAYS_ASK', // 'ALWAYS_ASK', 'SNIPPET_NOTE', 'MARKDOWN_NOTE'
|
||||||
showMenuBar: false
|
showMenuBar: false,
|
||||||
|
isStacking: false
|
||||||
},
|
},
|
||||||
editor: {
|
editor: {
|
||||||
theme: 'base16-light',
|
theme: 'base16-light',
|
||||||
|
|||||||
@@ -314,6 +314,12 @@ const view = {
|
|||||||
mainWindow.webContents.send('editor:fullscreen')
|
mainWindow.webContents.send('editor:fullscreen')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Toggle Editor Orientation',
|
||||||
|
click() {
|
||||||
|
mainWindow.webContents.send('editor:orientation')
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user