talonhub/community

Customizable timeout for `clip.capture` in `selected_text`

phillco opened this issue · 1 comments

@AndreasArvidsson pointed this out during the Cursorless session today, but clip.capture() has a default timeout of 500ms. This timeout is hit whenever the selection is empty.

This means that commands like "google that" are normally fast when used normally (with a selection), but if you don't have a selection (such as if they are triggered accidentally), you have to wait for this timeout. 500ms feels relatively high.

We theorized that this is to handle sluggish apps or sluggish computers, so this might be a reasonable default to keep, but we should make it a setting so that power users can lower the timeout (under the assumption that they would notice if they have an application that needs a higher timeout), and thus have a better experience.

Here's an example of setting 100ms, although we would obviously use a setting:

@ctx.action_class("edit")
class EditActions:
    def selected_text() -> str:
        with clip.capture(timeout=0.1) as s:
            actions.edit.copy()
        try:
            return s.text()
        except clip.NoChange:
            return ""

For what is worth I have now been using 0.1 for over a year without any problems. I'm definitely for reducing the default and adding a setting.