From 1f9ce80975cb6ffeefa1f867171850806bcf6e0d Mon Sep 17 00:00:00 2001 From: Christian Doczkal <20443222+chdoc@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:07:11 +0200 Subject: [PATCH 1/2] override peek implementation for libreoffice --- apps/libreoffice/libreoffice.py | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 apps/libreoffice/libreoffice.py diff --git a/apps/libreoffice/libreoffice.py b/apps/libreoffice/libreoffice.py new file mode 100644 index 0000000000..da8fd4f90a --- /dev/null +++ b/apps/libreoffice/libreoffice.py @@ -0,0 +1,40 @@ +from typing import Callable +from talon import Context, Module, actions, settings + +mod = Module() + +mod.apps.libreoffice = """ +os: linux +and app.exe: soffice.bin +""" + +ctx = Context() +ctx.matches = r""" +app: libreoffice +""" + +# Unlike most other applications, LibreOffice does not move the cursor to the +# start/end of the selection when pressing left/right. Instead, it only moves +# the cursor one step. +@ctx.action_class("user") +class UserActions: + def dictation_peek(left, right): + # clobber selection if it exists + actions.key("space backspace") + before, after = None, None + if left: + actions.edit.extend_word_left() + actions.edit.extend_word_left() + before = actions.edit.selected_text() + repeat_action(actions.edit.right,len(before)) + if right: + actions.edit.extend_word_right() + actions.edit.extend_word_right() + after = actions.edit.selected_text() + repeat_action(actions.edit.left,len(after)) + return (before, after) + + +def repeat_action(action: Callable, count: int): + for _ in range(count): + action() From 6cab367f724f2638d558fe23890f98e5790e6499 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:52:35 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/libreoffice/libreoffice.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/libreoffice/libreoffice.py b/apps/libreoffice/libreoffice.py index da8fd4f90a..8a0664c25c 100644 --- a/apps/libreoffice/libreoffice.py +++ b/apps/libreoffice/libreoffice.py @@ -1,4 +1,5 @@ from typing import Callable + from talon import Context, Module, actions, settings mod = Module() @@ -13,9 +14,10 @@ app: libreoffice """ + # Unlike most other applications, LibreOffice does not move the cursor to the # start/end of the selection when pressing left/right. Instead, it only moves -# the cursor one step. +# the cursor one step. @ctx.action_class("user") class UserActions: def dictation_peek(left, right): @@ -26,12 +28,12 @@ def dictation_peek(left, right): actions.edit.extend_word_left() actions.edit.extend_word_left() before = actions.edit.selected_text() - repeat_action(actions.edit.right,len(before)) + repeat_action(actions.edit.right, len(before)) if right: actions.edit.extend_word_right() actions.edit.extend_word_right() after = actions.edit.selected_text() - repeat_action(actions.edit.left,len(after)) + repeat_action(actions.edit.left, len(after)) return (before, after)