Skip to content

Commit b4343e5

Browse files
committed
fix: make Ctrl+W context-aware to preserve word deletion in editor
When the editor is focused, Ctrl+W now passes through for standard word deletion instead of closing the tab. A new SetCloseTabEnabled method on TabBar toggles the binding based on focus state before forwarding keys, keeping the logic encapsulated within the tab bar component. Fixes #1771 Assisted-By: docker-agent
1 parent f96edc1 commit b4343e5

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/tui/components/tabbar/tabbar.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ func New(maxTitleLen int) *TabBar {
146146
}
147147
}
148148

149+
// SetCloseTabEnabled enables or disables the close-tab key binding.
150+
// When disabled, Ctrl+W passes through to the editor for word deletion.
151+
func (t *TabBar) SetCloseTabEnabled(v bool) {
152+
t.keyMap.CloseTab.SetEnabled(v)
153+
}
154+
149155
// SetWidth sets the available width for the tab bar.
150156
func (t *TabBar) SetWidth(width int) {
151157
t.width = width

pkg/tui/tui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,10 @@ func (m *appModel) handleKeyPress(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
17751775

17761776
// Tab bar keys (Ctrl+t, Ctrl+p, Ctrl+n, Ctrl+w) are suppressed during
17771777
// history search so that ctrl+n/ctrl+p cycle through matches instead.
1778+
// Ctrl+w (close tab) is disabled when the editor is focused so that the
1779+
// standard "delete word" shortcut works while typing.
17781780
if !m.leanMode && !m.editor.IsHistorySearchActive() {
1781+
m.tabBar.SetCloseTabEnabled(m.focusedPanel != PanelEditor)
17791782
if cmd := m.tabBar.Update(msg); cmd != nil {
17801783
return m, cmd
17811784
}

0 commit comments

Comments
 (0)