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

Commit

Permalink
Merge pull request #12172 from brave/issue-9139
Browse files Browse the repository at this point in the history
Using composition event to detect IME composition stage ends
  • Loading branch information
bsclifton committed Feb 9, 2018
1 parent a220321 commit 6302637
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 @@ -51,11 +51,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 @@ -263,12 +265,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 @@ -521,6 +533,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 6302637

Please sign in to comment.