Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RTL optional #3510

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import PropTypes from 'prop-types'
import React from 'react'
import CSSModules from 'browser/lib/CSSModules'
Expand Down Expand Up @@ -29,20 +30,23 @@ class MarkdownEditor extends React.Component {
isLocked: props.isLocked
}

this.lockEditorCode = () => this.handleLockEditor()
this.lockEditorCode = this.handleLockEditor.bind(this)
this.focusEditor = this.focusEditor.bind(this)

this.previewRef = React.createRef()
}

componentDidMount() {
this.value = this.refs.code.value
eventEmitter.on('editor:lock', this.lockEditorCode)
eventEmitter.on('editor:focus', this.focusEditor.bind(this))
eventEmitter.on('editor:focus', this.focusEditor)
}

componentDidUpdate() {
this.value = this.refs.code.value
}

componentWillReceiveProps(props) {
UNSAFE_componentWillReceiveProps(props) {
if (props.value !== this.props.value) {
this.queueRendering(props.value)
}
Expand All @@ -51,7 +55,7 @@ class MarkdownEditor extends React.Component {
componentWillUnmount() {
this.cancelQueue()
eventEmitter.off('editor:lock', this.lockEditorCode)
eventEmitter.off('editor:focus', this.focusEditor.bind(this))
eventEmitter.off('editor:focus', this.focusEditor)
}

focusEditor() {
Expand All @@ -60,6 +64,9 @@ class MarkdownEditor extends React.Component {
status: 'CODE'
},
() => {
if (this.refs.code == null) {
return
}
this.refs.code.focus()
}
)
Expand Down Expand Up @@ -104,7 +111,7 @@ class MarkdownEditor extends React.Component {
if (newStatus === 'CODE') {
this.refs.code.focus()
} else {
this.refs.preview.focus()
this.previewRef.current.focus()
}
eventEmitter.emit('topbar:togglelockbutton', this.state.status)

Expand All @@ -131,8 +138,8 @@ class MarkdownEditor extends React.Component {
status: 'PREVIEW'
},
() => {
this.refs.preview.focus()
this.refs.preview.scrollToRow(cursorPosition.line)
this.previewRef.current.focus()
this.previewRef.current.scrollToRow(cursorPosition.line)
}
)
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
Expand Down Expand Up @@ -379,6 +386,7 @@ class MarkdownEditor extends React.Component {
RTL={RTL}
/>
<MarkdownPreview
ref={this.previewRef}
styleName={
this.state.status === 'PREVIEW' ? 'preview' : 'preview--hide'
}
Expand All @@ -397,7 +405,6 @@ class MarkdownEditor extends React.Component {
breaks={config.preview.breaks}
sanitize={config.preview.sanitize}
mermaidHTMLLabel={config.preview.mermaidHTMLLabel}
ref='preview'
onContextMenu={e => this.handleContextMenu(e)}
onDoubleClick={e => this.handleDoubleClick(e)}
tabIndex='0'
Expand Down
7 changes: 6 additions & 1 deletion browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,4 +1226,9 @@ MarkdownPreview.propTypes = {
breaks: PropTypes.bool
}

export default connect()(MarkdownPreview)
export default connect(
null,
null,
null,
{ forwardRef: true }
)(MarkdownPreview)
27 changes: 17 additions & 10 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import PropTypes from 'prop-types'
import React from 'react'
import CSSModules from 'browser/lib/CSSModules'
Expand Down Expand Up @@ -57,7 +58,8 @@ class MarkdownNoteDetail extends React.Component {
this.dispatchTimer = null

this.toggleLockButton = this.handleToggleLockButton.bind(this)
this.generateToc = () => this.handleGenerateToc()
this.generateToc = this.handleGenerateToc.bind(this)
this.handleUpdateContent = this.handleUpdateContent.bind(this)
}

focus() {
Expand All @@ -76,7 +78,7 @@ class MarkdownNoteDetail extends React.Component {
ee.on('code:generate-toc', this.generateToc)
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
const isNewNote = nextProps.note.key !== this.props.note.key
const hasDeletedTags =
nextProps.note.tags.length < this.props.note.tags.length
Expand Down Expand Up @@ -392,6 +394,9 @@ class MarkdownNoteDetail extends React.Component {
}

handleSwitchDirection() {
if (!this.props.config.editor.rtlEnabled) {
return
}
// If in split mode, hide the lock button
const direction = this.state.RTL
this.setState({ RTL: !direction })
Expand Down Expand Up @@ -436,10 +441,10 @@ class MarkdownNoteDetail extends React.Component {
storageKey={note.storage}
noteKey={note.key}
linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent.bind(this)}
onChange={this.handleUpdateContent}
isLocked={this.state.isLocked}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL}
RTL={config.editor.rtlEnabled && this.state.RTL}
/>
)
} else {
Expand All @@ -451,9 +456,9 @@ class MarkdownNoteDetail extends React.Component {
storageKey={note.storage}
noteKey={note.key}
linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent.bind(this)}
onChange={this.handleUpdateContent}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL}
RTL={config.editor.rtlEnabled && this.state.RTL}
/>
)
}
Expand Down Expand Up @@ -536,10 +541,12 @@ class MarkdownNoteDetail extends React.Component {
onClick={e => this.handleSwitchMode(e)}
editorType={editorType}
/>
<ToggleDirectionButton
onClick={e => this.handleSwitchDirection(e)}
isRTL={this.state.RTL}
/>
{this.props.config.editor.rtlEnabled && (
<ToggleDirectionButton
onClick={e => this.handleSwitchDirection(e)}
isRTL={this.state.RTL}
/>
)}
<StarButton
onClick={e => this.handleStarButtonClick(e)}
isActive={note.isStarred}
Expand Down
5 changes: 3 additions & 2 deletions browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DEFAULT_CONFIG = {
hotkey: {
toggleMain: OSX ? 'Command + Alt + L' : 'Super + Alt + E',
toggleMode: OSX ? 'Command + Alt + M' : 'Ctrl + M',
toggleDirection: OSX ? 'Command + Alt + Right' : 'Ctrl + Right',
toggleDirection: OSX ? 'Command + Alt + Right' : 'Ctrl + Alt + Right',
deleteNote: OSX
? 'Command + Shift + Backspace'
: 'Ctrl + Shift + Backspace',
Expand Down Expand Up @@ -85,7 +85,8 @@ export const DEFAULT_CONFIG = {
"semi": false,
"singleQuote": true
}`,
deleteUnusedAttachments: true
deleteUnusedAttachments: true,
rtlEnabled: false
},
preview: {
fontSize: '14',
Expand Down
15 changes: 14 additions & 1 deletion browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class UiTab extends React.Component {
.getCodeMirror()
.getValue(),
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(),
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked,
rtlEnabled: this.refs.rtlEnabled.checked
},
preview: {
fontSize: this.refs.previewFontSize.value,
Expand Down Expand Up @@ -742,6 +743,18 @@ class UiTab extends React.Component {
)}
</label>
</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-label'>
Expand Down