mirror of https://github.com/rivo/tview.git
parent
db90355feb
commit
677c227861
14
table.go
14
table.go
|
@ -242,9 +242,9 @@ func (t *Table) SetSelectedFunc(handler func(row, column int)) *Table {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSelectionChangedFunc sets a handler which is called whenever the user changes
|
// SetSelectionChangedFunc sets a handler which is called whenever the user
|
||||||
// selected cell/row/column. The handler receives the position of the selection.
|
// navigates to a new selection. The handler receives the position of the new
|
||||||
// If entire rows are selected, the column index is undefined.
|
// selection. If entire rows are selected, the column index is undefined.
|
||||||
// Likewise for entire columns.
|
// Likewise for entire columns.
|
||||||
func (t *Table) SetSelectionChangedFunc(handler func(row, column int)) *Table {
|
func (t *Table) SetSelectionChangedFunc(handler func(row, column int)) *Table {
|
||||||
t.selectionChanged = handler
|
t.selectionChanged = handler
|
||||||
|
@ -658,10 +658,8 @@ func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var previouslySelectedRow = t.selectedRow
|
|
||||||
var previouslySelectedColumn = t.selectedColumn
|
|
||||||
|
|
||||||
// Movement functions.
|
// Movement functions.
|
||||||
|
previouslySelectedRow, previouslySelectedColumn := t.selectedRow, t.selectedColumn
|
||||||
var (
|
var (
|
||||||
getCell = func(row, column int) *TableCell {
|
getCell = func(row, column int) *TableCell {
|
||||||
if row < 0 || column < 0 || row >= len(t.cells) || column >= len(t.cells[row]) {
|
if row < 0 || column < 0 || row >= len(t.cells) || column >= len(t.cells[row]) {
|
||||||
|
@ -844,8 +842,10 @@ func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the selection has changed, notify the handler.
|
||||||
if t.selectionChanged != nil &&
|
if t.selectionChanged != nil &&
|
||||||
(previouslySelectedRow != t.selectedRow || previouslySelectedColumn != t.selectedColumn) {
|
(t.rowsSelectable && previouslySelectedRow != t.selectedRow ||
|
||||||
|
t.columnsSelectable && previouslySelectedColumn != t.selectedColumn) {
|
||||||
t.selectionChanged(t.selectedRow, t.selectedColumn)
|
t.selectionChanged(t.selectedRow, t.selectedColumn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue