mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +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() {
|
||||
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)}
|
||||
/>
|
||||
|
||||
@@ -16,7 +16,8 @@ class MarkdownSplitEditor extends React.Component {
|
||||
this.userScroll = true
|
||||
this.state = {
|
||||
isSliderFocused: false,
|
||||
codeEditorWidthInPercent: 50
|
||||
codeEditorWidthInPercent: 50,
|
||||
codeEditorHeightInPercent: 50
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 (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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +175,7 @@ class MarkdownSplitEditor extends React.Component {
|
||||
storageKey,
|
||||
noteKey,
|
||||
linesHighlighted,
|
||||
isStacking,
|
||||
RTL
|
||||
} = this.props
|
||||
let storage
|
||||
@@ -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'
|
||||
@@ -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}
|
||||
@@ -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' />
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
height 100%
|
||||
font-size 30px
|
||||
display flex
|
||||
flex-wrap wrap
|
||||
.slider
|
||||
absolute top bottom
|
||||
top -2px
|
||||
@@ -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}]
|
||||
|
||||
@@ -60,6 +60,7 @@ class MarkdownNoteDetail extends React.Component {
|
||||
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() {
|
||||
@@ -67,6 +68,7 @@ class MarkdownNoteDetail extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
ee.on('editor:orientation', this.handleSwitchStackDirection)
|
||||
ee.on('topbar:togglelockbutton', this.toggleLockButton)
|
||||
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
|
||||
ee.on('topbar:togglemodebutton', () => {
|
||||
@@ -383,7 +385,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)
|
||||
@@ -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() {
|
||||
if (!this.props.config.editor.rtlEnabled) {
|
||||
return
|
||||
@@ -429,7 +443,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 (
|
||||
@@ -455,6 +469,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}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -314,6 +314,12 @@ const view = {
|
||||
mainWindow.webContents.send('editor:fullscreen')
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Editor Orientation',
|
||||
click() {
|
||||
mainWindow.webContents.send('editor:orientation')
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user