summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/tab.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index c39e327..2ab703a 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -10,6 +10,7 @@ type Tabs struct {
 	TabStrip   *TabStrip
 	TabContent *TabContent
 	Selected   int
+	history    []int
 
 	onInvalidateStrip   func(d Drawable)
 	onInvalidateContent func(d Drawable)
@@ -28,6 +29,7 @@ func NewTabs() *Tabs {
 	tabs := &Tabs{}
 	tabs.TabStrip = (*TabStrip)(tabs)
 	tabs.TabContent = (*TabContent)(tabs)
+	tabs.history = []int{0}
 	return tabs
 }
 
@@ -58,13 +60,11 @@ func (tabs *Tabs) Remove(content Drawable) {
 	for i, tab := range tabs.Tabs {
 		if tab.Content == content {
 			tabs.Tabs = append(tabs.Tabs[:i], tabs.Tabs[i+1:]...)
+			tabs.removeHistory(i)
 			break
 		}
 	}
-	/* Force the selected index into the existing range */
-	if tabs.Selected >= len(tabs.Tabs) {
-		tabs.Select(tabs.Selected - 1)
-	}
+	tabs.Select(tabs.popHistory())
 	tabs.TabStrip.Invalidate()
 }
 
@@ -75,11 +75,41 @@ func (tabs *Tabs) Select(index int) {
 
 	if tabs.Selected != index {
 		tabs.Selected = index
+		tabs.pushHistory(index)
 		tabs.TabStrip.Invalidate()
 		tabs.TabContent.Invalidate()
 	}
 }
 
+func (tabs *Tabs) pushHistory(index int) {
+	tabs.history = append(tabs.history, index)
+}
+
+func (tabs *Tabs) popHistory() int {
+	lastIdx := len(tabs.history) - 1
+	item := tabs.history[lastIdx]
+	tabs.history = tabs.history[:lastIdx]
+	return item
+}
+
+func (tabs *Tabs) removeHistory(index int) {
+	newHist := make([]int, 0, len(tabs.history))
+	for i, item := range tabs.history {
+		if item == index {
+			continue
+		}
+		if item > index {
+			item = item - 1
+		}
+		// dedup
+		if i > 0 && item == newHist[len(newHist)-1] {
+			continue
+		}
+		newHist = append(newHist, item)
+	}
+	tabs.history = newHist
+}
+
 // TODO: Color repository
 func (strip *TabStrip) Draw(ctx *Context) {
 	x := 0
&id=58bc15b4727c034f9ce656f7774d68ec2e7a3f55'>58bc15b ^
58a0f43 ^
58bc15b ^


58a0f43 ^
58bc15b ^

58a0f43 ^
58bc15b ^









062f00e ^
c295508 ^


58bc15b ^



c4c8648 ^


58bc15b ^



















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157