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

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented May 23, 2023

Description

This PR updates the Windows text input plugin to avoid adding a new line on a multiline text field when action is not set to TextInputAction.newline.

Related Issue

Fixes flutter/flutter#125879 as Linux and macOS implementations are merged.
Linux PR: #41895
macOS PR: #41977

Tests

Adds 2 tests.

@bleroux bleroux force-pushed the windows_text_input_insert_new_line_only_for_input_action_newline branch 2 times, most recently from 0a29291 to 16ea940 Compare May 23, 2023 14:16
@bleroux bleroux requested review from cbracken and justinmc May 23, 2023 15:11
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Maybe wait for @cbracken in case he wants to take a look, I'm no expert on the Windows tests here. Thanks for following up on another platform for this!

std::string input_action) {
auto arguments = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
auto& allocator = arguments->GetAllocator();
arguments->PushBack(42, allocator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the significance of this value 42 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the client ID. I duplicated this from existing code (see lines 173, 254 and 301).
I can add an inline comment such as arguments->PushBack(42, allocator); // Client id.or a constant such as kDefaultClientId, which one do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am inclined to prefer using a named constant, but either approach sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for named constant here

Comment on lines 215 to 219
int length = static_cast<int>(message_size);
std::vector<uint8_t> last_message(length);
memcpy(&last_message[0], &message[0], length * sizeof(uint8_t));
messages.push_back(last_message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of storing std::strings instead?

Suggested change
int length = static_cast<int>(message_size);
std::vector<uint8_t> last_message(length);
memcpy(&last_message[0], &message[0], length * sizeof(uint8_t));
messages.push_back(last_message);
std::string last_message(reinterpret_cast<const char*>(message), message_size);
messages.push_back(last_message);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@bleroux bleroux May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of storing std::strings instead?

I choosed to rely on std::vector<uint8_t> because this is the type that is returned by codec.EncodeMethodCall, I think it is more understandable to stick to the type expectations of the existing APIs use by the test.

Copy link
Member

@loic-sharma loic-sharma May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing std::strings would make debugging a bit easier if things break.

If you still prefer storing uint8_ts, could you replace the memcpy's &last_message[0] argument with last_message.data()?

Would this still allow use of std::equal on https://github.com/flutter/engine/pull/42244/files/16ea94095b930f2c0a85e244b43abf31dbe690f0#diff-f913efa93fd3ac5c33b9fc924f41ff6e1a7f8300a5e548aa52fb0d30a3904b4cR247, as update_state_message will still be the same type?

We can replace EXPECT_TRUE(std::equal(a, b)) with EXPECT_EQ(a, b) if both values are std::strings. Please let me know if I misunderstood your question!

Copy link
Contributor Author

@bleroux bleroux Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the PR to store messages as std::string as suggested (less code and not relying on memcpy, thanks for the suggestion).
I have not updated the check on line 248 because I did not manage to find a less verbose way to do it.

Copy link
Member

@loic-sharma loic-sharma Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally for line 248 I would just use a string with the expected JSON. Here's an example where we do that:

EXPECT_EQ(
R"({"method":"TextInputClient.performAction","args":[7,"TextInputAction.done"]})",
MessageToString(*last_message_));
}

I don't feel strongly about this though, feel free to keep the existing logic

@bleroux bleroux force-pushed the windows_text_input_insert_new_line_only_for_input_action_newline branch from 16ea940 to cc96f0c Compare May 31, 2023 06:56
Copy link
Contributor

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as long as @loic-sharma is good with the use of vectors as you've been discussing

@bleroux bleroux force-pushed the windows_text_input_insert_new_line_only_for_input_action_newline branch from cc96f0c to 75da226 Compare June 1, 2023 07:19
@bleroux bleroux force-pushed the windows_text_input_insert_new_line_only_for_input_action_newline branch from 75da226 to b4eea8b Compare June 1, 2023 14:15
Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a std::string for the expected JSON. See this comment: #42244 (comment)

Otherwise, LGTM! Thank you for the patch! :)

@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 1, 2023
@auto-submit auto-submit bot merged commit f382b85 into flutter:main Jun 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 1, 2023
@bleroux bleroux deleted the windows_text_input_insert_new_line_only_for_input_action_newline branch June 2, 2023 05:03
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 2, 2023
…128089)

flutter/engine@3a453f2...02d6fbb

2023-06-01 [email protected] [Impeller] Emplace directly into host buffer (avoid VBB) for text data (flutter/engine#42484)
2023-06-01 [email protected] Ensure PlatformView engine life cycle callbacks are invoked (flutter/engine#42491)
2023-06-01 [email protected] Roll Skia from c408e8e9cc96 to 082a7d1f72f7 (8 revisions) (flutter/engine#42496)
2023-06-01 [email protected] [Windows - TextInput] Insert new line only when TextInputAction.newline (flutter/engine#42244)
2023-06-01 [email protected] Revert "Move clang tidy v2 build to prod." (flutter/engine#42495)
2023-06-01 [email protected] Add myself to AUTHORS (flutter/engine#42406)
2023-06-01 [email protected] [Impeller] Add Impeller Metal support in the embedder API (flutter/engine#42411)
2023-06-01 [email protected] Support DisposalMethod::kRestorePrevious in MultiFrameCodec and fix the apng problem. (flutter/engine#42153)
2023-06-01 [email protected] Fix crash getting spell-check suggestions (flutter/engine#42466)
2023-06-01 [email protected] Fix lint in rectangle packer (flutter/engine#42489)
2023-06-01 [email protected] Wait for GL command completion in the ExternalTextureGLRefreshedTooOften test (flutter/engine#42438)
2023-06-01 [email protected] Reland "[web] Remove the JS API for url strategy (#42134)" (flutter/engine#42486)
2023-06-01 [email protected] Roll Skia from f5bc3d12f0eb to c408e8e9cc96 (9 revisions) (flutter/engine#42487)
2023-06-01 [email protected] Clean up Skia includes around SkSurfaceCharacterization (flutter/engine#42485)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected new line added after pressed Enter when using multi-line TextField with TextInputAction.send

5 participants