fix(demon): make max-items filter more robust

This commit is contained in:
yory8 2019-08-02 09:18:28 +02:00
parent cdce95b33a
commit df4b816db7

View file

@ -65,7 +65,6 @@ func listen(history []string, histfile string, persist bool, max int) {
l := len(history) l := len(history)
if l > 0 { if l > 0 {
// wl-paste will always give back the last copied text // wl-paste will always give back the last copied text
// (as long as the place we copied from is still running) // (as long as the place we copied from is still running)
if history[l-1] == text { if history[l-1] == text {
@ -73,15 +72,13 @@ func listen(history []string, histfile string, persist bool, max int) {
continue continue
} }
if l == max { if l >= max {
// we know that at any given time len(history) cannot be bigger than max, // usually just one item, but more if we reduce our --max-items value
// so it's enough to drop the first element history = history[l-max+1:]
history = history[1:]
} }
// remove duplicates // remove duplicates
history = filter(history, text) history = filter(history, text)
} }
history = append(history, text) history = append(history, text)