-
Notifications
You must be signed in to change notification settings - Fork 6k
[Windows - TextInput] Insert new line only when TextInputAction.newline #42244
[Windows - TextInput] Insert new line only when TextInputAction.newline #42244
Conversation
0a29291 to
16ea940
Compare
justinmc
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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?
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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::equalon https://github.com/flutter/engine/pull/42244/files/16ea94095b930f2c0a85e244b43abf31dbe690f0#diff-f913efa93fd3ac5c33b9fc924f41ff6e1a7f8300a5e548aa52fb0d30a3904b4cR247, asupdate_state_messagewill 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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
engine/shell/platform/fuchsia/flutter/text_delegate_unittests.cc
Lines 228 to 231 in 7c0a639
| 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
16ea940 to
cc96f0c
Compare
yaakovschectman
left a comment
There was a problem hiding this 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
cc96f0c to
75da226
Compare
75da226 to
b4eea8b
Compare
loic-sharma
left a comment
There was a problem hiding this 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! :)
…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
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.