aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2020-03-02 19:54:42 +0000
committerReto Brunner <reto@labrat.space>2020-03-03 20:08:29 +0100
commit68f179021d304d6edf939ecf5fc7d0d073b16152 (patch)
tree0ba86642579bfc7fa87ce38473ce234208277336 /lib/ui
parent2e381fa42d64442262335101fe3b7bf76ab50b92 (diff)
downloadaerc-68f179021d304d6edf939ecf5fc7d0d073b16152.tar.gz
Add move-tab command
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/tab.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 27fb6040..e1c53ea7 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -132,6 +132,47 @@ func (tabs *Tabs) SelectPrevious() bool {
return true
}
+func (tabs *Tabs) MoveTab(to int) {
+ from := tabs.Selected
+
+ if to < 0 {
+ to = 0
+ }
+
+ if to >= len(tabs.Tabs) {
+ to = len(tabs.Tabs) - 1
+ }
+
+ tab := tabs.Tabs[from]
+ if to > from {
+ copy(tabs.Tabs[from:to], tabs.Tabs[from+1:to+1])
+ for i, h := range tabs.history {
+ if h == from {
+ tabs.history[i] = to
+ }
+ if h > from && h <= to {
+ tabs.history[i] -= 1
+ }
+ }
+ } else if from > to {
+ copy(tabs.Tabs[to+1:from+1], tabs.Tabs[to:from])
+ for i, h := range tabs.history {
+ if h == from {
+ tabs.history[i] = to
+ }
+ if h >= to && h < from {
+ tabs.history[i] += 1
+ }
+ }
+ } else {
+ return
+ }
+
+ tabs.Tabs[to] = tab
+ tabs.Selected = to
+ tabs.TabStrip.Invalidate()
+}
+
func (tabs *Tabs) NextTab() {
next := tabs.Selected + 1
if next >= len(tabs.Tabs) {