fix: reset widget state when terminal ID changes (multi-terminal resize)#70
Merged
Harzu merged 2 commits intoHarzu:masterfrom Apr 3, 2026
Merged
Conversation
When Iced's Tree reconciliation recycles TerminalViewState for a different terminal (e.g., tab switching in a multi-tab app), the cached layout size prevents the resize check from firing. The new terminal's PTY stays at ~10 columns instead of resizing to match the actual widget dimensions. Fix: track terminal_id in TerminalViewState. When the state is reused for a different terminal, reset size to zero to force resize. Closes Harzu#67
Contributor
Author
Reproduction VideoBefore fix (iced_term 0.8.0 from crates.io)Tab 1 works, Tab 2+ has wrong column count (~10 instead of 80: Screen.Recording.2026-03-31.at.15.12.27.movAfter fix (this PR)All tabs resize correctly: Screen.Recording.2026-03-31.at.15.14.51.mov@Harzu here are the reproduction videos showing the bug and the fix. |
Harzu
reviewed
Apr 3, 2026
Address PR review feedback from @Harzu: - Move terminal ID check from handle_resize() to Widget::diff() - Change terminal_id from Option<u64> to u64 - Initialize terminal_id in state() via TerminalViewState::new(id) - Remove Default impl for TerminalViewState Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
Author
|
@Harzu Thanks for the review! I've addressed all your feedback in d9b343f:
Ready for another look when you get a chance! |
Harzu
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #67 — when using multiple terminal instances with tab switching or
pane_grid, non-first terminals render with wrong column count (~10 instead of 80+).Root Cause
TerminalViewState.sizepersists across different terminals due to Iced's Tree reconciliation (diff()). When switching from Terminal A to Terminal B in the same widget position, the state from A (withsizealready set to the correct layout dimensions) is reused for B. The resize checkstate.size != layout_sizeevaluates tofalse, soCommand::Resizeis never published for the new terminal.Changes
Only
src/view.rs— 9 lines added, 0 removed:terminal_id: Option<u64>field toTerminalViewStatehandle_resize(), detect when the state is recycled for a different terminal and resetsizeto(0, 0)to force the resize check to fireHow to Reproduce
pane_gridwith multipleTerminalinstances (tab switching)After this fix, all terminals resize correctly when switching.
Test Plan
cargo checkpasses