Skip to content
Closed
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
21 changes: 12 additions & 9 deletions browser/main/TopBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ class TopBar extends React.Component {
searchOptions: [],
isSearching: false,
isAlphabet: false,
isIME: false,
isIMEDone: false,
isConfirmTranslation: false
}

this.focusSearchHandler = () => {
this.handleOnSearchFocus()
}

this.handleIMEDone = () => {
this.setState({
isIMEDone: true
})
}

this.codeInitHandler = this.handleCodeInit.bind(this)
}

Expand All @@ -36,11 +42,13 @@ class TopBar extends React.Component {
isSearching: true
})
}
document.addEventListener('compositionend', this.handleIMEDone)
ee.on('top:focus-search', this.focusSearchHandler)
ee.on('code:init', this.codeInitHandler)
}

componentWillUnmount () {
document.removeEventListener('compositionend', this.handleIMEDone)
ee.off('top:focus-search', this.focusSearchHandler)
ee.off('code:init', this.codeInitHandler)
}
Expand All @@ -60,7 +68,7 @@ class TopBar extends React.Component {
// reset states
this.setState({
isAlphabet: false,
isIME: false
isIMEDone: false
})

// Clear search on ESC
Expand All @@ -85,11 +93,6 @@ class TopBar extends React.Component {
this.setState({
isAlphabet: true
})
// When the key is an IME input (Japanese, Chinese)
} else if (e.keyCode === 229) {
this.setState({
isIME: true
})
}
}

Expand All @@ -100,8 +103,8 @@ class TopBar extends React.Component {
isConfirmTranslation: false
})

// When the key is translation confirmation (Enter, Space)
if (this.state.isIME && (e.keyCode === 32 || e.keyCode === 13)) {
// When IME composition (Chinese, Japanese, Korean) is finished
if (this.state.isIMEDone) {
this.setState({
isConfirmTranslation: true
})
Expand Down