Skip to content

fix(auto): make :MdRender auto a true toggle by swapping back to source on off#18

Merged
delphinus merged 1 commit into
mainfrom
fix/auto-off-restore-source
May 16, 2026
Merged

fix(auto): make :MdRender auto a true toggle by swapping back to source on off#18
delphinus merged 1 commit into
mainfrom
fix/auto-off-restore-source

Conversation

@delphinus
Copy link
Copy Markdown
Owner

Summary

  • :MdRender auto (= auto_toggle) now returns to the pre-toggle state when called twice.
  • MdPreview.auto_off swaps the current window back to source when it's showing this buffer's render view, in addition to clearing b:md_render_auto / autocmds / Insert-entry keymaps.
  • Documented behavior in :help :MdRender-auto and :help MdPreview.auto_off() updated to match.

Why

The previous auto_off was deliberately documented as "leaves the displayed mode untouched". That made :MdRender auto (toggle) asymmetric: source → render on the first call, but render stays render on the second call (only the autocmd is gone). Users reasonably expected a toggle to be reversible. Since auto mode is still marked [EXPERIMENTAL], tightening the contract to be symmetric is preferable to keeping the surprise.

auto_toggle itself is unchanged; it inherits the fix from auto_off.

Test plan

  • make test — all 525 tests pass (toggle_test grew from 147 → 149).
  • New tests cover:
    • auto_off swaps render back to source (Test 18, rewritten).
    • Two auto_toggle calls return to the original (source, auto-off) state (Test 18b).
    • auto_off is a no-op for display when the current window is already showing source (Test 18c).

🤖 Generated with Claude Code

`:MdRender auto` is `auto_toggle` in disguise, so calling it twice
should return to the pre-toggle state. Previously `auto_off` only tore
down the autocmd / keymaps / b: marker but left the render buffer on
screen, so two `:MdRender auto` invocations ended up with auto OFF
plus render still displayed — surprising for a toggle.

Make `auto_off` also call `MdPreview.toggle()` when the current window
is showing this buffer's render view. `auto_toggle` inherits the fix
without further change. Update :help and tests accordingly.
@delphinus delphinus merged commit cd751c9 into main May 16, 2026
4 checks passed
@delphinus delphinus deleted the fix/auto-off-restore-source branch May 16, 2026 02:17
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.

1 participant