I don't wanna say this too loud, but I think tab completion is much more reliable now. No more not reading when you press tab and something appears.

This commit is contained in:
Storm Dragon
2025-08-31 20:45:32 -04:00
parent a6bb3e1301
commit 0658d37ae8
2 changed files with 158 additions and 39 deletions

View File

@@ -4,7 +4,7 @@
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors.
import time
from fenrirscreenreader.core.i18n import _
@@ -19,7 +19,25 @@ class command:
pass
def get_description(self):
return "No Description found"
return _("Announces incoming text changes")
def _was_handled_by_tab_completion(self, delta_text):
"""Check if this delta was already handled by tab completion to avoid duplicates"""
if "tabCompletion" not in self.env["commandBuffer"]:
return False
tab_state = self.env["commandBuffer"]["tabCompletion"]
# Check if this exact delta was processed recently by tab completion
if (tab_state.get("lastProcessedDelta") == delta_text and
tab_state.get("lastProcessedTime")):
# Only suppress if processed within the last 100ms to avoid stale suppression
time_since_processed = time.time() - tab_state["lastProcessedTime"]
if time_since_processed <= 0.1:
return True
return False
def run(self):
if not self.env["runtime"]["SettingsManager"].get_setting_as_bool(
@@ -30,6 +48,12 @@ class command:
if not self.env["runtime"]["ScreenManager"].is_delta(ignoreSpace=True):
return
delta_text = self.env["screen"]["new_delta"]
# Skip if tab completion already handled this delta
if self._was_handled_by_tab_completion(delta_text):
return
# this must be a keyecho or something
# if len(self.env['screen']['new_delta'].strip(' \n\t')) <= 1:
x_move = abs(
@@ -41,14 +65,14 @@ class command:
- self.env["screen"]["old_cursor"]["y"]
)
if (x_move >= 1) and x_move == len(self.env["screen"]["new_delta"]):
if (x_move >= 1) and x_move == len(delta_text):
# if len(self.env['screen']['new_delta'].strip(' \n\t0123456789'))
# <= 2:
if "\n" not in self.env["screen"]["new_delta"]:
if "\n" not in delta_text:
return
# print(x_move, y_move, len(self.env['screen']['new_delta']), len(self.env['screen']['newNegativeDelta']))
self.env["runtime"]["OutputManager"].present_text(
self.env["screen"]["new_delta"], interrupt=False, flush=False
delta_text, interrupt=False, flush=False
)
def set_callback(self, callback):