Skip to content

Preserve point and window-start across streaming rerenders#566

Open
Gleek wants to merge 1 commit into
xenodium:mainfrom
Gleek:preserve-point-streaming
Open

Preserve point and window-start across streaming rerenders#566
Gleek wants to merge 1 commit into
xenodium:mainfrom
Gleek:preserve-point-streaming

Conversation

@Gleek
Copy link
Copy Markdown
Contributor

@Gleek Gleek commented May 3, 2026

Hello Alvaro,

This solves a bug where the point jumps to the top of the block that is currently rendering, if it's placed inside it.

Root cause

Each streaming chunk delete-and-reinserts the in-progress block, which displaces any markers inside that region to its start. (point-marker) in the viewport branch and save-mark-and-excursion/save-excursion (in agent-shell-ui-update-fragment and shell-maker-with-auto-scroll-edit) all rely on markers, so cursor and viewport jumped to the block header when reading mid-stream.

Fix

Switch to integer-based save/restore for point and window-start: inside agent-shell-ui-update-fragment (covers the viewport flow) and around shell-maker-with-auto-scroll-edit in the main shell branch (overrides shell-maker's broken save-excursion).

Fixes #454
Also related (though different issue) is the #552

Please view the change with ?w=1 (link). The change is not as big as the UI makes it to appear

Checklist

  • I agree to communicate (PR description and comments) with the author myself (not AI-generated).
  • I've reviewed all code in PR myself and will vouch for its quality.
  • I've read and followed the Contributing guidelines.
  • I've filed a feature request/discussion for a new feature.
  • I'm making visual changes, so I'm including screenshots so you can view and discuss.
  • I've added tests where applicable.
  • I've updated documentation where necessary.
  • I've run M-x checkdoc and M-x byte-compile-file.

@xenodium
Copy link
Copy Markdown
Owner

xenodium commented May 7, 2026

Thank you for the PR.

I've tried the patch briefly and ran into issues with point placed in unexpected places in viewport buffer when multiple permission dialogs came through. It could be unrelated. Will have to have another play with it later on.

ps. IIRC, the previous implementation remembered region too?

Each streaming chunk delete-and-reinserts the in-progress block, which
displaces any markers inside that region to its start. `(point-marker)`
in the viewport branch and `save-mark-and-excursion`/`save-excursion`
(in `agent-shell-ui-update-fragment` and `shell-maker-with-auto-scroll-edit`)
all rely on markers, so cursor and viewport jumped to the block header
when reading mid-stream.

Switch to integer-based save/restore for point and window-start: inside
`agent-shell-ui-update-fragment` (covers the viewport flow) and around
`shell-maker-with-auto-scroll-edit` in the main shell branch (overrides
shell-maker's broken `save-excursion`).
@Gleek Gleek force-pushed the preserve-point-streaming branch from 2f9490e to 7832e7d Compare May 12, 2026 04:26
@Gleek
Copy link
Copy Markdown
Contributor Author

Gleek commented May 12, 2026

Thanks for trying it out.

Good point on region. I’d missed that save-mark-and-excursion also preserved mark state outside the rerendered block. I’ve amended the PR to preserve mark / mark-active using integer positions too.

One caveat: for a region inside the block being delete/reinserted, this is still positional rather than semantic. It restores the same offsets after rerender, not necessarily the same logical text if the replacement changes substantially. But it avoids the marker displacement to the block start, which was the original issue.

On the viewport permission-dialog issue: I couldn’t spot a direct cause in this patch. Permission dialogs still explicitly jump to the latest permission button after rendering, including in the viewport buffer. Happy to look more if you find a reproducible case.

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.

When "Thinking" output is streaming, point constantly jumps up to top of section

2 participants