From 23dc8a0944e4cdc31297e081606be7959b5c4efc Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 21 Jul 2019 15:54:19 +0200 Subject: [PATCH] Table.Select() also triggers "selection changed" event. Fixes #323 --- table.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/table.go b/table.go index 0c810e8..54eb6a7 100644 --- a/table.go +++ b/table.go @@ -355,9 +355,14 @@ func (t *Table) GetSelection() (row, column int) { // Select sets the selected cell. Depending on the selection settings // specified via SetSelectable(), this may be an entire row or column, or even -// ignored completely. +// ignored completely. The "selection changed" event is fired if such a callback +// is available (even if the selection ends up being the same as before, even if +// cells are not selectable). func (t *Table) Select(row, column int) *Table { t.selectedRow, t.selectedColumn = row, column + if t.selectionChanged != nil { + t.selectionChanged(row, column) + } return t } @@ -387,10 +392,10 @@ func (t *Table) SetSelectedFunc(handler func(row, column int)) *Table { return t } -// SetSelectionChangedFunc sets a handler which is called whenever the user -// navigates to a new selection. The handler receives the position of the new -// selection. If entire rows are selected, the column index is undefined. -// Likewise for entire columns. +// SetSelectionChangedFunc sets a handler which is called whenever the current +// selection changes. The handler receives the position of the new selection. +// If entire rows are selected, the column index is undefined. Likewise for +// entire columns. func (t *Table) SetSelectionChangedFunc(handler func(row, column int)) *Table { t.selectionChanged = handler return t