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

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Oct 6, 2023

Fixes flutter/flutter#130880 , by making sure when the text is cleared the markedTextRange is cleared with it.

[UITextField replaceRange:withText:] always sets the selection range to the end of the replacement text, and removes the current markedTextRange. This PR makes the input plugin do the same in the replaceRange:withText: implementation.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch 2 times, most recently from a0f4ec6 to 2bf714a Compare October 6, 2023 01:20
@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch 5 times, most recently from 9fb835d to 8ddf821 Compare October 8, 2023 04:59
@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch from 8ddf821 to 12a3d68 Compare October 9, 2023 03:29
@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch from 86b3df7 to 62ae972 Compare October 9, 2023 17:58
@LongCatIsLooong LongCatIsLooong marked this pull request as ready for review October 9, 2023 18:00
@LongCatIsLooong LongCatIsLooong requested review from cyanglaz, hellohuanlin and stuartmorgan-g and removed request for stuartmorgan-g October 9, 2023 18:01
// documentation but UITextField always sets markedTextRange to nil,
// and collapses the selection to the end of the new replacement text.
range.location += text.length;
range.length = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this stomping the parameter instead of making a new range (and then replacing that new range with the clamped version)? Writing to parameters is generally bad for readability.


NSUInteger selectionLocation = markedSelectedRange.location + markedTextRange.location;
selectedRange = NSMakeRange(selectionLocation, markedSelectedRange.length);
markedSelectedRange.location += newMarkedRange.location;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use a new variable rather than overwriting the param.

- (BOOL)isVisibleToAutofill;
- (id<FlutterTextInputDelegate>)textInputDelegate;
- (void)configureWithDictionary:(NSDictionary*)configuration;
- (void)replaceRangeLocal:(NSRange)range withText:(NSString*)text;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't the behavior be tested via the text input protocol, rather than internal implementation details?

@hellohuanlin
Copy link
Contributor

I may need some help understanding this change. Could you update the PR description with more details?

@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch 2 times, most recently from 0f23d4d to b1d2846 Compare October 12, 2023 20:59
@LongCatIsLooong
Copy link
Contributor Author

PR description updated.

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

Overall makes sense. Just 1 question

? currentMarkedTextRange.range
: _selectedTextRange.range;
// No need to call replaceRangeLocal as this method always adjusts the
// selected/marked text ranges anyways.
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 a bit lost here. Can you explain more why we had this before, and we removed it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaceRangeLocal also changes the selected text range and the marked text range, based on the original selected text range and the marked text range and the text replacement. It's not needed in this method because with this method the caller always have to specify a new selected range and marked range anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the the same reason we removed the markedText state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

markedText was never used.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Code LGTM

Just to be safe, have you checked any issues/behaviors referenced in the PRs that created the logic you are replacing, to make sure nothing is being regressed (that wasn't sufficiently unit tested)?

@LongCatIsLooong LongCatIsLooong force-pushed the ios-adjust-markedTextRange branch from b1d2846 to 97f0a33 Compare October 17, 2023 23:28
@LongCatIsLooong
Copy link
Contributor Author

i've tested this patch on ios17 simulator and it worked fine, and it does fix the framework assert.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 18, 2023
@auto-submit auto-submit bot merged commit b67edb0 into flutter:main Oct 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2023
@LongCatIsLooong LongCatIsLooong deleted the ios-adjust-markedTextRange branch October 18, 2023 21:46
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 18, 2023
…136844)

flutter/engine@6caee32...b67edb0

2023-10-18 [email protected] [iOS TextInputPlugin] adjust the markedTextRange when replacing text. (flutter/engine#46603)
2023-10-18 [email protected] Reland: Remove the frontend server wrapper (flutter/engine#47010)
2023-10-18 [email protected] Roll Skia from 9880c4006735 to ef0e93524e7d (1 revision) (flutter/engine#47069)
2023-10-18 [email protected] Roll Skia from 523f04f1a898 to 9880c4006735 (1 revision) (flutter/engine#47067)
2023-10-18 [email protected] Roll Skia from ccd07c6f5042 to 523f04f1a898 (1 revision) (flutter/engine#47065)

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://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…#46603)

Fixes flutter/flutter#130880 , by making sure when the text is cleared the `markedTextRange` is cleared with it. 

`[UITextField replaceRange:withText:]` always sets the selection range to the end of the replacement text, and removes the current `markedTextRange`. This PR makes the input plugin do the same in the `replaceRange:withText:` implementation.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
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-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android iOS] Error Occurs when Switching TextField with Chinese Input Method

3 participants