Skip to content

Commit 5d5326c

Browse files
committed
New Tab Bar Feature: Remove Tab on Mouse Middle Click
Removes a tab when middle-clicked. If the tab contains at least one dirty buffer, a prompt is shown. If the user cancels the prompt, they remain on the tab; otherwise, the previously active tab is restored.
1 parent b70df27 commit 5d5326c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

internal/action/tab.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,55 @@ func (t *TabList) HandleEvent(event tcell.Event) {
189189

190190
if i := t.LocFromVisual(buffer.Loc{mx, my}); i == -1 {
191191
t.List[t.Active()].CurPane().AddTab()
192+
} else {
193+
anyModified := false
194+
for _, p := range t.List[i].Panes {
195+
if bp, ok := p.(*BufPane); ok {
196+
if bp.Buf.Modified() {
197+
anyModified = true
198+
break
199+
}
200+
}
201+
}
202+
203+
removeTab := func() {
204+
panes := append([]Pane(nil), t.List[i].Panes...)
205+
for _, p := range panes {
206+
switch t := p.(type) {
207+
case *BufPane:
208+
t.ForceQuit()
209+
case *RawPane:
210+
t.Quit()
211+
case *TermPane:
212+
t.Quit()
213+
}
214+
}
215+
}
216+
217+
a := t.Active()
218+
if anyModified {
219+
t.SetActive(i)
220+
InfoBar.YNPrompt("Discard unsaved changes? (y,n,esc)", func(yes, canceled bool) {
221+
if !canceled {
222+
if yes {
223+
removeTab()
224+
if i <= a {
225+
a--
226+
}
227+
}
228+
t.SetActive(a)
229+
}
230+
})
231+
t.release = true
232+
t.tbClick = false
233+
t.tabDrag = false
234+
} else {
235+
removeTab()
236+
if i <= a {
237+
t.SetActive(a - 1)
238+
}
239+
}
240+
return
192241
}
193242
case tcell.WheelUp:
194243
t.Scroll(4)

0 commit comments

Comments
 (0)