-
Notifications
You must be signed in to change notification settings - Fork 3
feat: implement 3-state W2U toggle #5
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
Changes from 1 commit
fecb443
e38fd91
2794b34
8f7f7fc
0698dec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,7 @@ type IEngine interface { | |||||||||||||||||||
| SetFlag(uint) | ||||||||||||||||||||
| GetInputMethod() InputMethod | ||||||||||||||||||||
| ProcessKey(rune, Mode) | ||||||||||||||||||||
| SetW2UMode(int) | ||||||||||||||||||||
| ProcessString(string, Mode) | ||||||||||||||||||||
| GetProcessedString(Mode) string | ||||||||||||||||||||
| IsValid(bool) bool | ||||||||||||||||||||
|
|
@@ -59,6 +60,7 @@ type BambooEngine struct { | |||||||||||||||||||
| composition []*Transformation | ||||||||||||||||||||
| inputMethod InputMethod | ||||||||||||||||||||
| flags uint | ||||||||||||||||||||
| w2uMode int // 0: Disabled, 1: Middle-Only, 2: Everywhere | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func NewEngine(inputMethod InputMethod, flag uint) IEngine { | ||||||||||||||||||||
|
|
@@ -77,6 +79,10 @@ func (e *BambooEngine) SetFlag(flag uint) { | |||||||||||||||||||
| e.flags = flag | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func (e *BambooEngine) SetW2UMode(mode int) { | ||||||||||||||||||||
| e.w2uMode = mode | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
hthienloc marked this conversation as resolved.
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| func (e *BambooEngine) GetFlag(flag uint) uint { | ||||||||||||||||||||
| return e.flags | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -123,7 +129,18 @@ func (e *BambooEngine) generateTransformations(composition []*Transformation, lo | |||||||||||||||||||
| // If none of the applicable_rules can actually be applied then this new | ||||||||||||||||||||
| // transformation fall-backs to an APPENDING one. | ||||||||||||||||||||
| transformations = generateFallbackTransformations(composition, e.getApplicableRules(lowerKey), lowerKey, isUpperCase) | ||||||||||||||||||||
| if e.flags&Ew2uEnabled != 0 && lowerKey == 'w' && len(transformations) > 0 { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Unified Modular W2U Logic | ||||||||||||||||||||
| canApplyW2U := false | ||||||||||||||||||||
| if e.w2uMode == 1 { | ||||||||||||||||||||
| if len(composition) > 0 { | ||||||||||||||||||||
| canApplyW2U = true | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } else if e.w2uMode == 2 { | ||||||||||||||||||||
| canApplyW2U = true | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for determining Important: There is a potential regression here. The previous implementation checked the
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| if canApplyW2U && lowerKey == 'w' && len(transformations) > 0 { | ||||||||||||||||||||
| if transformations[0].Rule.Result == 'w' { | ||||||||||||||||||||
| transformations[0].Rule.Result = 'ư' | ||||||||||||||||||||
| transformations[0].Rule.EffectOn = 'ư' | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
Using magic numbers (0, 1, 2) for
w2uModemakes the code harder to read and maintain. It is recommended to define named constants or a custom type for these modes to improve clarity.