feat(rules): add URL match types and drag-to-reorder priority#26
Conversation
Per-URL rules (enhanced mode) gain a match type — domain suffix, exact domain, domain keyword, or a regular expression over the full URL — and a user-arranged priority order: rules resolve top to bottom, first match wins, and the list is drag-reorderable. The URL-scheme API, .lockime backup/import, and the localized docs carry the new field through. A rule's pattern is its portable identity (backups and import key on it), so the mutators enforce that no two rules ever share one: the upsert/reorder logic is centralized in URLRuleList, and the editor and URL-scheme API reject a colliding pattern. An edit can no longer silently mint a duplicate that would collapse, losing a rule, on the next export/import. URL-regex matching is bounded in UTF-16 code units to cap the regex engine's backtracking on long inputs. Signed-off-by: Kevin Cui <bh@bugs.cc>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (4)
Summary by CodeRabbitRelease Notes
WalkthroughThis PR adds flexible URL matching to LockIME's enhanced mode. A new
Possibly Related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
README.md (1)
124-126:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winRemove the stray
+beforexcbeautify.That character will render literally in the published README.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.md` around lines 124 - 126, Remove the stray `+` character that appears before the `[xcbeautify]` link in the installation instructions. This character should not be present and will render literally in the published README, disrupting the formatting of the dependency list.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/URL-Scheme-API/README.zh-CN.md`:
- Around line 142-145: The documentation lists only a partial set of match-type
aliases (suffix, keyword, regex) without clarifying whether this is a complete
or example list, creating ambiguity about other valid aliases. In
docs/URL-Scheme-API/README.zh-CN.md at lines 142-145, update the match-type
alias sentence to either enumerate all supported aliases (domain-exact, exact,
domainkeyword, domainsuffix, urlregex, matchtype) or explicitly state that the
listed aliases are examples only and the parser accepts additional forms. Then
apply the identical clarification to docs/URL-Scheme-API/README.zh-TW.md at
lines 143-145 to maintain consistency across the Simplified and Traditional
Chinese versions.
In `@Sources/LockIMEKit/Backup/ImportPlan.swift`:
- Around line 255-260: The ImportPlan file keys URL rules by raw case-sensitive
hostPattern strings at multiple locations, which can miss pattern collisions
differing only by case and break conflict detection. Create a canonical
pattern-key function (such as normalizing hostPattern to lowercase) and apply
this consistently everywhere URL rules are keyed: in the localByHost Dictionary
construction (line 258), in the seenFileHosts set insertion (line 259), and at
all other affected locations mentioned in the consolidated sites (lines 289-291,
367-373, 403-411). Ensure the same canonical normalization is used throughout
the file for all hostPattern-based lookups and deduplication.
In `@Sources/LockIMEKit/Rules/URLRuleList.swift`:
- Around line 77-80: The guard statement in the URLRuleList method is checking
only set equality of IDs, which allows duplicate IDs in the ordered array to
pass validation. To enforce that reordered accepts only valid permutations with
no duplicates, add an additional condition to the guard that verifies the
ordered array's ID count equals the count of unique IDs. This ensures that an
input like [a, a, b] is rejected rather than returning duplicated rules. Check
that ordered.map(\.id).count equals Set(ordered.map(\.id)).count or equivalently
that the ordered array length equals the byID keys count.
In `@Tests/LockIMEKitTests/LocalizationGuardTests.swift`:
- Around line 213-216: The check in the LocalizationGuardTests.swift file at the
Issue.record call is too lenient because it only searches for the presence of
`.environment(\.locale` without verifying that `state.locale` specifically is
the injected value. Update the condition in the if statement to check for the
complete pattern `.environment(\.locale, state.locale)` instead of just
`.environment(\.locale` to ensure sheets are re-injecting the correct locale
override as required by the in-app language override contract.
---
Outside diff comments:
In `@README.md`:
- Around line 124-126: Remove the stray `+` character that appears before the
`[xcbeautify]` link in the installation instructions. This character should not
be present and will render literally in the published README, disrupting the
formatting of the dependency list.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0dbd2dff-2db4-4882-8011-8b1e9d24d20d
📒 Files selected for processing (39)
README.mdSources/LockIME/API/URLCommandHandler.swiftSources/LockIME/AppState.swiftSources/LockIME/Localizable.xcstringsSources/LockIME/UI/AboutView.swiftSources/LockIME/UI/Settings/AppRulesSettingsPane.swiftSources/LockIME/UI/Settings/ImportReviewSheet.swiftSources/LockIME/UI/Settings/URLRulesSettingsPane.swiftSources/LockIMEKit/API/URLCommand.swiftSources/LockIMEKit/Backup/ConfigBackup.swiftSources/LockIMEKit/Backup/ImportPlan.swiftSources/LockIMEKit/Enhanced/URLMatcher.swiftSources/LockIMEKit/LockEngine/LockEngine.swiftSources/LockIMEKit/Rules/LockConfiguration.swiftSources/LockIMEKit/Rules/URLRuleList.swiftTests/LockIMEKitTests/ConfigBackupTests.swiftTests/LockIMEKitTests/ImportPlanTests.swiftTests/LockIMEKitTests/LocalizationGuardTests.swiftTests/LockIMEKitTests/LockConfigurationTests.swiftTests/LockIMEKitTests/URLCommandParserTests.swiftTests/LockIMEKitTests/URLMatcherTests.swiftTests/LockIMEKitTests/URLRuleListTests.swiftdocs/README/README.de.mddocs/README/README.es.mddocs/README/README.fr.mddocs/README/README.ja.mddocs/README/README.pt.mddocs/README/README.ru.mddocs/README/README.zh-CN.mddocs/README/README.zh-TW.mddocs/URL-Scheme-API/README.de.mddocs/URL-Scheme-API/README.es.mddocs/URL-Scheme-API/README.fr.mddocs/URL-Scheme-API/README.ja.mddocs/URL-Scheme-API/README.mddocs/URL-Scheme-API/README.pt.mddocs/URL-Scheme-API/README.ru.mddocs/URL-Scheme-API/README.zh-CN.mddocs/URL-Scheme-API/README.zh-TW.md
Address CodeRabbit review on #26: - URLRuleList.reordered: reject non-permutations carrying duplicate ids (matching id set but wrong count, e.g. [a, a, b] against [a, b]); set equality alone let such input through and returned a list with a duplicated rule, corrupting the persisted priority order. - LocalizationGuardTests: tighten the .sheet locale guard to require the window re-inject the app's own locale (state/appState.locale), not just any \.locale value, and strip per-line comments so a commented-out modifier can't satisfy it. - URL-Scheme-API docs (all languages): mark the match-type alias list as non-exhaustive, since the parser accepts more aliases (domain-exact, exact, domainsuffix, domainkeyword, urlregex, matchtype) than were listed. English authoritative copy and every translation kept in sync. Signed-off-by: Kevin Cui <bh@bugs.cc>
The committed screenshots predated the URL match-type badges and drag-to-reorder priority (#26) and the General "Automation" section (#25), so all three panes were out of date. Regenerate the full set of 12 (General, App Rules, URL Rules x en/zh-CN x light/dark). The URL Rules pane now shows four rules spanning every match type (domain suffix, exact domain, domain keyword, URL regex) to surface the new badges and the reorder caption. Images are now 2024x1600 because SettingsRootView gained a 600pt minimum content height. Signed-off-by: Kevin Cui <bh@bugs.cc>
Per-URL rules (enhanced mode) gain a match type — domain suffix, exact domain, domain keyword, or a regular expression over the full URL — and a user-arranged priority order: rules resolve top to bottom, first match wins, and the list is drag-reorderable. The URL-scheme API, .lockime backup/import, and the localized docs carry the new field through.
A rule's pattern is its portable identity (backups and import key on it), so the mutators enforce that no two rules ever share one: the upsert/reorder logic is centralized in URLRuleList, and the editor and URL-scheme API reject a colliding pattern. An edit can no longer silently mint a duplicate that would collapse, losing a rule, on the next export/import. URL-regex matching is bounded in UTF-16 code units to cap the regex engine's backtracking on long inputs.