Skip to content

Commit f2ece22

Browse files
[linux] Listen to Enter key events on text inputs
1 parent 4990b13 commit f2ece22

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

library/linux/src/internal/text_input_plugin.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ static constexpr char kHideMethod[] = "TextInput.hide";
2424

2525
static constexpr char kUpdateEditingStateMethod[] =
2626
"TextInputClient.updateEditingState";
27+
static constexpr char kPerformActionMethod[] = "TextInputClient.performAction";
28+
29+
static constexpr char kNewLineAction[] = "TextInputAction.newline";
2730

2831
static constexpr char kSelectionBaseKey[] = "selectionBase";
2932
static constexpr char kSelectionExtentKey[] = "selectionExtent";
@@ -85,6 +88,8 @@ void TextInputPlugin::KeyboardHook(GLFWwindow *window, int key, int scancode,
8588
SendStateUpdate(*active_model_);
8689
}
8790
break;
91+
case GLFW_KEY_ENTER:
92+
EnterPressed(*active_model_);
8893
default:
8994
break;
9095
}
@@ -170,4 +175,12 @@ void TextInputPlugin::SendStateUpdate(const TextInputModel &model) {
170175
InvokeMethod(kUpdateEditingStateMethod, model.GetState());
171176
}
172177

178+
void TextInputPlugin::EnterPressed(const TextInputModel &model) {
179+
Json::Value args = Json::arrayValue;
180+
args.append(model.client_id());
181+
args.append(kNewLineAction);
182+
183+
InvokeMethod(kPerformActionMethod, args);
184+
}
185+
173186
} // namespace flutter_desktop_embedding

library/linux/src/internal/text_input_plugin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class TextInputPlugin : public KeyboardHookHandler, public JsonPlugin {
4646
// Sends the current state of the given model to the Flutter engine.
4747
void SendStateUpdate(const TextInputModel &model);
4848

49+
// Sends a "newline" action to the Flutter engine.
50+
void EnterPressed(const TextInputModel &model);
51+
4952
// Mapping of client IDs to text input models.
5053
std::map<int, std::unique_ptr<TextInputModel>> input_models_;
5154

0 commit comments

Comments
 (0)