aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordelitako <delitako@delitako.xyz>2024-01-25 22:50:14 -0600
committerRobin Jarry <robin@jarry.cc>2024-01-26 20:27:08 +0100
commit936d519a67301bd78a4d737dc47234e3769e639f (patch)
tree701dc21c0551d4f020cb1c339ba0270c1525c2a7 /lib
parent58585e0a8e264f7a5500b3f24b0b319d59f36882 (diff)
downloadaerc-936d519a67301bd78a4d737dc47234e3769e639f.tar.gz
tabs: optimize switching by offsets
I imagine no sane user requires aerc to correctly handle commands like `:next-tab 1000000000`, but I tried anyway and it froze aerc while also eating up many GBs of system memory. This behavior is not ideal, so I improved it. This commit adds functions for selecting a tab at an offset from the currently-selected tab and changes the next-tab, prev-tab, and change-tab commands to use these functions instead of looping. Signed-off-by: delitako <delitako@delitako.xyz> Tested-by: Thomas Böhler <witcher@wiredspace.de> Reviewed-by: Thomas Böhler <witcher@wiredspace.de> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/tab.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 43b6e14f..f5e89064 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -209,6 +209,18 @@ func (tabs *Tabs) SelectPrevious() bool {
return tabs.selectPriv(index)
}
+func (tabs *Tabs) SelectOffset(offset int) {
+ tabs.m.Lock()
+ tabCount := len(tabs.tabs)
+ newIndex := (tabs.curIndex + offset) % tabCount
+ if newIndex < 0 {
+ // Handle negative offsets correctly
+ newIndex += tabCount
+ }
+ tabs.selectPriv(newIndex)
+ tabs.m.Unlock()
+}
+
func (tabs *Tabs) MoveTab(to int, relative bool) {
tabs.m.Lock()
tabs.moveTabPriv(to, relative)