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

Added rtl toggle button #3282

Merged
merged 7 commits into from
Jan 29, 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
14 changes: 11 additions & 3 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default class CodeEditor extends React.Component {
}

componentDidMount () {
const { rulers, enableRulers, enableMarkdownLint } = this.props
const { rulers, enableRulers, enableMarkdownLint, RTL } = this.props
eventEmitter.on('line:jump', this.scrollToLineHandeler)

snippetManager.init()
Expand All @@ -294,6 +294,8 @@ export default class CodeEditor extends React.Component {
scrollPastEnd: this.props.scrollPastEnd,
inputStyle: 'textarea',
dragDrop: false,
direction: RTL ? 'rtl' : 'ltr',
rtlMoveVisually: RTL,
foldGutter: true,
lint: enableMarkdownLint ? this.getCodeEditorLintConfig() : false,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
Expand Down Expand Up @@ -555,6 +557,10 @@ export default class CodeEditor extends React.Component {
if (prevProps.keyMap !== this.props.keyMap) {
needRefresh = true
}
if (prevProps.RTL !== this.props.RTL) {
this.editor.setOption('direction', this.props.RTL ? 'rtl' : 'ltr')
this.editor.setOption('rtlMoveVisually', this.props.RTL)
}
if (prevProps.enableMarkdownLint !== enableMarkdownLint || prevProps.customMarkdownLintConfig !== customMarkdownLintConfig) {
if (!enableMarkdownLint) {
this.editor.setOption('lint', {default: false})
Expand Down Expand Up @@ -1219,7 +1225,8 @@ CodeEditor.propTypes = {
spellCheck: PropTypes.bool,
enableMarkdownLint: PropTypes.bool,
customMarkdownLintConfig: PropTypes.string,
deleteUnusedAttachments: PropTypes.bool
deleteUnusedAttachments: PropTypes.bool,
RTL: PropTypes.bool
}

CodeEditor.defaultProps = {
Expand All @@ -1235,5 +1242,6 @@ CodeEditor.defaultProps = {
enableMarkdownLint: DEFAULT_CONFIG.editor.enableMarkdownLint,
customMarkdownLintConfig: DEFAULT_CONFIG.editor.customMarkdownLintConfig,
prettierConfig: DEFAULT_CONFIG.editor.prettierConfig,
deleteUnusedAttachments: DEFAULT_CONFIG.editor.deleteUnusedAttachments
deleteUnusedAttachments: DEFAULT_CONFIG.editor.deleteUnusedAttachments,
RTL: false
}
4 changes: 3 additions & 1 deletion browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class MarkdownEditor extends React.Component {
}

render () {
const {className, value, config, storageKey, noteKey, linesHighlighted} = this.props
const {className, value, config, storageKey, noteKey, linesHighlighted, RTL} = this.props

let editorFontSize = parseInt(config.editor.fontSize, 10)
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
Expand Down Expand Up @@ -325,6 +325,7 @@ class MarkdownEditor extends React.Component {
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
prettierConfig={config.editor.prettierConfig}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
RTL={RTL}
/>
<MarkdownPreview styleName={this.state.status === 'PREVIEW'
? 'preview'
Expand Down Expand Up @@ -360,6 +361,7 @@ class MarkdownEditor extends React.Component {
allowCustomCSS={config.preview.allowCustomCSS}
lineThroughCheckbox={config.preview.lineThroughCheckbox}
onDrop={(e) => this.handleDropImage(e)}
RTL={RTL}
/>
</div>
)
Expand Down
29 changes: 21 additions & 8 deletions browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function buildStyle (opts) {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
} = opts
return `
@font-face {
Expand Down Expand Up @@ -101,11 +102,14 @@ ${markdownStyle}
body {
font-family: '${fontFamily.join("','")}';
font-size: ${fontSize}px;

${scrollPastEnd ? `
padding-bottom: 90vh;
box-sizing: border-box;
`
: ''}
${RTL ? 'direction: rtl;' : ''}
${RTL ? 'text-align: right;' : ''}
}
@media print {
body {
Expand All @@ -115,6 +119,8 @@ body {
code {
font-family: '${codeBlockFontFamily.join("','")}';
background-color: rgba(0,0,0,0.04);
text-align: left;
direction: ltr;
}
.lineNumber {
${lineNumber && 'display: block !important;'}
Expand Down Expand Up @@ -337,7 +343,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
} = this.getStyleParams()

const inlineStyles = buildStyle({
Expand All @@ -348,7 +355,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
})
let body = this.refs.root.contentWindow.document.body.innerHTML
body = attachmentManagement.fixLocalURLS(
Expand Down Expand Up @@ -619,7 +627,8 @@ export default class MarkdownPreview extends React.Component {
prevProps.theme !== this.props.theme ||
prevProps.scrollPastEnd !== this.props.scrollPastEnd ||
prevProps.allowCustomCSS !== this.props.allowCustomCSS ||
prevProps.customCSS !== this.props.customCSS
prevProps.customCSS !== this.props.customCSS ||
prevProps.RTL !== this.props.RTL
) {
this.applyStyle()
needsRewriteIframe = true
Expand All @@ -643,7 +652,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
} = this.props
let { fontFamily, codeBlockFontFamily } = this.props
fontFamily = _.isString(fontFamily) && fontFamily.trim().length > 0
Expand All @@ -669,7 +679,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
}
}

Expand All @@ -683,7 +694,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
} = this.getStyleParams()

this.getWindow().document.getElementById(
Expand All @@ -697,7 +709,8 @@ export default class MarkdownPreview extends React.Component {
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
customCSS,
RTL
})
}

Expand Down
4 changes: 3 additions & 1 deletion browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class MarkdownSplitEditor extends React.Component {
}

render () {
const {config, value, storageKey, noteKey, linesHighlighted} = this.props
const {config, value, storageKey, noteKey, linesHighlighted, RTL} = this.props
const storage = findStorage(storageKey)
let editorFontSize = parseInt(config.editor.fontSize, 10)
if (!(editorFontSize > 0 && editorFontSize < 101)) editorFontSize = 14
Expand Down Expand Up @@ -183,6 +183,7 @@ class MarkdownSplitEditor extends React.Component {
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
RTL={RTL}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName='slider-hitbox' />
Expand Down Expand Up @@ -213,6 +214,7 @@ class MarkdownSplitEditor extends React.Component {
customCSS={config.preview.customCSS}
allowCustomCSS={config.preview.allowCustomCSS}
lineThroughCheckbox={config.preview.lineThroughCheckbox}
RTL={RTL}
/>
</div>
)
Expand Down
17 changes: 15 additions & 2 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
import markdownToc from 'browser/lib/markdown-toc-generator'
import queryString from 'query-string'
import { replace } from 'connected-react-router'
import ToggleDirectionButton from 'browser/main/Detail/ToggleDirectionButton'

class MarkdownNoteDetail extends React.Component {
constructor (props) {
Expand All @@ -46,7 +47,8 @@ class MarkdownNoteDetail extends React.Component {
isLockButtonShown: props.config.editor.type !== 'SPLIT',
isLocked: false,
editorType: props.config.editor.type,
switchPreview: props.config.editor.switchPreview
switchPreview: props.config.editor.switchPreview,
RTL: false
}

this.dispatchTimer = null
Expand All @@ -61,6 +63,7 @@ class MarkdownNoteDetail extends React.Component {

componentDidMount () {
ee.on('topbar:togglelockbutton', this.toggleLockButton)
ee.on('topbar:toggledirectionbutton', () => this.handleSwitchDirection())
ee.on('topbar:togglemodebutton', () => {
const reversedType = this.state.editorType === 'SPLIT' ? 'EDITOR_PREVIEW' : 'SPLIT'
this.handleSwitchMode(reversedType)
Expand Down Expand Up @@ -99,6 +102,7 @@ class MarkdownNoteDetail extends React.Component {

componentWillUnmount () {
ee.off('topbar:togglelockbutton', this.toggleLockButton)
ee.on('topbar:toggledirectionbutton', this.handleSwitchDirection)
ee.off('code:generate-toc', this.generateToc)
if (this.saveQueue != null) this.saveNow()
}
Expand Down Expand Up @@ -354,6 +358,12 @@ class MarkdownNoteDetail extends React.Component {
})
}

handleSwitchDirection () {
// If in split mode, hide the lock button
const direction = this.state.RTL
this.setState({ RTL: !direction })
}

handleDeleteNote () {
this.handleTrashButtonClick()
}
Expand Down Expand Up @@ -393,6 +403,7 @@ class MarkdownNoteDetail extends React.Component {
onChange={this.handleUpdateContent.bind(this)}
isLocked={this.state.isLocked}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL}
/>
} else {
return <MarkdownSplitEditor
Expand All @@ -404,6 +415,7 @@ class MarkdownNoteDetail extends React.Component {
linesHighlighted={note.linesHighlighted}
onChange={this.handleUpdateContent.bind(this)}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
RTL={this.state.RTL}
/>
}
}
Expand Down Expand Up @@ -472,7 +484,7 @@ class MarkdownNoteDetail extends React.Component {
</div>
<div styleName='info-right'>
<ToggleModeButton onClick={(e) => this.handleSwitchMode(e)} editorType={editorType} />

<ToggleDirectionButton onClick={(e) => this.handleSwitchDirection(e)} isRTL={this.state.RTL} />
<StarButton
onClick={(e) => this.handleStarButtonClick(e)}
isActive={note.isStarred}
Expand Down Expand Up @@ -518,6 +530,7 @@ class MarkdownNoteDetail extends React.Component {
print={this.print}
/>
</div>

</div>

return (
Expand Down
2 changes: 1 addition & 1 deletion browser/main/Detail/MarkdownNoteDetail.styl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.control-lockButton
topBarButtonRight()
position absolute
right 225px
right 265px
&:hover .tooltip
opacity 1

Expand Down
26 changes: 26 additions & 0 deletions browser/main/Detail/ToggleDirectionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PropTypes from 'prop-types'
import React from 'react'
import CSSModules from 'browser/lib/CSSModules'
import styles from './ToggleDirectionButton.styl'
import i18n from 'browser/lib/i18n'

const ToggleDirectionButton = ({
onClick, isRTL
}) => (
<div styleName='control-toggleModeButton'>
<div styleName={isRTL ? 'active' : undefined} onClick={() => onClick()}>
<img src={!isRTL ? '../resources/icon/icon-left-to-right.svg' : ''} />
</div>
<div styleName={!isRTL ? 'active' : undefined} onClick={() => onClick()}>
<img src={!isRTL ? '' : '../resources/icon/icon-right-to-left.svg'} />
</div>
<span lang={i18n.locale} styleName='tooltip'>{i18n.__('Toggle Direction')}</span>
</div>
)

ToggleDirectionButton.propTypes = {
onClick: PropTypes.func.isRequired,
isRTL: PropTypes.string.isRequired
}

export default CSSModules(ToggleDirectionButton, styles)
Loading