From eb9cd77e684d8657773ea67068f6b9424615c1f6 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Wed, 21 Sep 2016 21:01:41 +0200
Subject: [PATCH] Fixed some minor history bugs

---
 res/search.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/res/search.js b/res/search.js
index 4f3184c..2e41aec 100644
--- a/res/search.js
+++ b/res/search.js
@@ -19,9 +19,9 @@ var search_history = {
 
         var tmp = search_history.get().filter(function (x) {
             return x != query;
-        });
+        }).reverse();
         tmp.push(query);
-        localStorage.setItem('history', JSON.stringify(tmp.slice(0, tmp.max_size)));
+        localStorage.setItem('history', JSON.stringify(tmp.slice(Math.max(0, tmp.length - tmp.max_size))));
     }
 };
 
@@ -360,8 +360,12 @@ var make_toggle_context = function (buffer, id) {
 };
 
 var hashChange = function () {
-    $("#q").val(decodeURIComponent(location.hash.substr(1)));
-    search();
+    var input = $("#q");
+    var newquery = decodeURIComponent(location.hash.substr(1));
+    if (input.val() != newquery) {
+        input.val(newquery);
+        search();
+    }
 };
 
 var init = function () {
-- 
GitLab