From df4b816db766d5baf0b2c55195985de6944fc2fa Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Fri, 2 Aug 2019 09:18:28 +0200 Subject: [PATCH] fix(demon): make max-items filter more robust --- demon.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/demon.go b/demon.go index b977fe0..05d9a39 100644 --- a/demon.go +++ b/demon.go @@ -65,7 +65,6 @@ func listen(history []string, histfile string, persist bool, max int) { l := len(history) if l > 0 { - // wl-paste will always give back the last copied text // (as long as the place we copied from is still running) if history[l-1] == text { @@ -73,15 +72,13 @@ func listen(history []string, histfile string, persist bool, max int) { continue } - if l == max { - // we know that at any given time len(history) cannot be bigger than max, - // so it's enough to drop the first element - history = history[1:] + if l >= max { + // usually just one item, but more if we reduce our --max-items value + history = history[l-max+1:] } // remove duplicates history = filter(history, text) - } history = append(history, text)