Skip to content

fix: replace the active tab when opening a file from the tree - #56

Merged
leboiko merged 9 commits into
leboiko:masterfrom
Moler1995:fix/tree-open-replaces-active-tab
Nov 23, 2026
Merged

leboiko merged 9 commits into
leboiko:masterfrom
Moler1995:fix/tree-open-replaces-active-tab

Conversation

@Moler1995

Copy link
Copy Markdown

Summary

Opening a file from the tree (Enter, l, or a mouse click) silently did nothing
when that file was not already open in a tab: the tree cursor moved and focus
switched to the viewer, but the document on screen stayed the previous one — so
the file tree appeared to have stopped switching files.

Tabs::open_or_focus answers OpenOutcome::Replaced for that case and hands
back the active tab without rewriting its current_path, while
apply_file_loaded looks the receiving tab up by path. It therefore found no
match and dropped the content it had just read from the background reader. Only
files that were already open (OpenOutcome::Focused) switched correctly, which
is why this was easy to miss — a restored session that already has the file in a
tab behaves fine.

Changes

  • src/app/file_ops.rs — apply_file_loaded falls back to the active tab when
    the path-keyed lookup misses and the load is a replacement
    (new_tab == false); for a replacement the tab open_or_focus handed back
    is the target. new_tab is no longer _new_tab.
  • src/app/tests.rs — new regression test
    opening_other_file_replaces_active_tab_content, driving the same sequence
    (open_or_focus(second, false, None) followed by Action::FileLoaded) and
    asserting the tab's current_path, content and label.
  • CHANGELOG.md — entry under [Unreleased] / Fixed.

Test Plan

  • cargo test --workspace on Linux (x86_64-unknown-linux-gnu): all test
    binaries pass, 0 failures (536 in markdown-tui-explorer, 853 in
    mermaid-text, plus the integration binaries).

  • The checks from CONTRIBUTING.md all pass on the same host: cargo fmt --all,
    cargo clippy --all-targets --all-features -- -D warnings, and
    cargo test --all-targets (also 0 failures). No README change: it already
    documents Enter / l / Right as "Open file (current tab)", which is
    exactly the behaviour this restores.

  • The new test fails against the pre-fix apply_file_loaded
    (left: Some("/fake/test.md"), right: Some("/fake/other.md")), i.e. it covers
    the bug rather than the fix.

  • Exercised by hand in the TUI on Windows Terminal: opened a two-file directory,
    selected the second file in the tree and pressed Enter — the active tab
    switched to it, confirmed on screen and by the session the app writes on quit
    (state.toml records the tab's new path). No macOS machine available; the
    change contains no cfg(target_os) branches, so the code path is shared, but
    it has not been run on macOS.

  • Existing tests pass (cargo test --workspace)

  • New tests added where appropriate

  • Manually tested on macOS / Linux (specify which) — manual run was on
    Windows; on Linux only the test suite was run

  • If a Mermaid block changed, verified rendering in TUI and via
    mermaid-text CLI — N/A, no Mermaid code touched

Checklist

  • CHANGELOG.md entry added (root for markdown-tui-explorer, crate-local
    for mermaid-text)
  • No new clippy warnings (cargo clippy --all-targets -- -D warnings)
  • Documentation updated if public API changed — N/A, no public API change
  • Version bumped in Cargo.toml if user-visible — left to a release:
    commit, matching how the other [Unreleased] fixes are handled

Linked Issue

Closes #

ykzird and others added 3 commits September 21, 2026 20:15
Gruvbox warmth on a blue-grey surface, with a dusty-mauve accent, matching
the AETHER / G.A.I.A v2 desktop theme.

Three slots deviate from the source palette because its literal values fail
the crate's own contrast audit: accent.primary uses the source magenta
(#c98fa0) since no foreground reaches AA on #a0607a, state.selection_bg is
a lightened selection (#503a4a) to clear MIN_SELECTION_DELTA, and
state.focus is the magenta accent at 6.45:1 on the base surface.
`Tabs::open_or_focus` answers `Replaced` for a tree-driven open of a file
that is not already open, and hands back the active tab without rewriting
its `current_path`.  `apply_file_loaded` looks the receiving tab up by
path, so it found no match and dropped the content it had just read: the
tree cursor moved and focus switched to the viewer, but the previous
document stayed on screen, which reads as the file tree no longer
switching files.

Fall back to the active tab for replacements, and cover it with a test
that fails without the fallback.

Co-Authored-By: Claude Code <[email protected]>

@leboiko leboiko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking correctness finding in src/app/file_ops.rs:249: a replacement load writes into the tab active at completion, which can differ from its original target. Reproduced with a regression test: request B in tab A, open tab C, then deliver FileLoaded(B); C changes from /fake/third.md to /fake/other.md. Rapid replacement requests and closed targets also need coverage. I am building on your commits to preserve request ownership and test these cases before merge.

@leboiko

leboiko commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Reviewed and corrected in 00cf5e4, preserving the contributor commits and credit.

Finding Status
Delayed replacement overwrites another active tab Fixed with per-tab request ownership; failing reproduction now passes
Older completion overwrites latest selection / closed target Fixed and regression tested
Failed reads, empty files, focus retention Covered by exact path/content/focus assertions
Changelog conflict Resolved; includes reviewed #49 changes

Local validation passed: rustfmt, workspace/all-target Clippy, full workspace tests on stable and Rust 1.92, docs, cargo-deny and cargo-audit. Existing documentation warnings and six nonblocking audit warnings remain. A source-jump regression in the initial correction was caught by the existing harness and fixed without weakening that test. Detailed red-team review is committed in PR-56-review.md. No unresolved merge-blocking code findings; waiting for remote checks.

@leboiko leboiko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed corrected head 00cf5e4. The wrong-tab and stale-completion regressions are fixed, original contributor regression retained, and all local gates plus all 12 GitHub checks pass. Linux/macOS Nix builds and binary smoke tests pass. No unresolved merge-blocking findings; details in PR-56-review.md.

@leboiko
leboiko merged commit e1168e1 into leboiko:master Nov 23, 2026
12 checks passed
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.

3 participants