Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Using composition event to detect IME composition stage ends
Browse files Browse the repository at this point in the history
fix #9139

Auditors: @bsclifton, @bbondy

Test Plan:

1. Make sure you have IME which has composition state
(like Zhuyin in Chinese, some Japanese IME)
2. Enter the characters in the IME, make sure doing some
add/remove/select characters before ending composition state
(mostly pressing enter)
3. Autocomplete will show only after you complete the words/sentences
  • Loading branch information
darkdh committed Dec 4, 2017
1 parent d11c391 commit d102eed
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ class UrlBar extends React.Component {
super(props)
this.lastVal = ''
this.lastSuffix = ''
this.isOnComposition = false
this.onFocus = this.onFocus.bind(this)
this.onBlur = this.onBlur.bind(this)
this.onKeyDown = this.onKeyDown.bind(this)
this.onKeyUp = this.onKeyUp.bind(this)
this.onChange = this.onChange.bind(this)
this.onComposition = this.onComposition.bind(this)
this.onKeyPress = this.onKeyPress.bind(this)
this.onClick = this.onClick.bind(this)
this.onContextMenu = this.onContextMenu.bind(this)
Expand Down Expand Up @@ -262,12 +264,22 @@ class UrlBar extends React.Component {
}

onChange (e) {
if (e.target.value !== this.lastVal + this.lastSuffix) {
if (e.target.value !== this.lastVal + this.lastSuffix &&
!this.isOnComposition) {
e.preventDefault()
this.setValue(e.target.value)
}
}

onComposition (e) {
if (e.type === 'compositionend') {
this.isOnComposition = false
this.onChange(e)
} else {
this.isOnComposition = true
}
}

getValue () {
return this.lastVal + this.lastSuffix
}
Expand Down Expand Up @@ -511,6 +523,9 @@ class UrlBar extends React.Component {
onKeyUp={this.onKeyUp}
onChange={this.onChange}
onKeyPress={this.onKeyPress}
onCompositionStart={this.onComposition}
onCompositionUpdate={this.onComposition}
onCompositionEnd={this.onComposition}
onClick={this.onClick}
onContextMenu={this.onContextMenu}
data-l10n-id='urlbar'
Expand Down

0 comments on commit d102eed

Please sign in to comment.