Skip to content

fix(event-log): preserve RichTextLabel scroll across event_rev bumps - #382

Merged
joryirving merged 1 commit into
mainfrom
foreman/wl-misospace-windowstead-380/issue-380
Sep 9, 2026
Merged

fix(event-log): preserve RichTextLabel scroll across event_rev bumps#382
joryirving merged 1 commit into
mainfrom
foreman/wl-misospace-windowstead-380/issue-380

Conversation

@itsmiso-ai

Copy link
Copy Markdown
Contributor

Preserve RichTextLabel scroll position in the event log by capturing the VScrollBar value before rebuilding the text.

Fixes #380

Opened by foreman on review GO (workload wl-misospace-windowstead-380).

_render_event_log wiped the sidebar event log with clear() and rebuilt it
via append_text() on every event_rev bump, resetting the player's scroll
position so a new event (build finishing, worker break, ambient event,
recruit click) snapped an already-scrolling log back to the top.

Capture the v-scroll bar value before clear() and write it back after the
append. The restore is deferred to the next idle frame: with scroll-following
on, the layout pass that follows the rebuild snaps the bar back to the newest
line, so the value must be re-applied after that pass.

Add tests/test_event_log_scroll.gd, a regression test that drives the real
_render_event_log() against a scene-free main.gd with a real RichTextLabel and
asserts the scroll position survives an event_rev bump. It fails without the
fix (scroll snaps to the newest line) and passes with it.

Fixes #380

Signed-off-by: Saffron <263493777+itsmiso-ai@users.noreply.github.com>

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Automated Review

Full PR review.

Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — primary route

Recommendation: Approve

This PR correctly fixes issue PR 380 with a minimal, targeted change.

Change-by-Change Findings

scripts/main.gd — Scroll preservation in _render_event_log

The fix captures VScrollBar.value before clear() and restores it via call_deferred("set_value", saved_scroll) after rebuilding the log. The deferred restore is necessary because with scroll_following on, the layout pass that follows append_text would snap the bar back to the newest line — the value must be applied after that pass.

  • The null-check guard on scroll_bar != null is defensive and correct.
  • The inline comment explains the deferred restore rationale clearly.
  • No side effects; the event_rev cache gate remains intact.

tests/test_event_log_scroll.gd — New regression suite

Three test cases cover the acceptance criteria from issue PR 380:

  1. test_scroll_survives_event_rev_bump — single bump, scroll held at arbitrary target, also asserts the event list is bounded at MAX_EVENT_LOG (20) and newest entry is first.
  2. test_scroll_preserved_across_multiple_bumps — five rapid bumps in a loop, scroll preserved throughout.
  3. test_idle_render_does_not_touch_scroll — confirms early-return path (no event_rev change) never touches the scroll bar.

All assert_eq calls use the required three-argument form (actual, expected, name), matching the AGENTS.md testing trap warning.

Standards Compliance

No issues. The fix:

  • Touches only scripts/main.gd as specified in the issue's expected files.
  • Uses the new test file approach suggested by the issue.
  • Follows GDScript conventions consistent with the surrounding codebase.
  • Passes all CI checks (Linux, macOS, Windows export validation, headless smoke test, script test suite).

Linked Issue Fit

Issue PR 380 asked for preserving RichTextLabel scroll position across event_rev bumps. The PR implements the second acceptance criterion exactly: it reads get_v_scroll_bar().value before clear() and writes it back after append_text. The deferred restore is necessary to avoid the scroll_following layout-pass snap-back described in both the test comments and the issue evidence. Regression test coverage is added as required.

Tool Harness Findings

No tool harness output present in the corpus; reviewing the diff directly.

Unknowns / Needs Verification

None. The fix is self-contained, CI passes, and the test suite exercises the exact scenario from the issue.

@joryirving
joryirving merged commit b497842 into main Sep 9, 2026
8 checks passed
@joryirving
joryirving deleted the foreman/wl-misospace-windowstead-380/issue-380 branch September 9, 2026 02:43
@its-saffron its-saffron Bot mentioned this pull request Sep 9, 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.

[P2] Event-log RichTextLabel snaps back to top on every event_rev bump

2 participants