diff options
-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. |