mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add inline Other answers to async question choices (#42897)
## Why Async questions with suggested choices only accepted those choices. Allow users to write an alternative answer directly in the question pane. ## What changed - Append an editable Other choice. Typing or pasting opens it, while number shortcuts still submit named choices. - Preserve custom drafts when switching choices, reject blank Other submissions, and distinguish the input from a suggested choice named Other. - Support Vim editing and search in question inputs while keeping arrow keys available for choice navigation. - Wrap custom answers inline, cap the editor height, and keep the input visible in narrow layouts. ## Testing Add interaction tests and snapshots covering custom answer delivery, draft preservation, selector key repeats, blank answers, remapped shortcuts, Vim editing and search, and narrow or wrapped layouts. GitOrigin-RevId: 0e9aa9fcd2410e8da25f5ca43bdef94cbb9253b8
This commit is contained in:
1 parent
07f18d5ff7
commit
c126b0d8ef
21 files changed
+728
-70
No files matched your search
@@ -463,7 +463,7 @@ impl ChatComposer {
|
||||
/// footer area is collapsed or too narrow, the x coordinate is clamped inside the hint rect so
|
||||
/// terminal backends do not receive an off-screen cursor position.
|
||||
pub(super) fn history_search_cursor_pos(&self, area: Rect) -> Option<(u16, u16)> {
|
||||
let search = self.history_search.as_ref()?;
|
||||
self.history_search.as_ref()?;
|
||||
let [_, _, _, popup_rect] = self.layout_areas(area);
|
||||
if popup_rect.is_empty() {
|
||||
return None;
|
||||
@@ -488,17 +488,27 @@ impl ChatComposer {
|
||||
return None;
|
||||
}
|
||||
|
||||
let indent = (FOOTER_INDENT_COLS as u16).min(hint_rect.width.saturating_sub(1));
|
||||
self.history_search_query_cursor_pos(Rect {
|
||||
x: hint_rect.x.saturating_add(indent),
|
||||
width: hint_rect.width.saturating_sub(indent),
|
||||
..hint_rect
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn history_search_query_cursor_pos(&self, area: Rect) -> Option<(u16, u16)> {
|
||||
let search = self.history_search.as_ref()?;
|
||||
if area.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let prompt_width = Line::from("reverse-i-search: ").width() as u16;
|
||||
let query_width = Line::from(search.query.clone()).width() as u16;
|
||||
let desired_x = hint_rect
|
||||
let desired_x = area
|
||||
.x
|
||||
.saturating_add(FOOTER_INDENT_COLS as u16)
|
||||
.saturating_add(prompt_width)
|
||||
.saturating_add(query_width);
|
||||
let max_x = hint_rect
|
||||
.x
|
||||
.saturating_add(hint_rect.width.saturating_sub(1));
|
||||
Some((desired_x.min(max_x), hint_rect.y))
|
||||
let max_x = area.x.saturating_add(area.width.saturating_sub(1));
|
||||
Some((desired_x.min(max_x), area.y))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,14 @@ impl ChatComposer {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
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()
|
||||
&& !matches!(key.code, KeyCode::Up | KeyCode::Down)
|
||||
&& !self.submit_keys.is_pressed(key)
|
||||
&& !self.queue_keys.is_pressed(key)
|
||||
&& (self.vim_normal_keymap.move_up.is_pressed(key)
|
||||
@@ -72,6 +74,9 @@ impl ChatComposer {
|
||||
if let Some(query) = self.draft.textarea.vim_query() {
|
||||
return query.cursor_pos(query_area);
|
||||
}
|
||||
if self.history_search.is_some() {
|
||||
return self.history_search_query_cursor_pos(query_area);
|
||||
}
|
||||
self.draft
|
||||
.textarea
|
||||
.cursor_pos_with_state(area, *self.draft.textarea_state.borrow())
|
||||
@@ -101,6 +106,12 @@ impl ChatComposer {
|
||||
Rect::new(area.x, area.bottom(), area.width, /*height*/ 1),
|
||||
buf,
|
||||
);
|
||||
} else if let Some(line) = self.history_search_footer_line() {
|
||||
area.height = area.height.saturating_sub(1);
|
||||
line.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
|
||||
|
||||
Reference in new issue
Block a user