refactor(input,ui): track input mode per tab instead of globally#62
Merged
Conversation
Move the InputMode field from AppState onto TabState so each tab keeps its own Insert/Normal/Visual/Search mode; switching tabs restores that tab's mode. Access is routed through panic-free mode()/set_mode() accessors, and the global search_matches are cleared/recomputed on tab switch. Mode stays session-only and is never persisted.
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
Moves the
InputModefield from the globalAppStateonto per-tabTabState, so each tab keeps its own Insert/Normal/Visual/Search mode. Switching tabs now restores that tab's own mode instead of sharing one mode across the whole window — matching howzoomedandpassthroughare already handled (per-tab, session-only, never persisted).Changes
modefield moved fromAppStatetoTabState; initialized toInsertat all threeTabStateconstruction sites (new_tab, session restore,add_empty_tab).mode() -> &InputModeandset_mode(m)accessors that delegate to the active tab, with astatic DEFAULT_MODE = Insertfallback for the empty-tabs case.do_set_moderefactored to compute the resolved mode into a local before taking&mut self, avoiding a double borrow.on_active_tab_changed()to clear/recompute the globalsearch_matches(which describe only the active tab's grid) onnext_tab/prev_tab/do_go_to_tab.app_event,app_state,mouse_ops,input_ops,render_ops, andviews.Invariant
Mode stays session-only and is never serialized —
src/session/mod.rshas zeromodereferences.How to test
cargo runand open a second tab (Ctrl+T).Ctrl+[/ your normal-mode binding) — the mode badge shows NORMAL.Ctrl+PageDown/Ctrl+Tab) — the badge shows INSERT (tab 2 keeps its own mode)./) in one tab and switch tabs — no stale match highlight appears on the other tab (search_matchesare cleared/recomputed on switch).Automated coverage:
cargo test— new per-tab isolation tests assert that a new tab starts in Insert, mode is tracked per tab across switches, Visual does not leak between tabs, andsearch_matchesare cleared on tab switch.Checks
cargo fmt --checkclean;cargo clippy --locked -- -D warningsclean.