@@ -24,6 +24,8 @@ static constexpr char kUpdateEditingStateMethod[] =
24
24
static constexpr char kPerformActionMethod [] = " TextInputClient.performAction" ;
25
25
26
26
static constexpr char kInputActionKey [] = " inputAction" ;
27
+ static constexpr char kTextInputTypeKey [] = " inputType" ;
28
+ static constexpr char kTextInputTypeNameKey [] = " name" ;
27
29
static constexpr char kTextKey [] = " text" ;
28
30
static constexpr char kSelectionBaseKey [] = " selectionBase" ;
29
31
static constexpr char kSelectionExtentKey [] = " selectionExtent" ;
@@ -33,6 +35,7 @@ static constexpr char kComposingBaseKey[] = "composingBase";
33
35
static constexpr char kComposingExtentKey [] = " composingExtent" ;
34
36
35
37
static constexpr char kTextAffinityDownstream [] = " TextAffinity.downstream" ;
38
+ static constexpr char kMultilineInputType [] = " TextInputType.multiline" ;
36
39
37
40
static constexpr int64_t kClientIdUnset = -1 ;
38
41
@@ -47,6 +50,9 @@ struct _FlTextInputPlugin {
47
50
// Input action to perform when enter pressed.
48
51
gchar* input_action;
49
52
53
+ // Send newline when multi-line and enter is pressed.
54
+ gboolean input_multiline;
55
+
50
56
// Input method.
51
57
GtkIMContext* im_context;
52
58
@@ -175,6 +181,19 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
175
181
self->input_action = g_strdup (fl_value_get_string (input_action_value));
176
182
}
177
183
184
+ // Clear the multiline flag, then set it only if the field is multiline.
185
+ self->input_multiline = FALSE ;
186
+ FlValue* input_type_value =
187
+ fl_value_lookup (config_value, fl_value_new_string (kTextInputTypeKey ));
188
+ if (fl_value_get_type (input_type_value) == FL_VALUE_TYPE_MAP) {
189
+ FlValue* input_type_name = fl_value_lookup (
190
+ input_type_value, fl_value_new_string (kTextInputTypeNameKey ));
191
+ if (fl_value_equal (input_type_name,
192
+ fl_value_new_string (kMultilineInputType ))) {
193
+ self->input_multiline = TRUE ;
194
+ }
195
+ }
196
+
178
197
return FL_METHOD_RESPONSE (fl_method_success_response_new (nullptr ));
179
198
}
180
199
@@ -269,6 +288,7 @@ static void fl_text_input_plugin_class_init(FlTextInputPluginClass* klass) {
269
288
static void fl_text_input_plugin_init (FlTextInputPlugin* self) {
270
289
self->client_id = kClientIdUnset ;
271
290
self->im_context = gtk_im_multicontext_new ();
291
+ self->input_multiline = FALSE ;
272
292
g_signal_connect_object (self->im_context , " commit" , G_CALLBACK (im_commit_cb),
273
293
self, G_CONNECT_SWAPPED);
274
294
g_signal_connect_object (self->im_context , " retrieve-surrounding" ,
@@ -307,6 +327,8 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
307
327
return TRUE ;
308
328
}
309
329
330
+ // Handle the enter/return key.
331
+ gboolean do_action = FALSE ;
310
332
// Handle navigation keys.
311
333
gboolean changed = FALSE ;
312
334
if (event->type == GDK_KEY_PRESS) {
@@ -325,7 +347,11 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
325
347
case GDK_KEY_Return:
326
348
case GDK_KEY_KP_Enter:
327
349
case GDK_KEY_ISO_Enter:
328
- perform_action (self);
350
+ if (self->input_multiline == TRUE ) {
351
+ self->text_model ->AddCodePoint (' \n ' );
352
+ changed = TRUE ;
353
+ }
354
+ do_action = TRUE ;
329
355
break ;
330
356
case GDK_KEY_Home:
331
357
case GDK_KEY_KP_Home:
@@ -345,6 +371,9 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
345
371
if (changed) {
346
372
update_editing_state (self);
347
373
}
374
+ if (do_action) {
375
+ perform_action (self);
376
+ }
348
377
349
378
return FALSE ;
350
379
}
0 commit comments