diff --git a/gaze_ocr_talon.py b/gaze_ocr_talon.py index ef3080b..2055cbc 100644 --- a/gaze_ocr_talon.py +++ b/gaze_ocr_talon.py @@ -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(): @@ -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()) @@ -610,7 +618,7 @@ def run(): find_text, position, ) - actions.user.dictation_insert(insertion_text) + context_sensitive_insert(insertion_text) begin_generator(run()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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())