Skip to content

fix: defer BufDelete handler to ignore buflisted changes from scope-nvim#14

Merged
ttak0422 merged 1 commit intomainfrom
fix/terminal-disappears-on-tab-switch
Mar 11, 2026
Merged

fix: defer BufDelete handler to ignore buflisted changes from scope-nvim#14
ttak0422 merged 1 commit intomainfrom
fix/terminal-disappears-on-tab-switch

Conversation

@ttak0422
Copy link
Copy Markdown
Owner

@ttak0422 ttak0422 commented Mar 11, 2026

Summary

  • 原因: scope-nvim がタブ切り替え時に buflisted=false を設定 → BufDelete 発火 → pterm の M.detach() が bridge を kill → ターミナル消滅
  • 修正: BufDelete コールバックを vim.schedule で遅延させ、バッファが valid かつ loaded なら(単なる unlisting)detach をスキップ。真の削除(:bdelete/:bwipeout)時のみ detach を実行

Root cause

scope-nvim scopes buffers per tab page by toggling buflisted on TabLeave/TabEnter. Setting buflisted=false fires BufDelete, which pterm interpreted as true buffer deletion — calling M.detach(), killing the bridge (SIGHUP exit code 129), and wiping the buffer.

Built-in :terminal is unaffected because it has no BufDelete autocmd handler.

Test plan

  • :Pterm:tabnew:tabprev でターミナルが正しく表示されることを確認
  • :Pterm:bdelete! でバッファが正しく削除・detach されることを確認
  • :Pterm → シェルで exit:bdelete で正しくクリーンアップされることを確認

🤖 Generated with Claude Code

scope-nvim scopes buffers per tab page by toggling buflisted on
TabLeave/TabEnter. Setting buflisted=false fires BufDelete, which
pterm's handler interpreted as a true buffer deletion—calling
M.detach(), killing the bridge (SIGHUP/129), and wiping the buffer.

Defer the BufDelete callback with vim.schedule and check whether the
buffer is still valid and loaded. A merely-unlisted buffer survives
the check and the connection is preserved; a truly deleted buffer
triggers detach as before.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ttak0422 ttak0422 merged commit 922b086 into main Mar 11, 2026
2 checks passed
@ttak0422 ttak0422 deleted the fix/terminal-disappears-on-tab-switch branch March 11, 2026 16:57
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