forked from joejulian/gio
app,io/router: expand IME snippets if a new range overlaps the old
Instead of cmpletely replacing the IME snippet for every update, expand the old range if there is overlap. This change avoids never-ending restarts of the IME on Android where snippets are expanded in two calls, one for expanding before the selection and one for exanding after the selection. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -108,6 +108,27 @@ func FuzzIME(f *testing.F) {
|
||||
newState := r.EditorState()
|
||||
// We don't track caret position.
|
||||
state.Selection.Caret = newState.Selection.Caret
|
||||
// Expanded snippets are ok.
|
||||
their, our := newState.Snippet, state.EditorState.Snippet
|
||||
beforeLen := 0
|
||||
for before := our.Start - their.Start; before > 0; before-- {
|
||||
_, n := utf8.DecodeRuneInString(their.Text[beforeLen:])
|
||||
beforeLen += n
|
||||
}
|
||||
afterLen := 0
|
||||
for after := their.End - our.End; after > 0; after-- {
|
||||
_, n := utf8.DecodeLastRuneInString(their.Text[:len(their.Text)-afterLen])
|
||||
afterLen += n
|
||||
}
|
||||
if beforeLen > 0 {
|
||||
our.Text = their.Text[:beforeLen] + our.Text
|
||||
our.Start = their.Start
|
||||
}
|
||||
if afterLen > 0 {
|
||||
our.Text = our.Text + their.Text[len(their.Text)-afterLen:]
|
||||
our.End = their.End
|
||||
}
|
||||
state.EditorState.Snippet = our
|
||||
if newState != state.EditorState {
|
||||
t.Errorf("IME state: %+v\neditor state: %+v", state.EditorState, newState)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user