Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 57fdf0a

Browse files
authored
send newline char when input type is multiline (#20660)
1 parent 4de62c7 commit 57fdf0a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

shell/platform/linux/fl_text_input_plugin.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ static constexpr char kUpdateEditingStateMethod[] =
2424
static constexpr char kPerformActionMethod[] = "TextInputClient.performAction";
2525

2626
static constexpr char kInputActionKey[] = "inputAction";
27+
static constexpr char kTextInputTypeKey[] = "inputType";
28+
static constexpr char kTextInputTypeNameKey[] = "name";
2729
static constexpr char kTextKey[] = "text";
2830
static constexpr char kSelectionBaseKey[] = "selectionBase";
2931
static constexpr char kSelectionExtentKey[] = "selectionExtent";
@@ -33,6 +35,7 @@ static constexpr char kComposingBaseKey[] = "composingBase";
3335
static constexpr char kComposingExtentKey[] = "composingExtent";
3436

3537
static constexpr char kTextAffinityDownstream[] = "TextAffinity.downstream";
38+
static constexpr char kMultilineInputType[] = "TextInputType.multiline";
3639

3740
static constexpr int64_t kClientIdUnset = -1;
3841

@@ -47,6 +50,9 @@ struct _FlTextInputPlugin {
4750
// Input action to perform when enter pressed.
4851
gchar* input_action;
4952

53+
// Send newline when multi-line and enter is pressed.
54+
gboolean input_multiline;
55+
5056
// Input method.
5157
GtkIMContext* im_context;
5258

@@ -175,6 +181,19 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
175181
self->input_action = g_strdup(fl_value_get_string(input_action_value));
176182
}
177183

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+
178197
return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
179198
}
180199

@@ -269,6 +288,7 @@ static void fl_text_input_plugin_class_init(FlTextInputPluginClass* klass) {
269288
static void fl_text_input_plugin_init(FlTextInputPlugin* self) {
270289
self->client_id = kClientIdUnset;
271290
self->im_context = gtk_im_multicontext_new();
291+
self->input_multiline = FALSE;
272292
g_signal_connect_object(self->im_context, "commit", G_CALLBACK(im_commit_cb),
273293
self, G_CONNECT_SWAPPED);
274294
g_signal_connect_object(self->im_context, "retrieve-surrounding",
@@ -307,6 +327,8 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
307327
return TRUE;
308328
}
309329

330+
// Handle the enter/return key.
331+
gboolean do_action = FALSE;
310332
// Handle navigation keys.
311333
gboolean changed = FALSE;
312334
if (event->type == GDK_KEY_PRESS) {
@@ -325,7 +347,11 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
325347
case GDK_KEY_Return:
326348
case GDK_KEY_KP_Enter:
327349
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;
329355
break;
330356
case GDK_KEY_Home:
331357
case GDK_KEY_KP_Home:
@@ -345,6 +371,9 @@ gboolean fl_text_input_plugin_filter_keypress(FlTextInputPlugin* self,
345371
if (changed) {
346372
update_editing_state(self);
347373
}
374+
if (do_action) {
375+
perform_action(self);
376+
}
348377

349378
return FALSE;
350379
}

0 commit comments

Comments
 (0)