Skip to content

Commit

Permalink
Fix whitespace handling when context sensitive dictation is off.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmanstout committed Apr 19, 2024
1 parent 44e99fd commit 05627ef
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions gaze_ocr_talon.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ def perform_ocr_action_generator(
raise RuntimeError(f"Action not supported: {ocr_action}")


def context_sensitive_insert(text: str):
if settings.get("user.context_sensitive_dictation"):
actions.user.dictation_insert(text)
else:
# Use the default insert because the dictation context is likely wrong.
actions.insert(text)


@mod.action_class
class GazeOcrActions:
def connect_ocr_eye_tracker():
Expand Down Expand Up @@ -596,7 +604,7 @@ def run():
text_range,
for_deletion=settings.get("user.context_sensitive_dictation"),
)
actions.user.dictation_insert(replacement)
context_sensitive_insert(replacement)

begin_generator(run())

Expand All @@ -610,7 +618,7 @@ def run():
find_text,
position,
)
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -623,7 +631,7 @@ def run():
text, "after"
)
insertion_text = text.text[prefix_length:]
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -636,7 +644,7 @@ def run():
text, "before"
)
insertion_text = text.text[:-suffix_length]
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -647,7 +655,7 @@ def insert_text_difference(text: TimestampedText):
def run():
start, end = yield from move_text_cursor_to_difference(text)
insertion_text = text.text[start:end]
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -658,7 +666,7 @@ def revise_text(text: TimestampedText):
def run():
yield from select_matching_text_generator(text)
insertion_text = text.text
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -675,7 +683,7 @@ def run():
# Keep going so the user doesn't lose the dictated text.
print(e)
insertion_text = text.text
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand All @@ -692,7 +700,7 @@ def run():
# Keep going so the user doesn't lose the dictated text.
print(e)
insertion_text = text.text
actions.user.dictation_insert(insertion_text)
context_sensitive_insert(insertion_text)

begin_generator(run())

Expand Down

0 comments on commit 05627ef

Please sign in to comment.