diff options
author | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-05-25 21:14:55 +0200 |
---|---|---|
committer | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-05-25 21:14:55 +0200 |
commit | 61ca4b802c7df75de8a31c6e409eeae15190accf (patch) | |
tree | 8b2f63ad0b95dec515322614640148e19f8ec37f | |
parent | acea55225e340078dabeffe9b6aaa05f34bdc99d (diff) |
history: simplify get_entry query
By sorting rows in descending order instead of performing an arithmetic operation on the maximum value.
-rw-r--r-- | saneterm/history.py | 6 | ||||
-rw-r--r-- | saneterm/terminal.py | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/saneterm/history.py b/saneterm/history.py index 29e0c34..fba974a 100644 --- a/saneterm/history.py +++ b/saneterm/history.py @@ -66,6 +66,9 @@ class History(): an offset of zero would return the current entry and an offset of one would return the previous entry. None is returned if no entry with the given offset exists.''' + if (offset < 0): + return None + exe = self.__get_exec(fd) # Select an entry by the given offset. If the offset exceeds the @@ -73,8 +76,7 @@ class History(): self.__cur.execute(""" SELECT entry FROM history WHERE exe=:exe AND ( SELECT count(*) FROM history WHERE exe=:exe ) >= :offset - ORDER BY rowid ASC LIMIT 1 OFFSET - (( SELECT count(*) FROM history WHERE exe=:exe ) - :offset); + ORDER BY rowid DESC LIMIT 1 OFFSET :offset; """, {"exe": exe, "offset": offset}) res = self.__cur.fetchone() diff --git a/saneterm/terminal.py b/saneterm/terminal.py index 8bd3120..c48ea04 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -144,7 +144,7 @@ class Terminal(Gtk.Window): return GLib.SOURCE_CONTINUE def reset_history_index(self): - self.hist_index = 0 + self.hist_index = -1 def history(self, termview, idx): # Backup index and restore it if no entry with new index exists. |