feat: add chat input history navigation (up/down)

This commit is contained in:
Username
2026-02-24 13:28:03 +01:00
parent f77375422a
commit 6c16883135

View File

@@ -260,6 +260,9 @@ class TuimbleApp(App):
username=srv.username,
password=srv.password,
)
self._history: list[str] = []
self._history_idx: int = -1
self._history_draft: str = ""
acfg = self._config.audio
self._audio = AudioPipeline(
sample_rate=acfg.sample_rate,
@@ -362,6 +365,8 @@ class TuimbleApp(App):
if not text:
return
event.input.clear()
self._history.append(text)
self._history_idx = -1
if not self._client.connected:
self._show_error("not connected")
@@ -429,7 +434,35 @@ class TuimbleApp(App):
# -- PTT -----------------------------------------------------------------
def on_key(self, event: events.Key) -> None:
"""Handle PTT key events."""
"""Handle input history navigation and PTT key events."""
focused = self.focused
if isinstance(focused, Input) and event.key in ("up", "down"):
inp = focused
if event.key == "up":
if not self._history:
event.prevent_default()
return
if self._history_idx == -1:
self._history_draft = inp.value
self._history_idx = len(self._history) - 1
elif self._history_idx > 0:
self._history_idx -= 1
inp.value = self._history[self._history_idx]
inp.cursor_position = len(inp.value)
else: # down
if self._history_idx == -1:
event.prevent_default()
return
if self._history_idx < len(self._history) - 1:
self._history_idx += 1
inp.value = self._history[self._history_idx]
else:
self._history_idx = -1
inp.value = self._history_draft
inp.cursor_position = len(inp.value)
event.prevent_default()
return
if event.key != self._config.ptt.key:
return