Skip to content

Conversation

@VictoriousRaptor
Copy link
Contributor

Fixes #3965

@VictoriousRaptor VictoriousRaptor added this to the 2.1.0 milestone Dec 7, 2025
@VictoriousRaptor VictoriousRaptor self-assigned this Dec 7, 2025
@VictoriousRaptor VictoriousRaptor added the bug Something isn't working label Dec 7, 2025
@gitstream-cm
Copy link

gitstream-cm bot commented Dec 7, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the pinyin query text highlighting feature where characters were incorrectly highlighted when translated indices matched exact boundaries in the translation mapping. The issue occurred when a matched index in the translated pinyin string corresponded to a boundary position between original Chinese characters.

Key changes:

  • Fixed the MapToOriginalIndex method to correctly handle exact boundary matches by adding + 1 to the result when BinarySearch finds an exact match

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 7, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adjusts translated→original index mapping for exact matches, refines pinyin tokenization/spacing around Chinese vs non‑Chinese boundaries, and expands unit tests to assert finer-grained translated→original index mappings for mixed Chinese/non‑Chinese input.

Changes

Cohort / File(s) Change Summary
Index mapping adjustment
Flow.Launcher.Infrastructure/TranslationMapping.cs
MapToOriginalIndex now returns searchResult + 1 for exact-match translated indices; unchanged behavior for misses (~searchResult).
Pinyin tokenization & spacing
Flow.Launcher.Infrastructure/PinyinAlphabet.cs
When translating: insert a space before Chinese segments only if the previous character is not a space; after Chinese runs, append a space only if the current non‑Chinese char is not a space. Non‑Chinese mapping length fixed to 1 and the single character appended. Added and used a ContainsChinese(ReadOnlySpan<char>) overload.
Tests updated to match mapping behavior
Flow.Launcher.Test/TranslationMappingTest.cs
Expanded test cases to cover per-character translated→original index mappings for "Flow 用户" → "Flow Yong Hu", updated AddNewIndex setup and expected indices for translated positions 0–11 accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas:
    • Verify the +1 change in MapToOriginalIndex aligns with downstream indexing/consumers (call sites that interpret returned indices).
    • Validate Pinyin spacing logic at Chinese/non‑Chinese boundaries (edge cases: consecutive spaces, start/end of string).
    • Confirm tests reflect intended per-character mapping semantics and cover boundary positions.

Possibly related PRs

Suggested reviewers

  • jjw24
  • Jack251970
  • taooceros

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main fix: correcting incorrect text highlighting when using pinyin queries, which aligns with the core changes in the codebase.
Description check ✅ Passed The description references issue #3965, which matches the linked issue about incorrect text highlighting with pinyin queries.
Linked Issues check ✅ Passed The PR fixes the text highlighting bug [#3965] through corrected index mappings in PinyinAlphabet.cs and TranslationMapping.cs, with matching test updates demonstrating the expected behavior.
Out of Scope Changes check ✅ Passed All changes are focused on fixing pinyin translation index mappings and spacing logic, directly addressing the highlighting issue with no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix3965

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42e04d4 and b6339d3.

📒 Files selected for processing (1)
  • Flow.Launcher.Test/TranslationMappingTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)
Flow.Launcher.Infrastructure/TranslationMapping.cs (2)
  • TranslationMapping (6-33)
  • AddNewIndex (14-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)

40-51: Mapping setup and index comments correctly reflect “Flow 用户” → “Flow Yong Hu”.

The per‑character comments and AddNewIndex calls now line up with the actual indices and lengths:

  • Original: "Flow 用户" → indices 0–6.
  • Translated: "Flow Yong Hu" → indices 0–11.
  • _originalToTranslated ends up as [1,2,3,4,5,9,12], so:
    • 0–4 map to originals 0–4,
    • 5–8 map to original 5 ("Yong"),
    • 9–11 map to original 6 (" Hu").

This matches the updated MapToOriginalIndex semantics (exact matches returning searchResult + 1) and should robustly guard against the off‑by‑one highlighting issue the PR targets.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Jack251970
Jack251970 previously approved these changes Dec 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)

26-35: Consider adding a test case for the space at index 9.

The test cases cover a good range of scenarios, but notably skip index 9, which should be the space between "Yong" and "Hu". Adding [TestCase(9, 5)] or [TestCase(9, 6)] (depending on expected behavior) would provide more complete coverage of the space insertion logic that was modified in this PR.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d9de4b and b869eb8.

📒 Files selected for processing (2)
  • Flow.Launcher.Infrastructure/PinyinAlphabet.cs (5 hunks)
  • Flow.Launcher.Test/TranslationMappingTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)
Flow.Launcher.Infrastructure/TranslationMapping.cs (2)
  • TranslationMapping (6-33)
  • AddNewIndex (14-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: CodeQL analysis (csharp)
  • GitHub Check: Agent
  • GitHub Check: gitStream.cm
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (5)
Flow.Launcher.Test/TranslationMappingTest.cs (1)

39-50: Excellent test documentation and setup.

The comments clearly illustrate the character-by-character translation mapping, making the test logic easy to follow. The per-character AddNewIndex calls for ASCII characters and multi-character mappings for Chinese characters correctly reflect the updated translation behavior.

Flow.Launcher.Infrastructure/PinyinAlphabet.cs (4)

132-135: Correct fix to prevent double spaces.

The additional check content[i - 1] != ' ' prevents inserting a space before a Chinese character when the previous character is already a space, avoiding unnecessary double spacing in the translation.


147-150: Good symmetry in space handling logic.

The conditional space insertion after Chinese characters mirrors the logic before Chinese characters (line 132), ensuring consistent handling of existing spaces and preventing double spacing throughout the translation.


153-154: Key fix for the highlighting bug.

This change is critical to resolving issue #3965:

  • Using fixed length 1 for non-Chinese characters ensures correct 1:1 index mapping
  • Appending content[i] directly (instead of resultList[i]) is more efficient and guarantees the original character is preserved
  • Together, these changes prevent the "omitted last character" issue in mixed pinyin/non-pinyin queries by maintaining accurate translated-to-original index mappings

191-193: Minor formatting improvement.

The reformatted ternary expression is slightly more readable, though functionally unchanged. The logic correctly returns the double pinyin translation if available, otherwise falls back to the full pinyin.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gitstream-cm
Copy link

gitstream-cm bot commented Dec 7, 2025

🥷 Code experts: no user but you matched threshold 10

VictoriousRaptor has most 👩‍💻 activity in the files.
VictoriousRaptor has most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Activity based on git-commit:

VictoriousRaptor
DEC
NOV
OCT
SEP
AUG
JUL 94 additions & 59 deletions

Knowledge based on git-blame:
VictoriousRaptor: 92%

Flow.Launcher.Infrastructure/TranslationMapping.cs

Activity based on git-commit:

VictoriousRaptor
DEC
NOV
OCT
SEP
AUG
JUL 22 additions & 82 deletions

Knowledge based on git-blame:
VictoriousRaptor: 100%

Flow.Launcher.Test/TranslationMappingTest.cs

Activity based on git-commit:

VictoriousRaptor
DEC
NOV
OCT
SEP
AUG
JUL 56 additions & 0 deletions

Knowledge based on git-blame:
VictoriousRaptor: 84%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)

42-43: Consider clarifying the position markers.

The format "012345678901" uses single digits where the last "01" represents positions 10 and 11, which could be momentarily confusing. While technically correct, a two-row format might be clearer:

 // Test case :
 // 0123456
 // Flow 用户
-// 012345678901
+// 0         1
+// 01234567890 1
 // Flow Yong Hu

Or simply add spacing to align with the string:

-// 012345678901
-// Flow Yong Hu
+// 0    5    10
+// Flow Yong Hu
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7c67bb and 769179d.

📒 Files selected for processing (1)
  • Flow.Launcher.Test/TranslationMappingTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)
Flow.Launcher.Infrastructure/TranslationMapping.cs (2)
  • TranslationMapping (6-33)
  • AddNewIndex (14-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Agent
  • GitHub Check: CodeQL analysis (csharp)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher.Test/TranslationMappingTest.cs (2)

12-23: LGTM!

The test correctly verifies that AddNewIndex stores the cumulative boundary (translatedIndex + length) for each original index.


56-68: LGTM!

The helper methods appropriately use reflection to access private fields for white-box testing. This is a standard and acceptable pattern for verifying internal state in unit tests.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 769179d and 42e04d4.

📒 Files selected for processing (1)
  • Flow.Launcher.Test/TranslationMappingTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)
Flow.Launcher.Infrastructure/TranslationMapping.cs (2)
  • TranslationMapping (6-33)
  • AddNewIndex (14-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher.Test/TranslationMappingTest.cs (1)

26-37: Per‑index mapping tests look consistent and complete

The per‑character [TestCase] set for translated indices 0–11 matches the TranslationMapping.MapToOriginalIndex behavior (including the boundary at index 9 and the final 'u' at index 11) and now fully exercises the mixed Chinese/non‑Chinese example relevant to the pinyin highlighting bug.

@VictoriousRaptor VictoriousRaptor merged commit c03c778 into dev Dec 9, 2025
13 checks passed
@VictoriousRaptor VictoriousRaptor deleted the fix3965 branch December 9, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 min review bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Incorrect text highlighting when using pinyin queries

3 participants