Skip to content

[linux] Listen to Enter key events on text inputs #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/linux/src/internal/text_input_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ static constexpr char kHideMethod[] = "TextInput.hide";

static constexpr char kUpdateEditingStateMethod[] =
"TextInputClient.updateEditingState";
static constexpr char kPerformActionMethod[] = "TextInputClient.performAction";

static constexpr char kNewLineAction[] = "TextInputAction.newline";
static constexpr char kDoneAction[] = "TextInputAction.done";

static constexpr char kSelectionBaseKey[] = "selectionBase";
static constexpr char kSelectionExtentKey[] = "selectionExtent";
Expand Down Expand Up @@ -85,6 +89,8 @@ void TextInputPlugin::KeyboardHook(GLFWwindow *window, int key, int scancode,
SendStateUpdate(*active_model_);
}
break;
case GLFW_KEY_ENTER:
EnterPressed(*active_model_);
default:
break;
}
Expand Down Expand Up @@ -170,4 +176,12 @@ void TextInputPlugin::SendStateUpdate(const TextInputModel &model) {
InvokeMethod(kUpdateEditingStateMethod, model.GetState());
}

void TextInputPlugin::EnterPressed(const TextInputModel &model) {
Json::Value args = Json::arrayValue;
args.append(model.client_id());
args.append(kDoneAction);

InvokeMethod(kPerformActionMethod, args);
}

} // namespace flutter_desktop_embedding
3 changes: 3 additions & 0 deletions library/linux/src/internal/text_input_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class TextInputPlugin : public KeyboardHookHandler, public JsonPlugin {
// Sends the current state of the given model to the Flutter engine.
void SendStateUpdate(const TextInputModel &model);

// Sends an action triggered by the Enter key to the Flutter engine.
void EnterPressed(const TextInputModel &model);

// Mapping of client IDs to text input models.
std::map<int, std::unique_ptr<TextInputModel>> input_models_;

Expand Down