Skip to content

Commit 96ab8ec

Browse files
authored
Merge pull request #2661 from miguelalexbt/bugfix-2121
Fixed lock button behavior and display
2 parents c0f68dc + 7f6d4ac commit 96ab8ec

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

browser/components/MarkdownEditor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class MarkdownEditor extends React.Component {
2020
this.supportMdSelectionBold = [16, 17, 186]
2121

2222
this.state = {
23-
status: props.config.editor.switchPreview === 'RIGHTCLICK' ? props.config.editor.delfaultStatus : 'PREVIEW',
23+
status: props.config.editor.switchPreview === 'RIGHTCLICK' ? props.config.editor.delfaultStatus : 'CODE',
2424
renderValue: props.value,
2525
keyPressed: new Set(),
26-
isLocked: false
26+
isLocked: props.isLocked
2727
}
2828

2929
this.lockEditorCode = () => this.handleLockEditor()
@@ -76,6 +76,7 @@ class MarkdownEditor extends React.Component {
7676
}
7777

7878
handleContextMenu (e) {
79+
if (this.state.isLocked) return
7980
const { config } = this.props
8081
if (config.editor.switchPreview === 'RIGHTCLICK') {
8182
const newStatus = this.state.status === 'PREVIEW' ? 'CODE' : 'PREVIEW'

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ class MarkdownNoteDetail extends React.Component {
4242
content: '',
4343
linesHighlighted: []
4444
}, props.note),
45-
isLockButtonShown: false,
45+
isLockButtonShown: props.config.editor.type !== 'SPLIT',
4646
isLocked: false,
47-
editorType: props.config.editor.type
47+
editorType: props.config.editor.type,
48+
switchPreview: props.config.editor.switchPreview
4849
}
4950

5051
this.dispatchTimer = null
@@ -65,6 +66,9 @@ class MarkdownNoteDetail extends React.Component {
6566
})
6667
ee.on('hotkey:deletenote', this.handleDeleteNote.bind(this))
6768
ee.on('code:generate-toc', this.generateToc)
69+
70+
// Focus content if using blur or double click
71+
if (this.state.switchPreview === 'BLUR' || this.state.switchPreview === 'DBL_CLICK') this.focus()
6872
}
6973

7074
componentWillReceiveProps (nextProps) {
@@ -294,7 +298,7 @@ class MarkdownNoteDetail extends React.Component {
294298

295299
handleToggleLockButton (event, noteStatus) {
296300
// first argument event is not used
297-
if (this.props.config.editor.switchPreview === 'BLUR' && noteStatus === 'CODE') {
301+
if (noteStatus === 'CODE') {
298302
this.setState({isLockButtonShown: true})
299303
} else {
300304
this.setState({isLockButtonShown: false})
@@ -320,7 +324,8 @@ class MarkdownNoteDetail extends React.Component {
320324
}
321325

322326
handleSwitchMode (type) {
323-
this.setState({ editorType: type }, () => {
327+
// If in split mode, hide the lock button
328+
this.setState({ editorType: type, isLockButtonShown: !(type === 'SPLIT') }, () => {
324329
this.focus()
325330
const newConfig = Object.assign({}, this.props.config)
326331
newConfig.editor.type = type
@@ -365,6 +370,7 @@ class MarkdownNoteDetail extends React.Component {
365370
noteKey={note.key}
366371
linesHighlighted={note.linesHighlighted}
367372
onChange={this.handleUpdateContent.bind(this)}
373+
isLocked={this.state.isLocked}
368374
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
369375
/>
370376
} else {

0 commit comments

Comments
 (0)