Skip to content

Commit

Permalink
Added setting for selected text timeout (#1517)
Browse files Browse the repository at this point in the history
The default time out for `clip.capture()` is 0.5s. You run into this
every time you call `selected_text()` on an empty selection. I've been
running with 0.1 for over a year with no problems. That might be a bit
to aggressive for community, but 0.25 shouldn't be any problems. Just in
case I added a setting so people with slower (or faster) machines can
change this.

Fixes #1210
  • Loading branch information
AndreasArvidsson authored Aug 3, 2024
1 parent c68d5a4 commit 2d2ddeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/edit/edit.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
from talon import Context, Module, actions, clip
from talon import Context, Module, actions, clip, settings

ctx = Context()
mod = Module()

mod.setting(
"selected_text_timeout",
type=float,
default=0.25,
desc="Time in seconds to wait for the clipboard to change when trying to get selected text",
)

END_OF_WORD_SYMBOLS = ".!?;:—_/\\|@#$%^&*()[]{}<>=+-~`"


@ctx.action_class("edit")
class EditActions:
def selected_text() -> str:
with clip.capture() as s:
timeout = settings.get("user.selected_text_timeout")
with clip.capture(timeout) as s:
actions.edit.copy()
try:
return s.text()
Expand Down
3 changes: 3 additions & 0 deletions settings.talon
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ settings():
# Puts Talon into sleep mode if no commands are spoken for a defined period of time.
# user.listening_timeout_minutes = 3

# Time in seconds to wait for the clipboard to change when trying to get selected text
# user.selected_text_timeout = 0.25

# Uncomment to enable the curse yes/curse no commands (show/hide mouse cursor).
# See issue #688 for more detail: https://github.com/talonhub/community/issues/688
# tag(): user.mouse_cursor_commands_enable
Expand Down

0 comments on commit 2d2ddeb

Please sign in to comment.