From c5f3e4f8833e407ed880201c6a18de26c8d8d057 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 31 Dec 2019 11:06:47 +0100 Subject: [PATCH] Added GetFocusedItemIndex() to Form. Resolves #293 --- form.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/form.go b/form.go index 775b672..d5d9b48 100644 --- a/form.go +++ b/form.go @@ -341,6 +341,19 @@ func (f *Form) GetFormItemIndex(label string) int { return -1 } +// GetFocusedItemIndex returns the indices of the form element or button which +// currently has focus. If they don't, -1 is returned resepectively. +func (f *Form) GetFocusedItemIndex() (formItem, button int) { + index := f.focusIndex() + if index < 0 { + return -1, -1 + } + if index < len(f.items) { + return index, -1 + } + return -1, index - len(f.items) +} + // SetCancelFunc sets a handler which is called when the user hits the Escape // key. func (f *Form) SetCancelFunc(callback func()) *Form {