Skip to content

Commit 28d7b4a

Browse files
franciscojma86stuartmorgan
authored andcommitted
[linux] Listen to Enter key events on text inputs (#138)
Invokes TextInputAction.done on the platform channel when Enter is pressed.
1 parent 4990b13 commit 28d7b4a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

library/linux/src/internal/text_input_plugin.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ 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";
30+
static constexpr char kDoneAction[] = "TextInputAction.done";
2731

2832
static constexpr char kSelectionBaseKey[] = "selectionBase";
2933
static constexpr char kSelectionExtentKey[] = "selectionExtent";
@@ -85,6 +89,8 @@ void TextInputPlugin::KeyboardHook(GLFWwindow *window, int key, int scancode,
8589
SendStateUpdate(*active_model_);
8690
}
8791
break;
92+
case GLFW_KEY_ENTER:
93+
EnterPressed(*active_model_);
8894
default:
8995
break;
9096
}
@@ -170,4 +176,12 @@ void TextInputPlugin::SendStateUpdate(const TextInputModel &model) {
170176
InvokeMethod(kUpdateEditingStateMethod, model.GetState());
171177
}
172178

179+
void TextInputPlugin::EnterPressed(const TextInputModel &model) {
180+
Json::Value args = Json::arrayValue;
181+
args.append(model.client_id());
182+
args.append(kDoneAction);
183+
184+
InvokeMethod(kPerformActionMethod, args);
185+
}
186+
173187
} // 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 an action triggered by the Enter key 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)