fix: selected works as intended

This commit is contained in:
Anish Lakhwara 2024-05-04 18:21:17 -07:00
parent d920020d24
commit 9aeb85a771

View file

@ -325,26 +325,31 @@ func (m *Model) SetColumns(c []Column) {
// Update row to selected
func (m *Model) SwitchRow() {
// Get selected row
selected := m.SelectedRow()
if (selected[0] == "❌") {
selected[0] = "✅"
selectedRow := m.SelectedRow()
if (selectedRow[0] == "❌") {
selectedRow[0] = "✅"
} else {
selected[0] = "❌"
selectedRow[0] = "❌"
}
removedRows := remove(m.rows, m.cursor)
m.cursor = clamp(m.cursor - 1, 0, len(removedRows) + 1)
// If cursor outside selection (adding selection)
// We check equals because if it's on the border, we just moved into selection
// and are still adding
if m.cursor >= m.selected {
newSelection := append(removedRows[:m.selected], selected)
m.rows = append(newSelection, removedRows[m.selected+1:]...)
newSelection := make([]Row, len(removedRows) + 1)
newSelection = append(removedRows[:m.selected+1], removedRows[m.selected:]...)
newSelection[m.selected] = selectedRow
m.rows = newSelection
m.selected += 1
} else {
m.selected -= 1
m.rows = append(removedRows, selected)
newSelection := make([]Row, len(removedRows) + 1)
newSelection = append(removedRows[:m.selected+1], removedRows[m.selected:]...)
newSelection[m.selected] = selectedRow
m.rows = newSelection
}
m.UpdateViewport()