From 00504c43ff6e5ba32e7aa8cac355e15a43591653 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 7 May 2018 15:59:20 -0700 Subject: [PATCH] Fixes #39. Unfocused tab problem solved --- system/widget.go | 2 +- wtf.go | 2 +- wtf/focus_tracker.go | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/system/widget.go b/system/widget.go index b4521c38..435cff12 100644 --- a/system/widget.go +++ b/system/widget.go @@ -20,7 +20,7 @@ type Widget struct { func NewWidget(builtAt, version string) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" System ", "system", false), + TextWidget: wtf.NewTextWidget(" Build ", "system", false), BuiltAt: builtAt, Version: version, } diff --git a/wtf.go b/wtf.go index 1ba53b61..0ebd7a57 100644 --- a/wtf.go +++ b/wtf.go @@ -201,7 +201,7 @@ func main() { FocusTracker = wtf.FocusTracker{ App: app, - Idx: 0, + Idx: -1, Widgets: Widgets, } diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index b3ae18e4..9d6c328e 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -17,9 +17,11 @@ type FocusTracker struct { // Next sets the focus on the next widget in the widget list. If the current widget is // the last widget, sets focus on the first widget. func (tracker *FocusTracker) Next() { - tracker.blur(tracker.Idx) - tracker.increment() - tracker.focus(tracker.Idx) + if tracker.widgetHasFocus() { + tracker.blur(tracker.Idx) + tracker.increment() + tracker.focus(tracker.Idx) + } } // None removes focus from the currently-focused widget. @@ -30,9 +32,11 @@ func (tracker *FocusTracker) None() { // Prev sets the focus on the previous widget in the widget list. If the current widget is // the last widget, sets focus on the last widget. func (tracker *FocusTracker) Prev() { - tracker.blur(tracker.Idx) - tracker.decrement() - tracker.focus(tracker.Idx) + if tracker.widgetHasFocus() { + tracker.blur(tracker.Idx) + tracker.decrement() + tracker.focus(tracker.Idx) + } } func (tracker *FocusTracker) Refocus() { @@ -104,6 +108,10 @@ func (tracker *FocusTracker) increment() { // widgetHasFocus returns true if one of the widgets currently has the app's focus, // false if none of them do (ie: perhaps a modal dialog currently has it instead) func (tracker *FocusTracker) widgetHasFocus() bool { + if tracker.Idx < 0 { + return true + } + for _, widget := range tracker.Widgets { if widget.TextView() == tracker.App.GetFocus() { return true