Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit ae0eeaf

Browse files
committed
fixed save shortcut on original layout
1 parent a7e97ed commit ae0eeaf

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

browser/render/components/tag-input/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ export default class TagInput extends React.Component {
165165
return this.state.tags
166166
}
167167

168+
hasFocus () {
169+
return this.refs.input === document.activeElement
170+
}
171+
168172
render () {
169173
const { maxHeight } = this.props
170174
return (

browser/render/layouts/original/snippet-item-multi-files/index.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,28 @@ export default class SnippetItemMultiFiles extends React.Component {
2828

2929
componentDidMount () {
3030
eventEmitter.on('snippets:saveAll', () => {
31-
if (this.state.isEditing && this.refs.editor.hasFocus()) {
31+
if (this.state.isEditing && this.hasFocus()) {
3232
this.handleSaveChangesClick()
3333
}
3434
})
3535
eventEmitter.on('snippets:unSave', () => {
36-
if (this.state.isEditing && this.refs.editor.hasFocus()) {
36+
if (this.state.isEditing && this.hasFocus()) {
3737
this.handleDiscardChangesClick()
3838
}
3939
})
4040
}
4141

42+
hasFocus () {
43+
const { editor, lang, name, tags, description } = this.refs
44+
return (
45+
editor.hasFocus() ||
46+
lang === document.activeElement ||
47+
name === document.activeElement ||
48+
tags.wrappedInstance.hasFocus() ||
49+
description === document.activeElement
50+
)
51+
}
52+
4253
renderHeader () {
4354
const { isEditing } = this.state
4455
const { snippet } = this.props

browser/render/layouts/original/snippet-item/index.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ export default class SnippetItem extends React.Component {
2626

2727
componentDidMount () {
2828
eventEmitter.on('snippets:saveAll', () => {
29-
if (this.state.isEditing && this.refs.editor.hasFocus()) {
29+
if (this.state.isEditing && this.hasFocus()) {
3030
this.handleSaveChangesClick()
3131
}
3232
})
3333
eventEmitter.on('snippets:unSave', () => {
34-
if (this.state.isEditing && this.refs.editor.hasFocus()) {
34+
if (this.state.isEditing && this.hasFocus()) {
3535
this.handleDiscardChangesClick()
3636
}
3737
})
3838
}
3939

40+
hasFocus () {
41+
const { editor, lang, name, tags, description } = this.refs
42+
return (
43+
editor.hasFocus() ||
44+
lang === document.activeElement ||
45+
name === document.activeElement ||
46+
tags.wrappedInstance.hasFocus() ||
47+
description === document.activeElement
48+
)
49+
}
50+
4051
handleSnippetLangChange () {
4152
const { editor } = this.refs
4253
const snippetMode = CodeMirror.findModeByName(this.refs.lang.value).mode

0 commit comments

Comments
 (0)