Skip to content

Commit

Permalink
Use "from" and "through" to indicate before or
Browse files Browse the repository at this point in the history
after the cursor for selections.
  • Loading branch information
wolfmanstout committed Dec 8, 2024
1 parent dfd9ffa commit 5cf3cd3
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions timestamped_captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,37 @@ def prose_range(m) -> TextRange:
)


@mod.capture(rule="[through] <self.prose_position>")
@mod.capture(rule="[through | from] <self.prose_position>")
def one_ended_prose_range(m) -> TextRange:
"""A range of onscreen text with only start or end specified."""
has_through = m[0] == "through"
# As a convenience, allow dropping "through" if position is provided.
if has_through or m.prose_position.position:
if not m.prose_position.position:
actions.app.notify(
'Try "[through] before <phrase>" or "[through] after <phrase>" instead'
' of "through <phrase>". The cursor position is unknown to '
"talon-gaze-ocr."
)
raise ValueError(
'Text range "through <phrase>" not supported because cursor position is unknown.'
)
has_from = m[0] == "from"
# As a convenience, allow dropping "through" or "from" if position is provided.
if m.prose_position.position:
return TextRange(
start=None,
after_start=False,
end=m.prose_position.text,
before_end=m.prose_position.position == "before",
)
elif has_through:
# Select current cursor point through the text after the cursor.
return TextRange(
start=None,
after_start=False,
end=m.prose_position.text,
before_end=False,
)
elif has_from:
# Select from the text before the cursor up to the current cursor point.
return TextRange(
start=None,
after_start=False,
end=m.prose_position.text,
before_end=True,
)
else:
# Select the phrase itself.
return TextRange(
start=m.prose_position.text,
after_start=m.prose_position.position == "after",
Expand Down

0 comments on commit 5cf3cd3

Please sign in to comment.