summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-02-16 13:46:04 +0100
committerGitHub <noreply@github.com>2024-02-16 13:46:04 +0100
commit1081c45397d9bf6741fc5519ad1e3d736960e40a (patch)
treea83ea6453122fad86656503fe522669206387a66 /pkg/gui/controllers
parent5b567f37745ae82799d9460525935d83c0d97492 (diff)
parent6c6201ab044687cf276946f4a3578c9fd76fda34 (diff)
Fix order of custom commands history (#3286)
- **PR Description** Fix order problems when saving custom commands history This fixes two problems: - each time the custom commands panel was opened, the history of commands would be shown in reversed order compared to last time. (The reason is that lo.Reverse modifies the slice in place rather than just returning a new, reversed slice.) - when executing a previous command again (either by typing it in again, or by picking it from the history), it should move to the beginning of the history, but didn't. We fix this by storing the history in reversed order (as the user sees it in the panel), this makes the logic simpler. We just have to prepend rather than append newly added commands now. While this is theoretically a breaking change, it's not worth bothering because the order was wrong for existing users in 50% of the cases anyway.
Diffstat (limited to 'pkg/gui/controllers')
-rw-r--r--pkg/gui/controllers/custom_command_action.go10
1 files changed, 3 insertions, 7 deletions
diff --git a/pkg/gui/controllers/custom_command_action.go b/pkg/gui/controllers/custom_command_action.go
index bd24cda7d..bc595934d 100644
--- a/pkg/gui/controllers/custom_command_action.go
+++ b/pkg/gui/controllers/custom_command_action.go
@@ -20,15 +20,12 @@ func (self *CustomCommandAction) Call() error {
HandleConfirm: func(command string) error {
if self.shouldSaveCommand(command) {
self.c.GetAppState().CustomCommandsHistory = utils.Limit(
- lo.Uniq(append(self.c.GetAppState().CustomCommandsHistory, command)),
+ lo.Uniq(append([]string{command}, self.c.GetAppState().CustomCommandsHistory...)),
1000,
)
}
- err := self.c.SaveAppState()
- if err != nil {
- self.c.Log.Error(err)
- }
+ self.c.SaveAppStateAndLogError()
self.c.LogAction(self.c.Tr.Actions.CustomCommand)
return self.c.RunSubprocessAndRefresh(
@@ -39,8 +36,7 @@ func (self *CustomCommandAction) Call() error {
}
func (self *CustomCommandAction) GetCustomCommandsHistorySuggestionsFunc() func(string) []*types.Suggestion {
- // reversing so that we display the latest command first
- history := lo.Reverse(self.c.GetAppState().CustomCommandsHistory)
+ history := self.c.GetAppState().CustomCommandsHistory
return helpers.FuzzySearchFunc(history)
}