in pkg/selector/outputs/tableView.go [291:363]
func (m tableModel) update(msg tea.Msg) (tableModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
// update filtering input field
if m.filterTextInput.Focused() {
var cmd tea.Cmd
if msg.String() == "enter" || msg.String() == "esc" {
// exit filter input and update controls string
m.filterTextInput.Blur()
m = m.updateFooter()
} else {
m.filterTextInput, cmd = m.filterTextInput.Update(msg)
}
m.table = m.table.WithFilterInput(m.filterTextInput)
return m, cmd
}
// listen for specific inputs
switch msg.String() {
case "f":
// focus filter input field
m.filterTextInput.Focus()
case "t":
// handle trimming to selected rows
if m.isTrimmed {
// undo trim
m = m.untrim()
m.isTrimmed = false
} else {
// trim
m = m.trim()
m.isTrimmed = true
}
case " ":
// custom toggling of selected rows because bubble tea implementation
// breaks trimming
if m.canSelectRows {
originalRows := m.getUnfilteredRows()
selectedRow := m.table.HighlightedRow()
isSelected, ok := selectedRow.Data[selectedKey].(bool)
if !ok {
break
}
// flip selected flag
selectedRow.Data[selectedKey] = !isSelected
selectedRow = selectedRow.Selected(!isSelected)
// update selected row with new selected state. Must iterate through
// original rows since the cursor index in the bubble tea table
// takes the filter into account and therefore returns an incorrect index
for i, row := range originalRows {
if row.Data[instanceTypeKey] == selectedRow.Data[instanceTypeKey] {
originalRows[i] = selectedRow
break
}
}
m.table = m.table.WithRows(originalRows)
}
}
}
var cmd tea.Cmd
m.table, cmd = m.table.Update(msg)
// update footer
m = m.updateFooter()
return m, cmd
}