From 63a247000ba8ffee9f3eb4b15a949a1ef2f3a838 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Fri, 22 Mar 2019 16:08:28 +0100 Subject: [PATCH] only filter history if not empty --- main.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 018c173..a9310de 100644 --- a/main.go +++ b/main.go @@ -74,21 +74,23 @@ func main() { l := len(history) - // 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 { - time.Sleep(sleep) - continue - } + 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 { + time.Sleep(sleep) + 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 { + // 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:] + } - // remove duplicates - history = filter(history, text) + // remove duplicates + history = filter(history, text) + } history = append(history, text)