Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix the Japanese IME problem on macOS reported in the following issue. #166291

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 4 commits into from
Jun 21, 2025

Conversation

hidea
Copy link
Contributor

@hidea hidea commented Mar 31, 2025

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. a: desktop Running on desktop platform-macos labels Mar 31, 2025
@hidea
Copy link
Contributor Author

hidea commented Apr 3, 2025

cc: @cbenhagen , @justinmc

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #166291 at sha c0e00f8

@jmagman
Copy link
Member

jmagman commented Apr 14, 2025

@cbracken can you take a look?

@jmagman jmagman requested a review from cbracken April 14, 2025 16:38
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Thank you for your patch and apologies for missing this while I was out!

I think this is fine but I added a suggestion that might be a little cleaner. I'd like to know if you tried that approach, and if so, was it problematic?

// !range.collapsed()), selection == composing_range will failed. Therefore, the selection
// cursor should only be placed at the beginning of composing_range.
flutter::TextRange composing_range = _activeModel->composing_range();
_activeModel->SetSelection(flutter::TextRange(composing_range.start()));
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for spotting this. This feels like we're working around a bug in TextInputRange::AddText/TextInputRange::DeleteSelected.

I think when I wrote that code, I made the incorrect assumption that during composing, we'd only ever have a selection that matches the composing range.

I wonder if we should fix the logic there or at least add some assertions. If you look at what happens in the case where the selection is a subrange of the composing range, it deletes the selection and resets the composing range.

Instead it looks like what we should be doing is setting the selection to a collapsed selection at the start of the composing range. Here's the current implementation:

void TextInputModel::AddText(const std::u16string& text) {
  DeleteSelected();
  if (composing_) {
    // Delete the current composing text, set the cursor to composing start.
    text_.erase(composing_range_.start(), composing_range_.length());
    selection_ = TextRange(composing_range_.start());
    composing_range_.set_end(composing_range_.start() + text.length());
  }
  size_t position = selection_.position();
  text_.insert(position, text);
  selection_ = TextRange(position + text.length());
}

I wonder if we should change that to:

void TextInputModel::AddText(const std::u16string& text) {
  if (composing_) {
    // Delete the current composing text, set the cursor to composing start.
    text_.erase(composing_range_.start(), composing_range_.length());
    selection_ = TextRange(composing_range_.start());
    composing_range_.set_end(composing_range_.start() + text.length());
  } else {
    DeleteSelected();
  }
  size_t position = selection_.position();
  text_.insert(position, text);
  selection_ = TextRange(position + text.length());
}

I think the above is equivalent to your patch, but if we wanted to be a little more paranoid:

void TextInputModel::AddText(const std::u16string& text) {
  if (composing_ && composing_range_ != selection_) {
    selection_ = TextRange{composing_range_.start()};
  }
  DeleteSelected();
  if (composing_) {
    // Delete the current composing text, set the cursor to composing start.
    text_.erase(composing_range_.start(), composing_range_.length());
    selection_ = TextRange(composing_range_.start());
    composing_range_.set_end(composing_range_.start() + text.length());
  }
  size_t position = selection_.position();
  text_.insert(position, text);
  selection_ = TextRange(position + text.length());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My RP was not comprehensive enough to grasp the overall structure, and I focused on ensuring the consistency of input/output for bugs that would prevent the app from being released when using Flutter.
If that can be achieved, I will leave the final revision method up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't TextInputModel::AddText, which was presented, common code for all platforms?
I believe that this issue is limited to macOS IME behavior.

@jmagman
Copy link
Member

jmagman commented May 15, 2025

@cbracken can you take another look at this?

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

Apologies for the delay -- this lgtm.

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2025
Copy link
Contributor

auto-submit bot commented Jun 2, 2025

autosubmit label was removed for flutter/flutter/166291, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@cbracken cbracken requested a review from loic-sharma June 6, 2025 21:53
@cbracken
Copy link
Member

cbracken commented Jun 6, 2025

@loic-sharma would you mind doing a secondary review?

@chinmaygarde
Copy link
Member

While we are waiting for @loic-sharma s review, can we also resolve the merge conflicts?

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.

LGTM

@vashworth vashworth added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 11, 2025
Copy link
Contributor

auto-submit bot commented Jun 11, 2025

autosubmit label was removed for flutter/flutter/166291, because Pull request flutter/flutter/166291 is not in a mergeable state.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 11, 2025
@chinmaygarde
Copy link
Member

The presubmit failures do look real.

@cbracken
Copy link
Member

I've fixed up the formatting issue locally and re-pushed.

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 20, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 21, 2025
Merged via the queue into flutter:master with commit 453d113 Jun 21, 2025
174 of 175 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 21, 2025
@cbracken
Copy link
Member

@hidea Thanks for the fix! PRのマージが遅くなってすみませんでした。

@hidea
Copy link
Contributor Author

hidea commented Jun 21, 2025

@cbracken
Thank you very much for your review and merge.
I didn't know how to submit a PR, so it took me a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop engine flutter/engine repository. See also e: labels. platform-macos will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Japanese IME input is not working properly on macOS
6 participants