1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Make rtl optional

This commit is contained in:
Junyoung Choi
2020-03-04 05:35:09 +09:00
parent a27ddd7490
commit 87a737babc
4 changed files with 49 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import React from 'react' import React from 'react'
import CSSModules from 'browser/lib/CSSModules' import CSSModules from 'browser/lib/CSSModules'
@@ -29,20 +30,23 @@ class MarkdownEditor extends React.Component {
isLocked: props.isLocked isLocked: props.isLocked
} }
this.lockEditorCode = () => this.handleLockEditor() this.lockEditorCode = this.handleLockEditor.bind(this)
this.focusEditor = this.focusEditor.bind(this)
this.previewRef = React.createRef()
} }
componentDidMount() { componentDidMount() {
this.value = this.refs.code.value this.value = this.refs.code.value
eventEmitter.on('editor:lock', this.lockEditorCode) eventEmitter.on('editor:lock', this.lockEditorCode)
eventEmitter.on('editor:focus', this.focusEditor.bind(this)) eventEmitter.on('editor:focus', this.focusEditor)
} }
componentDidUpdate() { componentDidUpdate() {
this.value = this.refs.code.value this.value = this.refs.code.value
} }
componentWillReceiveProps(props) { UNSAFE_componentWillReceiveProps(props) {
if (props.value !== this.props.value) { if (props.value !== this.props.value) {
this.queueRendering(props.value) this.queueRendering(props.value)
} }
@@ -51,7 +55,7 @@ class MarkdownEditor extends React.Component {
componentWillUnmount() { componentWillUnmount() {
this.cancelQueue() this.cancelQueue()
eventEmitter.off('editor:lock', this.lockEditorCode) eventEmitter.off('editor:lock', this.lockEditorCode)
eventEmitter.off('editor:focus', this.focusEditor.bind(this)) eventEmitter.off('editor:focus', this.focusEditor)
} }
focusEditor() { focusEditor() {
@@ -60,6 +64,9 @@ class MarkdownEditor extends React.Component {
status: 'CODE' status: 'CODE'
}, },
() => { () => {
if (this.refs.code == null) {
return
}
this.refs.code.focus() this.refs.code.focus()
} }
) )
@@ -104,7 +111,7 @@ class MarkdownEditor extends React.Component {
if (newStatus === 'CODE') { if (newStatus === 'CODE') {
this.refs.code.focus() this.refs.code.focus()
} else { } else {
this.refs.preview.focus() this.previewRef.current.focus()
} }
eventEmitter.emit('topbar:togglelockbutton', this.state.status) eventEmitter.emit('topbar:togglelockbutton', this.state.status)
@@ -131,8 +138,8 @@ class MarkdownEditor extends React.Component {
status: 'PREVIEW' status: 'PREVIEW'
}, },
() => { () => {
this.refs.preview.focus() this.previewRef.current.focus()
this.refs.preview.scrollToRow(cursorPosition.line) this.previewRef.current.scrollToRow(cursorPosition.line)
} }
) )
eventEmitter.emit('topbar:togglelockbutton', this.state.status) eventEmitter.emit('topbar:togglelockbutton', this.state.status)
@@ -379,6 +386,7 @@ class MarkdownEditor extends React.Component {
RTL={RTL} RTL={RTL}
/> />
<MarkdownPreview <MarkdownPreview
ref={this.previewRef}
styleName={ styleName={
this.state.status === 'PREVIEW' ? 'preview' : 'preview--hide' this.state.status === 'PREVIEW' ? 'preview' : 'preview--hide'
} }
@@ -397,7 +405,6 @@ class MarkdownEditor extends React.Component {
breaks={config.preview.breaks} breaks={config.preview.breaks}
sanitize={config.preview.sanitize} sanitize={config.preview.sanitize}
mermaidHTMLLabel={config.preview.mermaidHTMLLabel} mermaidHTMLLabel={config.preview.mermaidHTMLLabel}
ref='preview'
onContextMenu={e => this.handleContextMenu(e)} onContextMenu={e => this.handleContextMenu(e)}
onDoubleClick={e => this.handleDoubleClick(e)} onDoubleClick={e => this.handleDoubleClick(e)}
tabIndex='0' tabIndex='0'

View File

@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import React from 'react' import React from 'react'
import CSSModules from 'browser/lib/CSSModules' import CSSModules from 'browser/lib/CSSModules'
@@ -57,7 +58,8 @@ class MarkdownNoteDetail extends React.Component {
this.dispatchTimer = null this.dispatchTimer = null
this.toggleLockButton = this.handleToggleLockButton.bind(this) this.toggleLockButton = this.handleToggleLockButton.bind(this)
this.generateToc = () => this.handleGenerateToc() this.generateToc = this.handleGenerateToc.bind(this)
this.handleUpdateContent = this.handleUpdateContent.bind(this)
} }
focus() { focus() {
@@ -76,7 +78,7 @@ class MarkdownNoteDetail extends React.Component {
ee.on('code:generate-toc', this.generateToc) ee.on('code:generate-toc', this.generateToc)
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
const isNewNote = nextProps.note.key !== this.props.note.key const isNewNote = nextProps.note.key !== this.props.note.key
const hasDeletedTags = const hasDeletedTags =
nextProps.note.tags.length < this.props.note.tags.length nextProps.note.tags.length < this.props.note.tags.length
@@ -392,6 +394,9 @@ class MarkdownNoteDetail extends React.Component {
} }
handleSwitchDirection() { handleSwitchDirection() {
if (!this.props.config.editor.rtlEnabled) {
return
}
// If in split mode, hide the lock button // If in split mode, hide the lock button
const direction = this.state.RTL const direction = this.state.RTL
this.setState({ RTL: !direction }) this.setState({ RTL: !direction })
@@ -436,10 +441,10 @@ class MarkdownNoteDetail extends React.Component {
storageKey={note.storage} storageKey={note.storage}
noteKey={note.key} noteKey={note.key}
linesHighlighted={note.linesHighlighted} linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent.bind(this)} onChange={this.handleUpdateContent}
isLocked={this.state.isLocked} isLocked={this.state.isLocked}
ignorePreviewPointerEvents={ignorePreviewPointerEvents} ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL} RTL={config.editor.rtlEnabled && this.state.RTL}
/> />
) )
} else { } else {
@@ -451,9 +456,9 @@ class MarkdownNoteDetail extends React.Component {
storageKey={note.storage} storageKey={note.storage}
noteKey={note.key} noteKey={note.key}
linesHighlighted={note.linesHighlighted} linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent.bind(this)} onChange={this.handleUpdateContent}
ignorePreviewPointerEvents={ignorePreviewPointerEvents} ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL} RTL={config.editor.rtlEnabled && this.state.RTL}
/> />
) )
} }
@@ -536,10 +541,12 @@ class MarkdownNoteDetail extends React.Component {
onClick={e => this.handleSwitchMode(e)} onClick={e => this.handleSwitchMode(e)}
editorType={editorType} editorType={editorType}
/> />
<ToggleDirectionButton {this.props.config.editor.rtlEnabled && (
onClick={e => this.handleSwitchDirection(e)} <ToggleDirectionButton
isRTL={this.state.RTL} onClick={e => this.handleSwitchDirection(e)}
/> isRTL={this.state.RTL}
/>
)}
<StarButton <StarButton
onClick={e => this.handleStarButtonClick(e)} onClick={e => this.handleStarButtonClick(e)}
isActive={note.isStarred} isActive={note.isStarred}

View File

@@ -33,7 +33,7 @@ export const DEFAULT_CONFIG = {
hotkey: { hotkey: {
toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E', toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E',
toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M', toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M',
toggleDirection: OSX ? 'Command + Alt + Right' : 'Ctrl + Right', toggleDirection: OSX ? 'Command + Alt + Right' : 'Ctrl + Alt + Right',
deleteNote: OSX deleteNote: OSX
? 'Command + Shift + Backspace' ? 'Command + Shift + Backspace'
: 'Ctrl + Shift + Backspace', : 'Ctrl + Shift + Backspace',
@@ -85,7 +85,8 @@ export const DEFAULT_CONFIG = {
"semi": false, "semi": false,
"singleQuote": true "singleQuote": true
}`, }`,
deleteUnusedAttachments: true deleteUnusedAttachments: true,
rtlEnabled: false
}, },
preview: { preview: {
fontSize: '14', fontSize: '14',

View File

@@ -127,7 +127,8 @@ class UiTab extends React.Component {
.getCodeMirror() .getCodeMirror()
.getValue(), .getValue(),
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(), prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(),
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked,
rtlEnabled: this.refs.rtlEnabled.checked
}, },
preview: { preview: {
fontSize: this.refs.previewFontSize.value, fontSize: this.refs.previewFontSize.value,
@@ -742,6 +743,18 @@ class UiTab extends React.Component {
)} )}
</label> </label>
</div> </div>
<div styleName='group-checkBoxSection'>
<label>
<input
onChange={e => this.handleUIChange(e)}
checked={this.state.config.editor.rtlEnabled}
ref='rtlEnabled'
type='checkbox'
/>
&nbsp;
{i18n.__('Enable right to left direction(RTL)')}
</label>
</div>
<div styleName='group-section'> <div styleName='group-section'>
<div styleName='group-section-label'> <div styleName='group-section-label'>