Skip to content

Commit

Permalink
feat: add SortAsc and SortDesc to keybind system
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Aug 30, 2024
1 parent 9dd8e99 commit f5bda70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/Keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ var Keymaps = KeymapSystem{
Bind{Key: Key{Char: '0'}, Cmd: cmd.GotoStart, Description: "Go to first cell"},
Bind{Key: Key{Char: 'y'}, Cmd: cmd.Copy, Description: "Copy cell to clipboard"},
Bind{Key: Key{Char: 'o'}, Cmd: cmd.AppendNewRow, Description: "Append new row"},
Bind{Key: Key{Char: 'J'}, Cmd: cmd.SortDesc, Description: "Sort descending"},
Bind{Key: Key{Char: 'K'}, Cmd: cmd.SortAsc, Description: "Sort ascending"},
// Tabs
Bind{Key: Key{Char: '['}, Cmd: cmd.TabPrev, Description: "Switch to previous tab"},
Bind{Key: Key{Char: ']'}, Cmd: cmd.TabNext, Description: "Switch to next tab"},
Expand Down
6 changes: 6 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
Execute
OpenInExternalEditor
AppendNewRow
SortAsc
SortDesc
)

func (c Command) String() string {
Expand Down Expand Up @@ -118,6 +120,10 @@ func (c Command) String() string {
return "OpenInExternalEditor"
case AppendNewRow:
return "AppendNewRow"
case SortAsc:
return "SortAsc"
case SortDesc:
return "SortDesc"
}
return "Unknown"
}
4 changes: 2 additions & 2 deletions components/ResultsTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
}

if len(table.GetRecords()) > 0 {
if eventKey == 'J' {
if command == commands.SortDesc {
currentColumnName := table.GetColumnNameByIndex(selectedColumnIndex)
table.Pagination.SetOffset(0)
table.SetSortedBy(currentColumnName, "DESC")

} else if eventKey == 'K' {
} else if command == commands.SortAsc {
currentColumnName := table.GetColumnNameByIndex(selectedColumnIndex)
table.Pagination.SetOffset(0)
table.SetSortedBy(currentColumnName, "ASC")
Expand Down

0 comments on commit f5bda70

Please sign in to comment.