feat(ui): preserve buffers on toggle#229
Conversation
cf1203c to
6ab8fd6
Compare
|
great addition! this is so useful, imo it would make for a sensible default. there is still |
|
This sems like a useful feature. As I will have to maintain this in the future, I would like it if you add a couple of tests for this. As well as updating the README file Thanks a lot for the PR |
|
Sorry, I found some more subtle issues. I'm glad you reviewed so carefully, including that it should probably be the default behavior. I will resolve all the above issues as soon as possible. |
Add `persist_state` configuration option (default: true) that preserves buffers and cursor positions when toggling the UI off. This enables faster restore and maintains scroll position across toggle operations.
6ab8fd6 to
ec6711e
Compare
|
I am quite satisfied with my local behavior, (my nvim configuration will switch when the position is both left and center, plus I want to retain the cursor position when toggling, so although the code is relatively complex, I also spent quite a while calibrating through actual testing. I might record a video hhh) The overall code writing and cleanup were all done by kimi2.5. There may be some unnecessary comments or still overdesigned parts here. I will carefully review my PR tomorrow and clean up that junk (it's late night here now, I have to sleep). I pushed the code up first in case someone might want to try it out early. @sudo-tee @disrupted update : iShot_2026-02-06_14.55.30.mp4 |
|
at 0:13 in the video it looks like the cursor jumped up a little when re-opening the output buffer. do you know why that's happening? |
|
Thanks for the PR, I will play with it a little bit in the coming days as welle a redo a finale review. |
When the cursor bounces back from the editing window to the opencode output window, if it wasn't at the bottom before (for example, if I was looking at messages in the middle), I want it to reappear at the corresponding position. Actually, it's not just the cursor jumping up; it seems to be one of my autojump commands that centers the entire window, although it does create a bit of visual noise. |
Background
This PR improves UI toggle behavior by introducing
ui.persist_state(default:true) and refining window and buffer lifecycle handling.Goal: when toggling UI off and on, preserve user context (buffers and cursor or scroll intent) without breaking close semantics.
Behavior Changes
Add
ui.persist_state(defaulttrue):togglenow hides windows and preserves buffers when enabled.Normalize window state semantics:
visible: input or output window is currently visiblehidden: windows are closed but restorable hidden buffers existclosed: no visible windows and no restorable hidden buffersFix toggle open-state detection:
visible(notclosed).Make
get_window_state()read-only:Restore policy after hidden reopen:
Explicit hidden-buffer lifecycle:
Type and LSP cleanup:
gdnavigation targeting real implementations.Test Coverage
Added and updated behavior-focused tests:
tests/unit/persist_state_spec.luaget_window_state()purity (no mutation)persist_state=falsefull-close pathtests/unit/core_spec.luaReviewer Guide
Suggested review order:
lua/opencode/state.lua: state model plus hidden snapshot lifecyclelua/opencode/ui/ui.lua: close and create window lifecycle splitlua/opencode/core.lua: reopen render gating behaviorlua/opencode/api.lua: toggle semantics plus getter purityRisks / Compatibility
persist_state=true).persist_state=false.visible/hidden/closed), covered by regression tests above.