Skip to content

fix: respect user's minimumKeyTime for modifier-only hotkeys#241

Open
monotykamary wants to merge 1 commit into
kitlangton:mainfrom
monotykamary:fix/respect-user-minimum-key-time
Open

fix: respect user's minimumKeyTime for modifier-only hotkeys#241
monotykamary wants to merge 1 commit into
kitlangton:mainfrom
monotykamary:fix/respect-user-minimum-key-time

Conversation

@monotykamary

@monotykamary monotykamary commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Remove the hardcoded 0.3s floor that was enforced for modifier-only hotkeys regardless of the user's minimumKeyTime setting. The Settings slider already allows values down to 0.0s, but max(minimumKeyTime, 0.3) silently overrode it.

Users with obscure hotkeys (e.g. right Option) that don't conflict with OS shortcuts should be able to set a lower threshold for faster response. The default of 0.2s still provides a reasonable guard against accidental triggers.

Changes

  • RecordingDecisionEngine.decide() — use minimumKeyTime directly instead of max(minimumKeyTime, modifierOnlyMinimumDuration=0.3)
  • HotKeyProcessor.process(keyEvent:) — same for extra key press threshold during hold
  • HotKeyProcessor.processMouseClick() — same for mouse click cancellation threshold
  • Updated tests and doc comments to reflect the new behavior

The modifierOnlyMinimumDuration constant is kept for reference but no longer enforced as a floor.

Testing

All 62 existing tests pass with updated assertions. No new tests added — existing tests were adjusted to verify that the user's minimumKeyTime is respected directly.

Summary by CodeRabbit

  • Bug Fixes

    • Modifier-only hotkeys now respect the user-configured minimum key time directly, removing a previously enforced separate minimum duration constraint.
  • Documentation

    • Updated hotkey timing constant descriptions to reflect the new modifier-only hotkey behavior.
  • Tests

    • Adjusted timing-related test cases to align with updated modifier-only hotkey minimum duration handling.

Remove the hardcoded 0.3s floor that was enforced for modifier-only
hotkeys regardless of the user's minimumKeyTime setting. The slider in
Settings already allows values down to 0.0s, but the max(minimumKeyTime,
0.3) calls silently overrode it.

Users with obscure hotkeys (e.g. right Option) that don't conflict
with OS shortcuts should be able to set a lower threshold for faster
response. The default of 0.2s still provides a reasonable guard against
accidental triggers.

Changes:
- RecordingDecisionEngine.decide(): use minimumKeyTime directly
  instead of max(minimumKeyTime, modifierOnlyMinimumDuration=0.3)
- HotKeyProcessor.process(keyEvent): same for extra key press threshold
- HotKeyProcessor.processMouseClick(): same for mouse click cancellation
- Updated tests and doc comments accordingly

The modifierOnlyMinimumDuration constant is kept for reference but
no longer enforced as a floor.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates how modifier-only hotkeys enforce minimum key-press duration. Instead of using a fixed modifierOnlyMinimumDuration floor, the system now respects the user-configured minimumKeyTime directly. Changes span decision logic, processor implementation, test assertions, and documentation.

Changes

Modifier-only hotkey minimum duration consolidation

Layer / File(s) Summary
Documentation clarifications for hotkey timing constants
HexCore/Sources/HexCore/Constants.swift
Doc comments for pressAndHoldCancelWindow and defaultMinimumKeyTime updated to reflect that modifier-only hotkeys now use minimumKeyTime directly instead of being subject to modifier-only overrides.
RecordingDecisionEngine minimum-duration logic consolidation
HexCore/Sources/HexCore/Logic/RecordingDecision.swift
RecordingDecisionEngine now removes the fixed floor enforcement; decide() sets effectiveMinimum to context.minimumKeyTime unconditionally (previously took the maximum with modifierOnlyMinimumDuration for modifier-only hotkeys), directly changing when recordings are discarded or allowed to proceed.
HotKeyProcessor modifier-only timing enforcement
HexCore/Sources/HexCore/Logic/HotKeyProcessor.swift
processMouseClick and handleNonmatchingChord now use minimumKeyTime directly as the discard threshold for modifier-only hotkeys, removing the prior max-with-hardcoded-minimum logic; documentation updated to match.
Test updates for modifier-only minimum-duration behavior
HexCore/Tests/HexCoreTests/HotKeyProcessorTests.swift
Test comments clarified to reference minimumKeyTime instead of modifierOnlyMinimumDuration; test assertions and timing values adjusted to match the new thresholds; new test cases verify modifier-only hotkeys respect the user-configured minimumKeyTime directly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A modifier so modest, no longer confined,
Now listens to users with adjustable mind.
No hardcoded floor, just a gentle request—
The minimumKeyTime shall put it to rest! 🐰⌨️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: respecting the user's minimumKeyTime for modifier-only hotkeys instead of enforcing a hardcoded 0.3s floor.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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 `@HexCore/Sources/HexCore/Constants.swift`:
- Line 50: Update the misleading comments in Constants.swift so they match the
hotkey timing contract: state that modifier-only hotkeys use a fixed 0.3s safety
threshold (not the user's minimumKeyTime), while regular hotkeys use the user's
minimumKeyTime; reference the HotKeyProcessor timing behavior and the
minimumKeyTime symbol in the comment to make the distinction explicit and ensure
consistency with the modifier-only handling described in HotKeyProcessor.swift.

In `@HexCore/Sources/HexCore/Logic/HotKeyProcessor.swift`:
- Around line 46-47: The discard threshold for modifier-only hotkeys was changed
to use minimumKeyTime directly; revert this by enforcing a 0.3s safety floor for
modifier-only hotkeys: compute the threshold as max(minimumKeyTime, 0.3) (or
otherwise ensure it is at least 0.3s) wherever discard/ignore decisions are made
(e.g., the mouse-click cancellation path and the non-matching-chord cancellation
path in HotKeyProcessor.swift); update the three other occurrences called out in
the comment so modifier-only hotkeys use the 0.3s floor while regular hotkeys
continue to use minimumKeyTime.

In `@HexCore/Sources/HexCore/Logic/RecordingDecision.swift`:
- Around line 69-73: The discard logic now uses effectiveMinimum =
context.minimumKeyTime directly which allows sub-0.3s modifier-only recordings;
change the computation so that when the recording/hotkey is modifier-only (check
the appropriate boolean used in this file, e.g., isModifierOnly or modifierOnly
flag on the recording/hotkey), effectiveMinimum becomes
max(context.minimumKeyTime, 0.3) instead of just context.minimumKeyTime; update
the assignment in RecordingDecision.swift where effectiveMinimum is set and
ensure any downstream comparisons use this capped value.

In `@HexCore/Tests/HexCoreTests/HotKeyProcessorTests.swift`:
- Around line 741-743: Tests wrongly assume modifier-only hotkeys respect the
user-configured minimumKeyTime (e.g., 0.2s); update assertions to enforce the
fixed modifier-only safety floor of 0.3s. Locate the tests that call
makeContext(hotkey: HotKey(key: nil, modifiers: [...] ), duration: ...) and
assert via RecordingDecisionEngine.decide(...) and change expectations so
durations < 0.3s result in the non-transcription decision and durations >= 0.3s
result in .proceedToTranscription, ensuring all occurrences (around the
makeContext/HotKey usage at the referenced ranges) follow the 0.3s threshold
rather than the user minimumKeyTime.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65cd24d6-e748-4bd0-b821-e36062dc233e

📥 Commits

Reviewing files that changed from the base of the PR and between 71878b7 and 2e02926.

📒 Files selected for processing (4)
  • HexCore/Sources/HexCore/Constants.swift
  • HexCore/Sources/HexCore/Logic/HotKeyProcessor.swift
  • HexCore/Sources/HexCore/Logic/RecordingDecision.swift
  • HexCore/Tests/HexCoreTests/HotKeyProcessorTests.swift

Comment thread HexCore/Sources/HexCore/Constants.swift
Comment thread HexCore/Sources/HexCore/Logic/HotKeyProcessor.swift
Comment thread HexCore/Sources/HexCore/Logic/RecordingDecision.swift
Comment thread HexCore/Tests/HexCoreTests/HotKeyProcessorTests.swift
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