Hammerspoon / Spoons

The official repository of Spoon plugins
https://www.hammerspoon.org/Spoons/
443 stars 139 forks source link

Clipboard tool ignoring some inputs, sometimes #174

Open tiagoboldt opened 4 years ago

tiagoboldt commented 4 years ago

Recently, it might have been since the last Hammerspoon update, the clipboard tool began behaving erratically. Sometimes, it ignores some inputs. Specifically it doesn't always open with hyper + p, it doesn't always close with escape and it never goes does with the down arrow. It does always go up with the up arrow and pastes the value with enter. There's no errors on my console.

My config for it is:

spoon.ClipboardTool.paste_on_select = true
spoon.ClipboardTool.frequency = 2
spoon.ClipboardTool.max_size = false
spoon.ClipboardTool.hist_size = 20
spoon.ClipboardTool.honor_ignoredidentifiers = true
spoon.ClipboardTool.ignoredIdentifiers =  {
    ["de.petermaurer.TransientPasteboardType"] = true, -- Transient : Textpander, TextExpander, Butler
    ["com.typeit4me.clipping"]                 = true, -- Transient : TypeIt4Me
    ["Pasteboard generator type"]              = true, -- Transient : Typinator
    ["com.agilebits.onepassword"]              = true, -- Confidential : 1Password
    ["org.nspasteboard.TransientType"]         = true, -- Universal, Transient
    ["org.nspasteboard.ConcealedType"]         = true, -- Universal, Concealed
    ["org.nspasteboard.AutoGeneratedType"]     = true, -- Universal, Automatic
 }
spoon.ClipboardTool.show_in_menubar = false
spoon.ClipboardTool:start()
jacix commented 1 month ago

I've noticed similar behavior when ClipboardTool.max_entry_size is set to less than 3000 and what I've copied to the clipboard is also less than 3000. After that ClipboardTool stops noticing when I copy anything to the clipboard. Only a restart fixes it.

The problem is in function obj:reduceSize which starts looking at position 3000 for a newline character. If the clipboard entry doesn't have that many characters, variable "endingpos" is nil so the print in line 413 throws an error like I pasted below. Removing the print statement moves the error to the comparison in line 414. The value of 3000 there also means that any setting of ClipboardTool.max_entry_size smaller than 3000 gets treated like 3000.

2024-07-18 01:45:43: answer: Copy partially
2024-07-18 01:45:43: 1064 ? 512
2024-07-18 01:45:43: 01:45:43 ERROR:   LuaSkin: hs.timer callback error: ~/.hammerspoon/Spoons/ClipboardTool.spoon/init.lua:412: attempt to concatenate a nil value (local 'endingpos')
stack traceback:
    ~/.hammerspoon/Spoons/ClipboardTool.spoon/init.lua:412: in function 'ClipboardTool.reduceSize'
    ~/.hammerspoon/Spoons/ClipboardTool.spoon/init.lua:443: in function 'ClipboardTool.checkAndStorePasteboard'
    (...tail calls...)