@@ -93,73 +93,74 @@ func glfwMouseButtonCallback(window *glfw.Window, key glfw.MouseButton, action g
93
93
94
94
var state = textModel {}
95
95
96
- func glfwKeyCallback (w * glfw.Window , key glfw.Key , scancode int , action glfw.Action , mods glfw.ModifierKey ) {
96
+ func glfwKey ( keyboardLayout keyboardShortcuts ) func (w * glfw.Window , key glfw.Key , scancode int , action glfw.Action , mods glfw.ModifierKey ) {
97
97
98
- if key == glfw .KeyEscape && action == glfw .Press {
99
- w .SetShouldClose (true )
100
- }
98
+ return func (w * glfw.Window , key glfw.Key , scancode int , action glfw.Action , mods glfw.ModifierKey ) {
99
+ if key == glfw .KeyEscape && action == glfw .Press {
100
+ w .SetShouldClose (true )
101
+ }
101
102
102
- if action == glfw .Repeat || action == glfw .Press {
103
- if state .clientID != 0 {
103
+ if action == glfw .Repeat || action == glfw .Press {
104
+ if state .clientID != 0 {
104
105
105
- switch key {
106
- case glfw .KeyEnter :
107
- if mods == glfw .ModControl {
108
- performAction (w , "done" )
109
- } else {
110
- state .addChar ([]rune {'\n' })
111
- performAction (w , "newline" )
112
- }
106
+ switch key {
107
+ case glfw .KeyEnter :
108
+ if mods == glfw .ModControl {
109
+ performAction (w , "done" )
110
+ } else {
111
+ state .addChar ([]rune {'\n' })
112
+ performAction (w , "newline" )
113
+ }
113
114
114
- case glfw .KeyHome :
115
- state .MoveCursorHome (int (mods ))
115
+ case glfw .KeyHome :
116
+ state .MoveCursorHome (int (mods ))
116
117
117
- case glfw .KeyEnd :
118
- state .MoveCursorEnd (int (mods ))
118
+ case glfw .KeyEnd :
119
+ state .MoveCursorEnd (int (mods ))
119
120
120
- case glfw .KeyLeft :
121
- state .MoveCursorLeft (int (mods ))
121
+ case glfw .KeyLeft :
122
+ state .MoveCursorLeft (int (mods ))
122
123
123
- case glfw .KeyRight :
124
- state .MoveCursorRight (int (mods ))
124
+ case glfw .KeyRight :
125
+ state .MoveCursorRight (int (mods ))
125
126
126
- case glfw .KeyDelete :
127
- state .Delete (int (mods ))
127
+ case glfw .KeyDelete :
128
+ state .Delete (int (mods ))
128
129
129
- case glfw .KeyBackspace :
130
- state .Backspace (int (mods ))
130
+ case glfw .KeyBackspace :
131
+ state .Backspace (int (mods ))
131
132
132
- case glfw . KeyA :
133
- if mods == glfw .ModControl {
134
- state .SelectAll ()
135
- }
133
+ case keyboardLayout . selectAll :
134
+ if mods == glfw .ModControl {
135
+ state .SelectAll ()
136
+ }
136
137
137
- case glfw . KeyC :
138
- if mods == glfw .ModControl && state .isSelected () {
139
- _ , _ , selectedContent := state .GetSelectedText ()
140
- w .SetClipboardString (selectedContent )
141
- }
138
+ case keyboardLayout . copy :
139
+ if mods == glfw .ModControl && state .isSelected () {
140
+ _ , _ , selectedContent := state .GetSelectedText ()
141
+ w .SetClipboardString (selectedContent )
142
+ }
142
143
143
- case glfw . KeyX :
144
- if mods == glfw .ModControl && state .isSelected () {
145
- _ , _ , selectedContent := state .GetSelectedText ()
146
- w .SetClipboardString (selectedContent )
147
- state .RemoveSelectedText ()
148
- }
144
+ case keyboardLayout . cut :
145
+ if mods == glfw .ModControl && state .isSelected () {
146
+ _ , _ , selectedContent := state .GetSelectedText ()
147
+ w .SetClipboardString (selectedContent )
148
+ state .RemoveSelectedText ()
149
+ }
149
150
150
- case glfw .KeyV :
151
- if mods == glfw .ModControl {
152
- var clpString , err = w .GetClipboardString ()
153
- if err != nil {
154
- log .Printf ("unable to get the clipboard content: %v\n " , err )
155
- } else {
156
- state .addChar ([]rune (clpString ))
151
+ case keyboardLayout .paste :
152
+ if mods == glfw .ModControl {
153
+ var clpString , err = w .GetClipboardString ()
154
+ if err != nil {
155
+ log .Printf ("unable to get the clipboard content: %v\n " , err )
156
+ } else {
157
+ state .addChar ([]rune (clpString ))
158
+ }
157
159
}
158
160
}
159
161
}
160
162
}
161
163
}
162
-
163
164
}
164
165
165
166
func glfwWindowSizeCallback (window * glfw.Window , width int , height int ) {
@@ -243,6 +244,8 @@ func runFlutter(window *glfw.Window, c config) *flutter.EngineOpenGL {
243
244
width , height := window .GetFramebufferSize ()
244
245
glfwWindowSizeCallback (window , width , height )
245
246
247
+ glfwKeyCallback := glfwKey (c .KeyboardLayout )
248
+
246
249
window .SetKeyCallback (glfwKeyCallback )
247
250
window .SetFramebufferSizeCallback (glfwWindowSizeCallback )
248
251
window .SetMouseButtonCallback (glfwMouseButtonCallback )
@@ -286,11 +289,11 @@ func performAction(window *glfw.Window, action string) {
286
289
"TextInputAction." + action ,
287
290
})
288
291
message := flutter.Message {
289
- Args : actionArgs ,
290
- Method :"TextInputClient.performAction" ,
292
+ Args : actionArgs ,
293
+ Method : "TextInputClient.performAction" ,
291
294
}
292
295
var mess = & flutter.PlatformMessage {
293
- Channel :textInputChannel ,
296
+ Channel : textInputChannel ,
294
297
Message : message ,
295
298
}
296
299
flutterOGL := flutter .SelectEngine (0 )
0 commit comments