1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-23 22:51:42 +00:00

fixes #2903 - Rearrange layout of columns

This commit is contained in:
Callum booth
2019-03-19 20:39:34 +00:00
parent 78c00b1722
commit 93f0d3c1cf
10 changed files with 234 additions and 32 deletions

View File

@@ -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={

View File

@@ -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') {

View File

@@ -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 (
<div styleName='root' ref='root'
onMouseMove={e => this.handleMouseMove(e)}
@@ -152,19 +196,20 @@ class MarkdownSplitEditor extends React.Component {
<CodeEditor
styleName='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}
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}
@@ -180,7 +225,7 @@ class MarkdownSplitEditor extends React.Component {
hotkey={config.hotkey}
switchPreview={config.editor.switchPreview}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName={isStacking ? 'slider-hoz' : 'slider'} style={{left: sliderStyle.left, top: sliderStyle.top}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName='slider-hitbox' />
</div>
<MarkdownPreview

View File

@@ -3,6 +3,7 @@
height 100%
font-size 30px
display flex
flex-wrap wrap
.slider
absolute top bottom
top -2px
@@ -14,3 +15,11 @@
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