Skip to content

Commit 2e8cd5d

Browse files
author
Pierre Champion
authored
Merge pull request #8 from james-lawrence/textModel/properly-set-initial-position
fixes crash when editing input fields Former-commit-id: b6345d2
2 parents f0c8d2a + f20978d commit 2e8cd5d

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

flutter/message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const (
1515
TextUpdateStateMethod = "TextInputClient.updateEditingState"
1616

1717
// text
18-
SetClientMethod = "TextInput.setClient"
19-
ClearClientMethod = "TextInput.clearClient"
20-
SetEditingStateMethod = "TextInput.setEditingState"
18+
TextInputClientSet = "TextInput.setClient"
19+
TextInputClientClear = "TextInput.clearClient"
20+
TextInputSetEditState = "TextInput.setEditingState"
2121
)
2222

2323
// Message is the json content of a PlatformMessage

gutter.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,24 @@ func onPlatformMessage(platMessage flutter.PlatformMessage, window unsafe.Pointe
271271
}
272272

273273
if platMessage.Channel == flutter.TextInputChannel {
274-
275-
if message.Method == flutter.ClearClientMethod {
274+
switch message.Method {
275+
case flutter.TextInputClientClear:
276276
state.clientID = 0
277-
}
278-
279-
if message.Method == flutter.SetClientMethod {
277+
case flutter.TextInputClientSet:
280278
var body []interface{}
281279
json.Unmarshal(message.Args, &body)
282280
state.clientID = body[0].(float64)
283-
}
284-
285-
if message.Method == flutter.SetEditingStateMethod {
281+
case flutter.TextInputSetEditState:
286282
if state.clientID != 0 {
287283
editingState := flutter.ArgsEditingState{}
288284
json.Unmarshal(message.Args, &editingState)
289285
state.word = editingState.Text
286+
state.selectionBase = editingState.SelectionBase
287+
state.selectionExtent = editingState.SelectionExtent
290288
}
291-
289+
default:
290+
// log.Printf("unhandled text input method: %#v\n", platMessage.Message)
292291
}
293-
294292
}
295293

296294
return true

0 commit comments

Comments
 (0)