about summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-19 18:12:57 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-23 10:27:59 -0400
commite42b95a617399b2736df96ae6469309e6b306d71 (patch)
tree65bd6f78faa0607a3d73a35b7c59a713472adbea /lib/ui
parentd526786c9358bc92a5ffc3233e0ba4491aff07ba (diff)
downloadaerc-e42b95a617399b2736df96ae6469309e6b306d71.tar.gz
Add change tab command
This command allows the user to change tab by giving the tab name. This
can be tab completed too. The previous tab is stored in the tabs module
so that when a new tab is created it is still possible to go to the
previous one.

Normal invocation is :ct folder
Previous tab is :ct -
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/tab.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 0061472..7808db4 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -29,7 +29,7 @@ func NewTabs() *Tabs {
 	tabs := &Tabs{}
 	tabs.TabStrip = (*TabStrip)(tabs)
 	tabs.TabContent = (*TabContent)(tabs)
-	tabs.history = []int{0}
+	tabs.history = []int{}
 	return tabs
 }
 
@@ -64,7 +64,10 @@ func (tabs *Tabs) Remove(content Drawable) {
 			break
 		}
 	}
-	tabs.Select(tabs.popHistory())
+	index, ok := tabs.popHistory()
+	if ok {
+		tabs.Select(index)
+	}
 	tabs.TabStrip.Invalidate()
 }
 
@@ -90,22 +93,34 @@ func (tabs *Tabs) Select(index int) {
 	}
 
 	if tabs.Selected != index {
+		tabs.pushHistory(tabs.Selected)
 		tabs.Selected = index
-		tabs.pushHistory(index)
 		tabs.TabStrip.Invalidate()
 		tabs.TabContent.Invalidate()
 	}
 }
 
+func (tabs *Tabs) SelectPrevious() bool {
+	index, ok := tabs.popHistory()
+	if !ok {
+		return false
+	}
+	tabs.Select(index)
+	return true
+}
+
 func (tabs *Tabs) pushHistory(index int) {
 	tabs.history = append(tabs.history, index)
 }
 
-func (tabs *Tabs) popHistory() int {
+func (tabs *Tabs) popHistory() (int, bool) {
 	lastIdx := len(tabs.history) - 1
+	if lastIdx < 0 {
+		return 0, false
+	}
 	item := tabs.history[lastIdx]
 	tabs.history = tabs.history[:lastIdx]
-	return item
+	return item, true
 }
 
 func (tabs *Tabs) removeHistory(index int) {
a id='n197' href='#n197'>197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357