mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add TUI building blocks for inline async question editing (#42889)
## What changed - Introduce an async-question editor component with per-question drafts, navigation, replay deduplication, and submit or queue handling using the shared composer. - Add bounded `AnsweredQuestion` framing that truncates question text at a UTF-8 boundary and flattens line breaks before prepending it to an answer. - Add `prompt_stack_back` and `skip_question` keybinding actions and the `tui.question_esc_back` setting. Normalize `Ctrl+]` and `Ctrl+5` for key matching and conflict detection, and let default question shortcuts yield to explicit bindings. - Flush buffered typing in both the main composer and the covering view so background input cannot keep the draw loop waiting. The async-question component is not yet connected to the TUI event flow. ## Testing Add regression coverage for bounded Unicode question framing, question-shortcut conflicts, and paste-buffer flushing in background and covering editors. GitOrigin-RevId: 4098043cf588ddafc05c27505645495edd690cb9
This commit is contained in:
1 parent
574a36ff99
commit
6ae8dcf6e1
32 files changed
+750
-44
No files matched your search
@@ -0,0 +1,115 @@
|
||||
//! Embed the composer in question rows, resetting history navigation when drafts change.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ComposerDraft {
|
||||
pub(in crate::bottom_pane) fn text_with_pending(&self) -> String {
|
||||
ChatComposer::expand_pending_pastes(
|
||||
&self.text,
|
||||
self.text_elements.clone(),
|
||||
&self.pending_pastes,
|
||||
)
|
||||
.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ChatComposer {
|
||||
pub(in crate::bottom_pane) fn restore_inline_draft(&mut self, draft: ComposerDraft) {
|
||||
self.history.reset_navigation();
|
||||
self.restore_draft(draft);
|
||||
}
|
||||
|
||||
pub(crate) fn reset_vim_mode(&mut self) {
|
||||
self.vim_history = VimHistory::default();
|
||||
self.draft.textarea.enter_vim_insert_mode();
|
||||
}
|
||||
|
||||
/// Give modal editing precedence over a containing view's submit/navigation keys.
|
||||
pub(crate) fn handles_key_as_editing(&self, key: KeyEvent) -> bool {
|
||||
self.history_search.is_some()
|
||||
|| self.should_handle_vim_insert_escape(key)
|
||||
|| self.draft.textarea.is_vim_operator_pending()
|
||||
|| self.draft.textarea.wants_vim_search_key(key)
|
||||
|| (self.draft.textarea.is_vim_normal_mode()
|
||||
&& !self.submit_keys.is_pressed(key)
|
||||
&& !self.queue_keys.is_pressed(key)
|
||||
&& (self.vim_normal_keymap.move_up.is_pressed(key)
|
||||
|| self.vim_normal_keymap.move_down.is_pressed(key)))
|
||||
}
|
||||
|
||||
/// Finish buffered typing before another answer takes over this editor.
|
||||
pub(crate) fn flush_pending_input(&mut self) {
|
||||
if let Some(text) = self.draft.paste_burst.flush_before_modified_input() {
|
||||
self.handle_paste(text);
|
||||
}
|
||||
self.draft.paste_burst.clear_after_explicit_paste();
|
||||
}
|
||||
|
||||
pub(crate) fn inline_input_height(&self, width: u16) -> u16 {
|
||||
self.draft.textarea.desired_height(width.max(1))
|
||||
+ u16::from(self.history_search.is_some() || self.draft.textarea.vim_query().is_some())
|
||||
+ u16::from(self.footer.flash_visible())
|
||||
}
|
||||
|
||||
pub(crate) fn inline_cursor_pos(&self, mut area: Rect) -> Option<(u16, u16)> {
|
||||
area.height = area
|
||||
.height
|
||||
.saturating_sub(u16::from(self.footer.flash_visible()));
|
||||
let query_area = Rect::new(
|
||||
area.x,
|
||||
area.bottom().saturating_sub(1),
|
||||
area.width,
|
||||
area.height.min(1),
|
||||
);
|
||||
if let Some(query) = self.draft.textarea.vim_query() {
|
||||
return query.cursor_pos(query_area);
|
||||
}
|
||||
self.draft
|
||||
.textarea
|
||||
.cursor_pos_with_state(area, *self.draft.textarea_state.borrow())
|
||||
}
|
||||
|
||||
pub(crate) fn render_inline_input(&self, area: Rect, buf: &mut Buffer) {
|
||||
if area.is_empty() {
|
||||
return;
|
||||
}
|
||||
ratatui::widgets::Clear.render(area, buf);
|
||||
Block::default()
|
||||
.style(Style::reset().patch(user_message_style()))
|
||||
.render(area, buf);
|
||||
let mut area = area;
|
||||
if self.footer.flash_visible()
|
||||
&& let Some(flash) = &self.footer.flash
|
||||
{
|
||||
area.height = area.height.saturating_sub(1);
|
||||
flash.line.clone().render(
|
||||
Rect::new(area.x, area.bottom(), area.width, /*height*/ 1),
|
||||
buf,
|
||||
);
|
||||
}
|
||||
if let Some(query) = self.draft.textarea.vim_query() {
|
||||
area.height = area.height.saturating_sub(1);
|
||||
query.render(
|
||||
Rect::new(area.x, area.bottom(), area.width, /*height*/ 1),
|
||||
buf,
|
||||
);
|
||||
}
|
||||
let mut state = self.draft.textarea_state.borrow_mut();
|
||||
let highlights: Vec<_> = self
|
||||
.history_search_highlight_ranges()
|
||||
.into_iter()
|
||||
.chain(self.draft.textarea.vim_search_highlights())
|
||||
.map(|range| (range, Style::new().reversed().bold()))
|
||||
.collect();
|
||||
self.draft.textarea.render_ref_styled_with_highlights(
|
||||
area,
|
||||
buf,
|
||||
&mut state,
|
||||
Style::default(),
|
||||
&highlights,
|
||||
);
|
||||
if self.draft.textarea.is_empty() {
|
||||
Line::from(self.placeholder_text.as_str().dim()).render(area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user