Skip to content

Conversation

@gdamore
Copy link
Owner

@gdamore gdamore commented Dec 16, 2025

This also fixes the missing time initialization for focus events.

Summary by CodeRabbit

Release Notes

  • Refactor

    • Unified event timestamp handling by consolidating individual time fields into an embedded mechanism
    • Applied consistent timestamp initialization across all event types
    • Improved internal event object structure and initialization flow
  • Tests

    • Added validation to ensure event timestamps remain in chronological order

✏️ Tip: You can customize this high-level summary in your review settings.

This also fixes the missing time initialization for focus events.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

Walkthrough

This pull request refactors timestamp handling across multiple event types by replacing individual time.Time fields with embedded EventTime types, removing corresponding When() accessor methods, and updating constructors to initialize timestamps via SetEventNow(). A timestamp validation check is added to event tests.

Changes

Cohort / File(s) Summary
Event type timestamp refactoring
errors.go, interrupt.go, key.go, mouse.go, resize.go
Replaces direct t time.Time field with embedded EventTime; removes When() methods; updates constructors to call SetEventNow() instead of direct timestamp assignment; removes unused time imports.
Focus event time field update
focus.go
Changes embedded pointer field from *EventTime to value type EventTime; refactors NewEventFocus to set Focused, call SetEventNow(), and return the value.
Event test timestamp validation
event_test.go
Adds non-decreasing timestamp verification for events processed from the channel; tracks current timestamp and validates new events do not occur earlier.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Homogeneous refactoring pattern across five event types reduces per-file complexity, but the breadth of changes requires systematic verification across all affected types.
  • Areas requiring extra attention:
    • Verify all calls to removed When() methods have been updated throughout the codebase (not just these files).
    • Confirm SetEventNow() implementation correctly initializes timestamps on the embedded EventTime type.
    • Validate that focus.go's shift from pointer to value embedding does not introduce unintended behavioral changes in event copying or modification.
    • Review the test addition in event_test.go to ensure the timestamp ordering logic is correct and does not introduce flakiness.

Poem

🐰 Timestamps now nestle in EventTime's embrace,
No more scattered fields in each event's case,
When() methods fade, SetEventNow takes the stage,
Refactored and tidy on this organized page!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main refactoring objective: replacing individual time.Time fields across multiple event types with a common embedded EventTime base.
✨ 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 gdamore/event-time

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

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)
event_test.go (1)

43-46: Potential false positive on equal timestamps.

The condition !now.Before(ev.When()) triggers an error when now >= ev.When(), which includes the case where two events have exactly the same timestamp. If events can legitimately share a timestamp (e.g., when created in rapid succession), this would cause a spurious test failure.

Consider using ev.When().Before(now) instead, which only errors if the event timestamp is strictly before the previous one:

-			if !now.Before(ev.When()) {
+			if ev.When().Before(now) {
 				t.Errorf("Events arrived out of order!")
 			}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2799c and 7116de1.

📒 Files selected for processing (7)
  • errors.go (2 hunks)
  • event_test.go (2 hunks)
  • focus.go (1 hunks)
  • interrupt.go (1 hunks)
  • key.go (2 hunks)
  • mouse.go (2 hunks)
  • resize.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
event_test.go (2)
event.go (2)
  • When (23-26)
  • when (30-32)
paste.go (2)
  • ev (69-71)
  • ev (32-34)
focus.go (1)
event.go (2)
  • EventTime (30-32)
  • e (45-47)
resize.go (1)
event.go (1)
  • EventTime (30-32)
key.go (1)
event.go (1)
  • EventTime (30-32)
interrupt.go (1)
event.go (1)
  • EventTime (30-32)
mouse.go (1)
event.go (1)
  • EventTime (30-32)
errors.go (1)
event.go (1)
  • EventTime (30-32)
🔇 Additional comments (12)
mouse.go (2)

33-39: LGTM on struct embedding.

The EventTime embedding correctly replaces the previous t time.Time field, allowing EventMouse to inherit the When() method from EventTime.


60-64: Clean constructor pattern.

The two-step initialization (create struct, then call SetEventNow()) is consistent with the pattern used across all event types in this PR.

focus.go (2)

19-24: Good fix: proper timestamp initialization.

The embedding of EventTime (by value, not pointer) aligns with the pattern used in other event types.


26-30: Fixes the missing time initialization for focus events.

This addresses the issue mentioned in the PR description where focus events previously lacked proper timestamp initialization.

errors.go (2)

43-46: Clean struct refactoring.

Embedding EventTime correctly replaces the previous t time.Time field and removes the need for a dedicated When() method.


54-58: Constructor follows the established pattern.

The two-step initialization is consistent with other event constructors in this PR.

interrupt.go (2)

19-22: Consistent struct refactoring.

EventInterrupt now properly embeds EventTime, matching the pattern across all event types.


30-34: LGTM on constructor.

Properly initializes timestamp via SetEventNow().

key.go (2)

46-51: Consistent struct embedding.

EventKey now embeds EventTime, aligning with the unified timestamp handling pattern.


302-305: Constructor properly timestamps after key processing.

The timestamp is set after all key normalization logic, which correctly reflects when the final event object is created.

resize.go (2)

18-21: Consistent struct embedding.

EventResize now embeds EventTime, completing the unified event timestamp pattern across all event types.


25-33: LGTM on constructor.

The initialization pattern matches all other event constructors in this PR.

@gdamore gdamore merged commit d93423d into main Dec 16, 2025
13 checks passed
@gdamore gdamore deleted the gdamore/event-time branch December 16, 2025 03:15
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