Preserve TUI question state and integrate history and queue navigation (#42903)

## What changed

- Retain question drafts, selections, expanded state, and handled message IDs across thread input restoration and reconnects. Preserve buffered live questions during session refresh without replaying their message text.
- Enable history recall and search in question answers, honoring updated key bindings and stripping image attachments and placeholders from recalled entries. Preserve Vim mode when an answer is not accepted.
- Let forward navigation past the last question restore the latest queued message as an editable main composer draft. Keep working status and queued messages visible alongside questions.
- Show a countdown for newly arrived collapsed questions and clear it when the question editor is opened or used.
- Disable question submission and skipping while the thread is unavailable.

## Testing

Add regression tests and snapshots for draft restoration and replay deduplication, history search and key bindings, queued-message editing, countdown rendering, and question layout with working status.

GitOrigin-RevId: de016120a979db860fd0d4b8098b322b312b7d84
This commit is contained in:
Ian MacLeod authored and copyberry committed 2026-09-05 01:13:54 +00:00
1 parent d05e6d5f46
commit be2684ede0
35 files changed
+700 -87

No files matched your search

@@ -32,6 +32,25 @@ impl ChatComposer {
self.draft.textarea.enter_vim_insert_mode();
}
/// Refresh at traversal start without resetting recalled entries or pending lookups.
pub(crate) fn copy_history_for_key(&mut self, composer: &Self, key: KeyEvent) {
let recall = self.is_empty()
&& !self.history.is_navigating()
&& if self.draft.textarea.is_vim_normal_mode() {
self.vim_normal_keymap.move_up.is_pressed(key)
|| self.vim_normal_keymap.move_down.is_pressed(key)
} else {
self.editor_keymap.move_up.is_pressed(key)
|| self.editor_keymap.move_down.is_pressed(key)
};
let search =
self.history_search_previous_keys.is_pressed(key) && !self.handles_key_as_editing(key);
if self.history_search.is_none() && (recall || search) {
self.history = composer.history.clone();
self.history.reset_navigation();
}
}
/// Give modal editing precedence over a containing view's submit/navigation keys.
/// Up/Down remain available to inline choices; j/k keep their Vim editing behavior.
pub(crate) fn handles_key_as_editing(&self, key: KeyEvent) -> bool {