fix(demon): make max-items filter more robust
This commit is contained in:
parent
cdce95b33a
commit
df4b816db7
1 changed files with 3 additions and 6 deletions
9
demon.go
9
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)
|
||||
|
|
Loading…
Reference in a new issue