Skip to content

Refactor input handling and validation with new tests#2

Closed
hthienloc wants to merge 2 commits intoLotusInputMethod:masterfrom
hthienloc:master
Closed

Refactor input handling and validation with new tests#2
hthienloc wants to merge 2 commits intoLotusInputMethod:masterfrom
hthienloc:master

Conversation

@hthienloc
Copy link

@hthienloc hthienloc commented Mar 21, 2026

This pull request refactors the backspace (removal) logic in the Bamboo input engine, unifying and simplifying how backspace is handled, and updates related tests to match the new behavior. It also introduces new tests for edge cases and updates the module path.

Backspace handling and composition management:

  • Refactored the backspace logic by introducing a new handleBackspace method in bamboo.go, which now removes the last transformation and any trailing virtual transformations with a Rule.Key of 0. The RemoveLastChar method now delegates to this new method, and the logic for refreshing the last tone has been simplified. (bamboo.go)
  • Updated ProcessKey to handle backspace keys (\b or 0x7f) directly in Vietnamese mode, calling the new handleBackspace method and returning early. (bamboo.go`)

Rule application and shortcut handling:

  • Modified getApplicableRules to return nil if the key cannot be processed, preventing unnecessary rule lookups for invalid keys. (bamboo.go)
  • Refactored shortcut application logic by replacing direct calls to applyUowShortcut with a new applyUIShortcuts helper, which returns a slice of transformations and is more extensible. (bamboo.go) [1] [2]

Testing improvements and coverage:

  • Updated several test cases in bamboo_test.go to reflect the new backspace/removal behavior, ensuring the processed string matches the expected output after removals. (bamboo_test.go) [1] [2] [3] [4] [5] [6]
  • Added new tests for backspace key handling, invalid key processing in getApplicableRules, and the CanProcessKey method, improving coverage for edge cases. (bamboo_test.go)

Project maintenance:

  • Updated the Go module path from github.com/BambooEngine/bamboo-core to github.com/LotusInputMethod/bamboo-core in go.mod. (go.mod)

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the BambooEngine's core input processing by enhancing backspace logic, making shortcut application more extensible, and strengthening input validation. These changes aim to increase the robustness and maintainability of the input method engine, supported by new comprehensive tests to ensure correct functionality.

Highlights

  • Input Handling Refactoring: Refactored backspace handling into a dedicated handleBackspace method for consistent behavior across ProcessKey and RemoveLastChar.
  • Shortcut Extensibility: Generalized the application of virtual transformations with a new applyUIShortcuts method, making it easier to extend input shortcuts like the 'uwo+' typing shortcut.
  • Input Validation: Enhanced input validation in getApplicableRules to return nil for invalid keys, preventing unnecessary rule processing.
  • Testing: Added new unit tests to verify backspace behavior, rule application for invalid keys, and the correctness of CanProcessKey.
  • Module Path Update: Updated the Go module path from github.com/BambooEngine/bamboo-core to github.com/LotusInputMethod/bamboo-core.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors input handling, particularly for backspace and shortcuts, and adds corresponding tests. The refactoring improves code structure, but I've identified a potential logic issue in the backspace handling that leads to unintuitive behavior. The new test case for backspace seems to confirm this incorrect behavior. I've also suggested a small improvement to the new applyUIShortcuts function for better clarity and efficiency. The module path update and other new tests look good.

@hthienloc hthienloc marked this pull request as draft March 21, 2026 05:36
@hthienloc hthienloc marked this pull request as ready for review March 21, 2026 06:03
@hthienloc hthienloc closed this Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant