Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override peek implementation for libreoffice #1532

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions apps/libreoffice/libreoffice.py
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from typing import Callable

from talon import Context, Module, actions, settings

mod = Module()

mod.apps.libreoffice = """
os: linux
and app.exe: soffice.bin
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add the windows matcher

os: windows
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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this function and just inline it. It's actually fewer lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think inlining this increases clarity. In fact, I copied the function from core/edit/edit_navigation_steps.py. So I would prefer moving this to the right place instead, whatever the right place is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Andreas, I found this harder to parse. For a two-line function I agree we should just inline it - otherwise it leads the reader to try to understand why the function was necessary (performance? etc).

While edit_navigation_steps.py does have many functions like this, it has so many that the pattern becomes more understandable.

for _ in range(count):
action()