Skip to content

Commit 7669b26

Browse files
committed
don't send key event when the textinput has client
A little work-around. Waiting for #314 to have a real answer. For now, I am a bit sceptical on how the keyboard text selection/keyboard pasting will be handled in the flutter side. I'm afraid it might not be suited to our need. We are sending GLFW(linux) related event to the framework. But the framework only has one handler, linux. This means, sending keyevent on darwin will not support the correct keyboard layout (Ctrl -> Meta). As those different keyboard layout are already supported in go-flutter, this work-around ensure that we keep control of the textinput when needed.
1 parent c4c03d1 commit 7669b26

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

application.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,12 @@ func (a *Application) Run() error {
308308
a.window.SetKeyCallback(
309309
func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
310310
defaultTextinputPlugin.glfwKeyCallback(window, key, scancode, action, mods)
311-
defaultKeyeventsPlugin.sendKeyEvent(window, key, scancode, action, mods)
311+
if !defaultTextinputPlugin.hasClient() {
312+
// don't send keyevent if the user is editing text in a TextField.
313+
// let go-flutter handle keyboard text selection/keyboard paste
314+
// https://github.com/go-flutter-desktop/go-flutter/issues/314
315+
defaultKeyeventsPlugin.sendKeyEvent(window, key, scancode, action, mods)
316+
}
312317
})
313318
a.window.SetCharCallback(defaultTextinputPlugin.glfwCharCallback)
314319

textinput.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ func (p *textinputPlugin) handleClearClient(arguments interface{}) (reply interf
9494
return nil, nil
9595
}
9696

97+
func (p *textinputPlugin) hasClient() bool {
98+
return p.clientID != 0
99+
}
100+
97101
func (p *textinputPlugin) handleSetEditingState(arguments interface{}) (reply interface{}, err error) {
98-
if p.clientID == 0 {
102+
if !p.hasClient() {
99103
return nil, errors.New("cannot set editing state when no client is selected")
100104
}
101105

@@ -124,7 +128,7 @@ func (p *textinputPlugin) handleSetEditingState(arguments interface{}) (reply in
124128
}
125129

126130
func (p *textinputPlugin) glfwCharCallback(w *glfw.Window, char rune) {
127-
if p.clientID == 0 {
131+
if !p.hasClient() {
128132
return
129133
}
130134
// Opinionated: If a flutter dev uses TextCapitalization.characters
@@ -149,7 +153,7 @@ func (p *textinputPlugin) glfwKeyCallback(window *glfw.Window, key glfw.Key, sca
149153
}
150154

151155
if action == glfw.Repeat || action == glfw.Press {
152-
if p.clientID == 0 {
156+
if !p.hasClient() {
153157
return
154158
}
155159

0 commit comments

Comments
 (0)