Skip to content

feat(tui): expose scrollToMessage to TUI plugins - #46047

Closed
settingzbot wants to merge 2 commits into
anomalyco:devfrom
settingzbot:tui-plugin-scroll-to-message
Closed

settingzbot wants to merge 2 commits into
anomalyco:devfrom
settingzbot:tui-plugin-scroll-to-message

Conversation

@settingzbot

Copy link
Copy Markdown

Issue for this PR

Related: #37699 (scrollbar message-boundary markers). No separate issue was filed for this; the motivation is the same "find an earlier message in a long session" problem.

Type of change

  • New feature

What does this PR do?

Adds scrollToMessage(messageID) to the TUI plugin state API, letting a plugin scroll the session chat viewport to a specific message.

There was previously no way for a plugin to do this: the session scrollbox is a module-local ScrollBoxRenderable inside the Session route, and the only built-in way to jump to a message is the ctrl+x g timeline dialog. This PR:

  • adds a small sessionScroll controller (packages/tui/src/util/session-scroll.ts) that holds the currently displayed session's scrollbox,
  • attaches/detaches it from the Session route, mirroring the existing toBottom setTimeout-deferred pattern so the ref is assigned before attach,
  • exposes it on the plugin state API as scrollToMessage(messageID): boolean (returns false when no session is attached),
  • factors the four existing "find child by id, then scrollBy(child.y - scroll.y - 1)" blocks into one shared scrollToMessageID helper in util/scroll.ts.

The plugin-facing types (packages/plugin/src/tui.ts) and the test fixture (packages/opencode/test/fixture/tui-plugin.ts) are updated, and the method is documented in specs/tui-plugins.md.

How did you verify your code works?

  • bun run typecheck passes (30/30 tasks).
  • oxlint clean on the changed files.
  • Ran bun dev and confirmed through a temporary home_bottom probe that typeof api.state.scrollToMessage === "function".
  • Built a small TUI plugin that registers a sidebar_content slot listing user messages and calls scrollToMessage on hover/click; confirmed the sidebar renders and the method is callable.

I did not verify the resulting scroll position pixel-perfectly beyond the above (headless terminal); the scroll math is unchanged from the existing timeline/fork call sites, which now share the same helper.

Screenshots / recordings

None — terminal UI change, not meaningful as a static screenshot.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@a-r-m-i-n

Copy link
Copy Markdown

This would unlock a sidebar timeline/table-of-contents plugin: list user prompts in sidebar_content and jump directly to the selected message.

The current plugin API already exposes session messages and parts, but without scrollToMessage(messageID) a plugin cannot reproduce the built-in /timeline navigation. This is a small, focused API addition with a clear practical use case.

I would very much appreciate merging this.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@englishisnotenglish

Copy link
Copy Markdown

+111111111111111111111111111111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants