From 0d2667685e1ae9d64c21b7234087e3d095854005 Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Fri, 10 May 2019 18:46:31 -0400 Subject: [PATCH] Add stable sort for focusable windows Addresses #435 --- wtf/focus_tracker.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index 002c5e10..de935c96 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -1,6 +1,8 @@ package wtf import ( + "sort" + "github.com/olebedev/config" "github.com/rivo/tview" ) @@ -177,6 +179,17 @@ func (tracker *FocusTracker) focusables() []Wtfable { } } + // Sort for deterministic ordering + sort.SliceStable(focusable[:], func(i, j int) bool { + if focusable[i].Top() < focusable[j].Top() { + return true + } + if focusable[i].Top() == focusable[j].Top() { + return focusable[i].Left() < focusable[j].Left() + } + return false + }) + return focusable }