mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Make TUI workspace divider drags more responsive (#63997)
## Why Rapid mouse motion can queue more drag reports than the TUI needs to resize a pane. Rebuilding sidebar document layouts at each preview width also adds work while the divider moves. ## What changed - Share drag handling between the Command Center and sidebar dividers. Let users grab either column of the Command Center gutter, keep the grab offset, and highlight the divider on hover and during a drag. - Use the release position for the final width. If focus loss interrupts a valid drag, keep the last width. When the terminal holds image pixels, show a guide and defer pane reflow until the drag ends. - Batch consecutive mouse motion reports during divider drags while preserving input order at batch boundaries. Rewrap cached sidebar document content during live previews and rebuild its layout at the final width. ## Testing Cover gutter hit testing, grab offsets, release and focus-loss behavior, drag batching at input boundaries, and document layout reuse during preview followed by a rebuild. GitOrigin-RevId: 949a805a42d269f4bac1a86ac7e4b7f8c2a4cacf
This commit is contained in:
+1
-15
@@ -899,8 +899,6 @@ impl App {
|
||||
) -> Result<AppRunControl> {
|
||||
if matches!(event, TuiEvent::Draw) && tui::mouse_capture_disabled() {
|
||||
self.sidebar_press = None;
|
||||
self.divider_drag = None;
|
||||
self.agents_overview.workspace.divider_drag_viewport = None;
|
||||
self.chat_widget.end_composer_drag();
|
||||
self.chat_widget.rendered_selection.borrow_mut().end_drag();
|
||||
}
|
||||
@@ -918,10 +916,7 @@ impl App {
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.sidebar_press = None;
|
||||
self.agents_overview.workspace.divider_drag_viewport = None;
|
||||
}
|
||||
_ => self.sidebar_press = None,
|
||||
}
|
||||
self.transcript_view.bidi_layout = tui.terminal.bidi_layout;
|
||||
self.transcript_view.agent_links = self
|
||||
@@ -1055,15 +1050,6 @@ impl App {
|
||||
if let TuiEvent::Mouse(mouse) = &event
|
||||
&& self.handle_workspace_mouse(tui, *mouse)
|
||||
{
|
||||
if mouse.kind == MouseEventKind::Down(MouseButton::Left)
|
||||
&& self
|
||||
.agents_overview
|
||||
.workspace
|
||||
.divider_drag_viewport
|
||||
.is_some()
|
||||
{
|
||||
self.refresh_link_hover(tui)?;
|
||||
}
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
if matches!(&event, TuiEvent::Key(_))
|
||||
|
||||
@@ -1361,12 +1361,53 @@ async fn workspace_navigation_preserves_the_draft_and_reading_position() -> Resu
|
||||
use crossterm::event::MouseEventKind::Down;
|
||||
use crossterm::event::MouseEventKind::Drag;
|
||||
use crossterm::event::MouseEventKind::Moved;
|
||||
use crossterm::event::MouseEventKind::Up;
|
||||
let mut pointers = Vec::new();
|
||||
for column in [divider.x, center.right(), center.right() + 1] {
|
||||
for column in [
|
||||
divider.x,
|
||||
center.right(),
|
||||
center.right() + 1,
|
||||
center.right() + 2,
|
||||
] {
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, mouse(Moved, column)))
|
||||
.await?;
|
||||
pointers.push(tui.link_hover.shape);
|
||||
}
|
||||
// Grab the padding cell. The divider should keep its one-column offset.
|
||||
let gutter = center.right() + 1;
|
||||
for event in [
|
||||
mouse(Down(Left), gutter),
|
||||
mouse(Drag(Left), gutter + 5),
|
||||
TuiEvent::FocusGained,
|
||||
] {
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, event)).await?;
|
||||
}
|
||||
crate::app::test_support::side_frame(&mut app, &mut tui, three_panes)?;
|
||||
let preview = app.conversation_frame.command_center.unwrap().right();
|
||||
assert_eq!(preview, center.right() + 5);
|
||||
let accent = tui.terminal.previous_buffer()[(preview, 4)]
|
||||
.style()
|
||||
.add_modifier
|
||||
.contains(ratatui::style::Modifier::BOLD);
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, mouse(Up(Left), gutter + 8)))
|
||||
.await?;
|
||||
crate::app::test_support::side_frame(&mut app, &mut tui, three_panes)?;
|
||||
let released = app.conversation_frame.command_center.unwrap().right();
|
||||
assert_eq!(released, center.right() + 8);
|
||||
// Focus loss can replace a release. Continue to route the focus event.
|
||||
for event in [
|
||||
mouse(Down(Left), released),
|
||||
mouse(Drag(Left), center.right()),
|
||||
TuiEvent::FocusLost,
|
||||
TuiEvent::FocusGained,
|
||||
] {
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, event)).await?;
|
||||
}
|
||||
crate::app::test_support::side_frame(&mut app, &mut tui, three_panes)?;
|
||||
let interrupted = app.conversation_frame.command_center.unwrap().right();
|
||||
assert_eq!(interrupted, center.right());
|
||||
insta::assert_snapshot!(format!("preview {preview}, highlighted {accent}, release {released}, focus loss {interrupted}"), @"preview 41, highlighted true, release 44, focus loss 36");
|
||||
// Reserve the simulated three-pane size for the sidebar press, after the preview draws.
|
||||
tui.screen_size_for_event(&TuiEvent::Resize(three_panes))?;
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, mouse(Down(Left), divider.x)))
|
||||
.await?;
|
||||
@@ -1420,7 +1461,7 @@ async fn workspace_navigation_preserves_the_draft_and_reading_position() -> Resu
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, event)).await?;
|
||||
pointers.push(tui.link_hover.shape);
|
||||
}
|
||||
insta::assert_snapshot!(format!("{pointers:?}"), @"[Resize, Resize, Default, Resize, Resize]");
|
||||
insta::assert_snapshot!(format!("{pointers:?}"), @"[Resize, Resize, Resize, Default, Resize, Resize]");
|
||||
let release = mouse(crossterm::event::MouseEventKind::Up(Left), resized);
|
||||
crate::boxed_future!(app.handle_tui_event(&mut tui, &mut server, release)).await?;
|
||||
crate::app::test_support::side_frame(&mut app, &mut tui, three_panes)?;
|
||||
|
||||
@@ -26,8 +26,6 @@ use ratatui::layout::Constraint;
|
||||
use ratatui::layout::Layout;
|
||||
use ratatui::layout::Rect;
|
||||
|
||||
use ratatui::style::Style;
|
||||
|
||||
const CENTER_WIDTH: u16 = 36;
|
||||
// One column for the divider and one for padding before the conversation.
|
||||
const GUTTER_WIDTH: u16 = 2;
|
||||
@@ -47,8 +45,7 @@ pub(super) struct Workspace {
|
||||
focus: Option<Pane>,
|
||||
pub(super) motion: super::pane_motion::PaneMotion,
|
||||
pub(super) fraction: Option<f64>,
|
||||
width: Option<u16>,
|
||||
pub(super) divider_drag_viewport: Option<Rect>,
|
||||
pub(super) width: Option<u16>,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
@@ -74,7 +71,33 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn center_width(width: i32, total: u16) -> u16 {
|
||||
width.clamp(
|
||||
24,
|
||||
i32::from(total.saturating_sub(MIN_CHAT_WIDTH + GUTTER_WIDTH).max(24)),
|
||||
) as u16
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Both blank gutter cells belong to the painted outer divider. The task
|
||||
/// details separator inside the center is not a workspace resize handle.
|
||||
pub(super) fn center_divider_area(&self, viewport: Rect) -> Option<Rect> {
|
||||
let workspace = &self.agents_overview.workspace;
|
||||
if !workspace.is_open()
|
||||
|| self.overlay.is_some()
|
||||
|| self.chat_widget.has_active_view()
|
||||
|| viewport.width < MIN_SPLIT_WIDTH
|
||||
|| workspace.fraction != Some(1.0)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let center = self.conversation_frame.command_center?;
|
||||
// Between input and paint, only a captured drag may be ahead of the painted center.
|
||||
(center.right().saturating_add(GUTTER_WIDTH) <= viewport.right()
|
||||
&& (self.divider_drag.is_some() || self.workspace_areas(viewport).0 == Some(center)))
|
||||
.then(|| Rect::new(center.right(), center.y, GUTTER_WIDTH, center.height))
|
||||
}
|
||||
|
||||
pub(super) fn workspace_center_owns_input(&self) -> bool {
|
||||
self.agents_overview.workspace.focus == Some(Pane::Center)
|
||||
&& self.overlay.is_none()
|
||||
@@ -97,16 +120,16 @@ impl App {
|
||||
|
||||
pub(super) fn workspace_areas(&self, viewport: Rect) -> (Option<Rect>, Option<Rect>) {
|
||||
if viewport.width >= MIN_SPLIT_WIDTH {
|
||||
let preferred = self
|
||||
.divider_drag
|
||||
.and_then(|drag| drag.center_preview(viewport))
|
||||
.or(self.agents_overview.workspace.width)
|
||||
.unwrap_or(CENTER_WIDTH);
|
||||
let width = center_width(i32::from(preferred), viewport.width);
|
||||
let [center, _, conversation] = Layout::horizontal([
|
||||
Constraint::Length(
|
||||
(f64::from(
|
||||
self.agents_overview
|
||||
.workspace
|
||||
.width
|
||||
.unwrap_or(CENTER_WIDTH)
|
||||
.min(viewport.width.saturating_sub(MIN_CHAT_WIDTH + GUTTER_WIDTH)),
|
||||
) * self.agents_overview.workspace.fraction.unwrap_or(1.0))
|
||||
.round() as u16,
|
||||
(f64::from(width) * self.agents_overview.workspace.fraction.unwrap_or(1.0))
|
||||
.round() as u16,
|
||||
),
|
||||
Constraint::Length(GUTTER_WIDTH),
|
||||
Constraint::Min(MIN_CHAT_WIDTH),
|
||||
@@ -227,7 +250,6 @@ impl App {
|
||||
}
|
||||
if view.is_complete() {
|
||||
self.agents_overview.workspace.focus = None;
|
||||
self.agents_overview.workspace.divider_drag_viewport = None;
|
||||
self.focus_workspace_composer(tui);
|
||||
self.conversation_frame = Default::default();
|
||||
}
|
||||
@@ -235,51 +257,14 @@ impl App {
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
|
||||
pub(super) fn workspace_divider_at(&self, viewport: Rect, mouse: MouseEvent) -> bool {
|
||||
self.agents_overview.workspace.is_open()
|
||||
&& !self.chat_widget.has_active_view()
|
||||
&& viewport.contains((mouse.column, mouse.row).into())
|
||||
&& self
|
||||
.conversation_frame
|
||||
.command_center
|
||||
.is_some_and(|center| {
|
||||
mouse.column == center.right()
|
||||
&& self.workspace_areas(viewport).0 == Some(center)
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn handle_workspace_mouse(&mut self, tui: &mut Tui, mouse: MouseEvent) -> bool {
|
||||
if !self.agents_overview.workspace.is_open()
|
||||
|| self.overlay.is_some()
|
||||
|| self.chat_widget.has_active_view()
|
||||
{
|
||||
self.agents_overview.workspace.divider_drag_viewport = None;
|
||||
return false;
|
||||
}
|
||||
let viewport: Rect = tui.terminal.last_known_screen_size.into();
|
||||
if mouse.kind == MouseEventKind::Down(MouseButton::Left)
|
||||
&& self.workspace_divider_at(viewport, mouse)
|
||||
{
|
||||
self.agents_overview.workspace.divider_drag_viewport = Some(viewport);
|
||||
return true;
|
||||
}
|
||||
if matches!(
|
||||
mouse.kind,
|
||||
MouseEventKind::Drag(MouseButton::Left) | MouseEventKind::Up(MouseButton::Left)
|
||||
) && self.agents_overview.workspace.divider_drag_viewport.take() == Some(viewport)
|
||||
{
|
||||
let max = viewport
|
||||
.width
|
||||
.saturating_sub(MIN_CHAT_WIDTH + GUTTER_WIDTH)
|
||||
.max(24);
|
||||
self.agents_overview.workspace.width =
|
||||
Some(mouse.column.saturating_sub(viewport.x).clamp(24, max));
|
||||
if mouse.kind == MouseEventKind::Drag(MouseButton::Left) {
|
||||
self.agents_overview.workspace.divider_drag_viewport = Some(viewport);
|
||||
}
|
||||
tui.frame_requester().schedule_frame();
|
||||
return true;
|
||||
}
|
||||
let center_was_focused = self.agents_overview.workspace.focus == Some(Pane::Center);
|
||||
// The press chose the owner. Let its selection finish even outside its pane.
|
||||
if matches!(mouse.kind, MouseEventKind::Drag(_) | MouseEventKind::Up(_)) {
|
||||
@@ -349,12 +334,5 @@ impl App {
|
||||
frame.set_cursor_style(view.cursor_style(area));
|
||||
}
|
||||
}
|
||||
if conversation.is_some() {
|
||||
for y in center.y..center.bottom() {
|
||||
frame.buffer[(center.right(), y)]
|
||||
.set_symbol("│")
|
||||
.set_style(Style::default().dim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,21 +245,25 @@ impl App {
|
||||
|| self.overlay.is_some()
|
||||
{
|
||||
PointerShape::Default
|
||||
} else if let Some(drag) = self.divider_drag {
|
||||
sidebar_divider = !drag.is_center();
|
||||
PointerShape::Resize
|
||||
} else if self.conversation_focus_available(tui)
|
||||
&& (self.divider_drag.is_some()
|
||||
|| tui.link_hover.mouse.is_some_and(|mouse| {
|
||||
self.conversation_frame
|
||||
.divider_area()
|
||||
.is_some_and(|area| area.contains((mouse.column, mouse.row).into()))
|
||||
&& self.divider_is_settled(tui, viewport)
|
||||
}))
|
||||
&& tui.link_hover.mouse.is_some_and(|mouse| {
|
||||
self.conversation_frame
|
||||
.divider_area()
|
||||
.is_some_and(|area| area.contains((mouse.column, mouse.row).into()))
|
||||
&& self.divider_is_settled(tui, viewport)
|
||||
})
|
||||
{
|
||||
sidebar_divider = true;
|
||||
PointerShape::Resize
|
||||
} else if self.agents_overview.workspace.divider_drag_viewport == Some(viewport)
|
||||
|| self
|
||||
.hover_pointer(tui, tui.link_hover.mouse)
|
||||
.is_some_and(|mouse| self.workspace_divider_at(viewport, mouse))
|
||||
} else if self
|
||||
.hover_pointer(tui, tui.link_hover.mouse)
|
||||
.is_some_and(|mouse| {
|
||||
self.center_divider_area(viewport)
|
||||
.is_some_and(|area| area.contains((mouse.column, mouse.row).into()))
|
||||
})
|
||||
{
|
||||
PointerShape::Resize
|
||||
} else if self.chat_widget.no_modal_or_popup_active()
|
||||
@@ -272,7 +276,9 @@ impl App {
|
||||
} else {
|
||||
PointerShape::Default
|
||||
};
|
||||
if sidebar_divider != tui.link_hover.sidebar_divider {
|
||||
if sidebar_divider != tui.link_hover.sidebar_divider
|
||||
|| (shape == PointerShape::Resize) != (tui.link_hover.shape == PointerShape::Resize)
|
||||
{
|
||||
tui.link_hover.sidebar_divider = sidebar_divider;
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
|
||||
@@ -322,14 +322,15 @@ impl App {
|
||||
self.conversation_frame.sidebar_input =
|
||||
self.sidebar().map(sidebar::SidebarPane::input_state);
|
||||
let divider = self.conversation_frame.divider_area();
|
||||
if self.divider_drag.is_some_and(|drag| {
|
||||
divider.is_none()
|
||||
|| !drag.matches(content, self)
|
||||
|| !self.conversation_focus_available(tui)
|
||||
}) {
|
||||
if self
|
||||
.divider_drag
|
||||
.is_some_and(|drag| !drag.valid(viewport, self, tui))
|
||||
{
|
||||
self.divider_drag = None;
|
||||
}
|
||||
let highlight_divider = self.pane_resize.is_some() || tui.link_hover.sidebar_divider;
|
||||
let highlight_center =
|
||||
tui.link_hover.shape == tui::PointerShape::Resize && !tui.link_hover.sidebar_divider;
|
||||
let pointer = tui
|
||||
.link_hover
|
||||
.mouse
|
||||
@@ -432,6 +433,9 @@ impl App {
|
||||
frames: &frames,
|
||||
keymap: &self.keymap,
|
||||
resize_hint,
|
||||
resize_preview: self
|
||||
.divider_drag
|
||||
.is_some_and(super::side_pane::DividerDrag::is_live_preview),
|
||||
image_protocol: sidebar_image_protocol,
|
||||
},
|
||||
) && focused
|
||||
@@ -629,7 +633,12 @@ impl App {
|
||||
}
|
||||
self.conversation_frame.sidebar_targets = std::mem::take(&mut sidebar_targets);
|
||||
if let Some(divider) = divider {
|
||||
side_pane::paint_divider(frame, divider.x, self.divider_drag, highlight_divider);
|
||||
side_pane::paint_divider(
|
||||
frame,
|
||||
divider.x,
|
||||
self.divider_drag.filter(|drag| !drag.is_center()),
|
||||
highlight_divider,
|
||||
);
|
||||
}
|
||||
self.conversation_frame.close_buttons = Default::default();
|
||||
if let Some(close) = self.sidebar().and_then(|pane| pane.close.as_ref()) {
|
||||
@@ -657,6 +666,14 @@ impl App {
|
||||
}
|
||||
if let Some(center) = center {
|
||||
self.paint_command_center(frame, center, available, &frames);
|
||||
if available.is_some() {
|
||||
side_pane::paint_divider(
|
||||
frame,
|
||||
center.right(),
|
||||
self.divider_drag.filter(|drag| drag.is_center()),
|
||||
highlight_center,
|
||||
);
|
||||
}
|
||||
}
|
||||
self.paint_centered_dialog(frame);
|
||||
})?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Lay out paired conversations and resize the shared sidebar split.
|
||||
//! Lay out paired conversations and handle pointer resizing for both workspace dividers.
|
||||
|
||||
use super::App;
|
||||
use super::agents_overview::AGENTS_OVERVIEW_VIEW_ID;
|
||||
@@ -36,9 +36,12 @@ pub(super) const MIN_SPLIT_WIDTH: u16 = 100;
|
||||
pub(super) const RESIZE_HINT: &str = "Resize · ←/h →/l · Shift+←/→ 10 cols · Enter/Esc done";
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
struct ResizeTarget {
|
||||
displayed: Option<ThreadId>,
|
||||
content: SidebarContent,
|
||||
enum ResizeTarget {
|
||||
Sidebar {
|
||||
displayed: Option<ThreadId>,
|
||||
content: SidebarContent,
|
||||
},
|
||||
CommandCenter,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -59,12 +62,49 @@ pub(super) struct DividerDrag {
|
||||
}
|
||||
|
||||
impl DividerDrag {
|
||||
pub(super) fn matches(&self, screen: Rect, app: &App) -> bool {
|
||||
screen == self.screen && app.sidebar_resize_target() == Some(self.target)
|
||||
pub(super) fn is_live_preview(self) -> bool {
|
||||
!self.guide_only && self.width != self.initial_width
|
||||
}
|
||||
|
||||
fn percent(&self) -> Option<u8> {
|
||||
(self.width != self.initial_width).then(|| width_percent(self.width, self.screen.width))
|
||||
pub(super) fn is_center(self) -> bool {
|
||||
self.target == ResizeTarget::CommandCenter
|
||||
}
|
||||
|
||||
pub(super) fn center_preview(self, viewport: Rect) -> Option<u16> {
|
||||
(self.is_center() && !self.guide_only && self.screen == viewport).then_some(self.width)
|
||||
}
|
||||
|
||||
fn matches_sidebar(self, area: Rect, app: &App) -> bool {
|
||||
area == self.screen && app.sidebar_resize_target() == Some(self.target)
|
||||
}
|
||||
|
||||
pub(super) fn valid(self, viewport: Rect, app: &App, tui: &Tui) -> bool {
|
||||
match self.target {
|
||||
ResizeTarget::CommandCenter => {
|
||||
self.screen == viewport && app.center_divider_area(viewport).is_some()
|
||||
}
|
||||
ResizeTarget::Sidebar { .. } => {
|
||||
app.conversation_frame.divider_area().is_some()
|
||||
&& !app.conversation_frame.has_caller_inset()
|
||||
&& !(app.zoomed_thread.is_some()
|
||||
&& app.zoomed_thread == app.current_displayed_thread_id())
|
||||
&& app.conversation_focus_available(tui)
|
||||
&& self.matches_sidebar(app.workspace_chat_area(viewport), app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn width_at(self, column: u16) -> u16 {
|
||||
let delta = i32::from(column) - i32::from(self.press);
|
||||
match self.target {
|
||||
ResizeTarget::Sidebar { .. } => {
|
||||
sidebar_width(i32::from(self.initial_width) - delta, self.screen.width)
|
||||
}
|
||||
ResizeTarget::CommandCenter => super::conversation_workspace::center_width(
|
||||
i32::from(self.initial_width) + delta,
|
||||
self.screen.width,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +215,9 @@ pub(super) fn sidebar_areas(app: &App, tui: &Tui, area: Rect, fraction: f64) ->
|
||||
let preview = app
|
||||
.divider_drag
|
||||
.filter(|drag| {
|
||||
!drag.guide_only && drag.matches(area, app) && app.conversation_focus_available(tui)
|
||||
!drag.guide_only
|
||||
&& drag.matches_sidebar(area, app)
|
||||
&& app.conversation_focus_available(tui)
|
||||
})
|
||||
.map(|drag| drag.width);
|
||||
let saved = app.local_settings.tui.sidebar_width_percent;
|
||||
@@ -205,7 +247,7 @@ pub(super) fn sidebar_areas(app: &App, tui: &Tui, area: Rect, fraction: f64) ->
|
||||
|
||||
impl App {
|
||||
fn sidebar_resize_target(&self) -> Option<ResizeTarget> {
|
||||
Some(ResizeTarget {
|
||||
Some(ResizeTarget::Sidebar {
|
||||
displayed: self.current_displayed_thread_id(),
|
||||
content: self.sidebar()?.visible_content()?,
|
||||
})
|
||||
@@ -371,83 +413,118 @@ impl App {
|
||||
true
|
||||
}
|
||||
|
||||
async fn finish_divider_drag(&mut self, drag: DividerDrag) {
|
||||
if drag.width == drag.initial_width {
|
||||
return;
|
||||
}
|
||||
match drag.target {
|
||||
ResizeTarget::CommandCenter => self.agents_overview.workspace.width = Some(drag.width),
|
||||
ResizeTarget::Sidebar { .. } => {
|
||||
let total = drag.screen.width;
|
||||
if self
|
||||
.save_sidebar_width(width_percent(drag.width, total))
|
||||
.await
|
||||
{
|
||||
self.exact_sidebar_width = Some((total, drag.width));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn handle_divider_event(
|
||||
&mut self,
|
||||
tui: &mut Tui,
|
||||
event: &TuiEvent,
|
||||
) -> Result<bool> {
|
||||
let mouse = match event {
|
||||
TuiEvent::Mouse(mouse) if self.conversation_focus_available(tui) => mouse,
|
||||
TuiEvent::Draw if self.conversation_focus_available(tui) => return Ok(false),
|
||||
_ => {
|
||||
if self.divider_drag.take().is_some() {
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
return Ok(false);
|
||||
}
|
||||
};
|
||||
if matches!(mouse.kind, Down(_)) && self.divider_drag.take().is_some() {
|
||||
let viewport: Rect = tui.terminal.last_known_screen_size.into();
|
||||
if self
|
||||
.divider_drag
|
||||
.is_some_and(|drag| !drag.valid(viewport, self, tui))
|
||||
{
|
||||
// Never apply a stale drag to a different pane or conversation.
|
||||
self.divider_drag = None;
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
match mouse.kind {
|
||||
Down(Left) => {
|
||||
let Some(divider) = self
|
||||
.conversation_frame
|
||||
.divider_area()
|
||||
.filter(|area| area.contains((mouse.column, mouse.row).into()))
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
let screen = tui.prepare_draw_size()?.into();
|
||||
if !self.divider_is_settled(tui, screen) {
|
||||
// The painted divider still owns this press while it moves.
|
||||
if let Some(mut drag) = self.divider_drag {
|
||||
let released = match event {
|
||||
TuiEvent::Mouse(mouse) if mouse.kind == Drag(Left) => {
|
||||
let width = drag.width_at(mouse.column);
|
||||
if drag.width != width {
|
||||
drag.width = width;
|
||||
self.divider_drag = Some(drag);
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
let Some(target) = self.sidebar_resize_target() else {
|
||||
return Ok(false);
|
||||
};
|
||||
let screen = self.workspace_chat_area(screen);
|
||||
let width = screen.right() - divider.right();
|
||||
self.divider_drag = Some(DividerDrag {
|
||||
target,
|
||||
screen,
|
||||
press: mouse.column,
|
||||
initial_width: width,
|
||||
width,
|
||||
// Both panes share the divider. Reflowing either can move terminal-owned
|
||||
// image pixels across it, so defer both layouts until release.
|
||||
guide_only: !tui.retained_images.is_empty(),
|
||||
});
|
||||
self.cancel_pending_key_chord();
|
||||
}
|
||||
Drag(Left) | Up(Left) => {
|
||||
let Some(mut drag) = self.divider_drag.take() else {
|
||||
return Ok(false);
|
||||
};
|
||||
let screen = tui.terminal.last_known_screen_size.into();
|
||||
if drag.matches(self.workspace_chat_area(screen), self)
|
||||
&& visible_split(self, tui, screen).is_some()
|
||||
{
|
||||
let width = i32::from(drag.initial_width) + i32::from(drag.press)
|
||||
- i32::from(mouse.column);
|
||||
let total = drag.screen.width;
|
||||
let width = sidebar_width(width, total);
|
||||
let changed = drag.width != width;
|
||||
drag.width = width;
|
||||
if mouse.kind == Drag(Left) {
|
||||
self.divider_drag = Some(drag);
|
||||
if !changed {
|
||||
return Ok(true);
|
||||
}
|
||||
} else if let Some(percent) = drag.percent()
|
||||
&& self.save_sidebar_width(percent).await
|
||||
{
|
||||
self.exact_sidebar_width = Some((total, width));
|
||||
}
|
||||
TuiEvent::Mouse(mouse) if mouse.kind == Up(Left) => {
|
||||
// The release can have a newer position than the last motion report.
|
||||
drag.width = drag.width_at(mouse.column);
|
||||
true
|
||||
}
|
||||
TuiEvent::Draw if !crate::tui::mouse_capture_disabled() => return Ok(false),
|
||||
TuiEvent::FocusGained => return Ok(false),
|
||||
TuiEvent::Resize(size) if Rect::from(*size) == viewport => return Ok(false),
|
||||
TuiEvent::Key(key) if key.kind == KeyEventKind::Release => return Ok(false),
|
||||
TuiEvent::Mouse(mouse) if !matches!(mouse.kind, Down(_)) => return Ok(false),
|
||||
// A focus loss or a fresh press can replace a missing release. Keep
|
||||
// the last valid width, then route the interrupting event normally.
|
||||
TuiEvent::FocusLost
|
||||
| TuiEvent::Key(_)
|
||||
| TuiEvent::Paste(_)
|
||||
| TuiEvent::Resize(_)
|
||||
| TuiEvent::Resume
|
||||
| TuiEvent::Draw
|
||||
| TuiEvent::Mouse(_) => false,
|
||||
};
|
||||
self.divider_drag = None;
|
||||
self.finish_divider_drag(drag).await;
|
||||
self.refresh_link_hover(tui)?;
|
||||
tui.frame_requester().schedule_frame();
|
||||
if released {
|
||||
return Ok(true);
|
||||
}
|
||||
_ => return Ok(false),
|
||||
}
|
||||
let TuiEvent::Mouse(mouse) = event else {
|
||||
return Ok(false);
|
||||
};
|
||||
if mouse.kind != Down(Left) {
|
||||
return Ok(false);
|
||||
}
|
||||
let point = (mouse.column, mouse.row).into();
|
||||
let (target, screen, width) = if let Some(area) = self
|
||||
.center_divider_area(viewport)
|
||||
.filter(|area| area.contains(point))
|
||||
{
|
||||
(ResizeTarget::CommandCenter, viewport, area.x - viewport.x)
|
||||
} else if let Some(divider) = self
|
||||
.conversation_frame
|
||||
.divider_area()
|
||||
.filter(|area| area.contains(point) && self.conversation_focus_available(tui))
|
||||
{
|
||||
let screen = tui.prepare_draw_size()?.into();
|
||||
if !self.divider_is_settled(tui, screen) {
|
||||
// The painted divider still owns this press while it moves.
|
||||
return Ok(true);
|
||||
}
|
||||
let Some(target) = self.sidebar_resize_target() else {
|
||||
return Ok(false);
|
||||
};
|
||||
let screen = self.workspace_chat_area(screen);
|
||||
(target, screen, screen.right() - divider.right())
|
||||
} else {
|
||||
return Ok(false);
|
||||
};
|
||||
self.divider_drag = Some(DividerDrag {
|
||||
target,
|
||||
screen,
|
||||
press: mouse.column,
|
||||
initial_width: width,
|
||||
width,
|
||||
// Reflow can move terminal-owned image pixels across a divider.
|
||||
guide_only: !tui.retained_images.is_empty(),
|
||||
});
|
||||
self.cancel_pending_key_chord();
|
||||
self.refresh_link_hover(tui)?;
|
||||
tui.frame_requester().schedule_frame();
|
||||
Ok(true)
|
||||
}
|
||||
@@ -567,7 +644,10 @@ pub(super) fn paint_divider(
|
||||
// of retained pixels can erase the rest of that terminal row.
|
||||
let guide = drag
|
||||
.filter(|drag| drag.guide_only)
|
||||
.map_or(divider, |drag| drag.screen.right() - drag.width - GAP);
|
||||
.map_or(divider, |drag| match drag.target {
|
||||
ResizeTarget::CommandCenter => drag.screen.x + drag.width,
|
||||
ResizeTarget::Sidebar { .. } => drag.screen.right() - drag.width - GAP,
|
||||
});
|
||||
let style = if highlight_divider || drag.is_some() {
|
||||
crate::style::accent_style()
|
||||
} else {
|
||||
|
||||
@@ -100,6 +100,7 @@ pub(super) struct DocumentRenderOptions<'a> {
|
||||
pub(super) motion: MotionMode,
|
||||
pub(super) frames: &'a tui::FrameRequester,
|
||||
pub(super) keymap: &'a RuntimeKeymap,
|
||||
pub(super) resize_preview: bool,
|
||||
pub(super) resize_hint: Option<&'a str>,
|
||||
pub(super) image_protocol: Option<ImageProtocol>,
|
||||
}
|
||||
@@ -392,6 +393,7 @@ impl Document {
|
||||
frames,
|
||||
keymap,
|
||||
resize_hint,
|
||||
resize_preview,
|
||||
image_protocol,
|
||||
} = options;
|
||||
let buf = &mut *frame.buffer;
|
||||
@@ -519,6 +521,7 @@ impl Document {
|
||||
line_starts,
|
||||
target,
|
||||
} => {
|
||||
view.set_document_resize_preview(resize_preview);
|
||||
view.set_keymap_bindings(keymap);
|
||||
if view.tick_selection(cells) {
|
||||
frames.schedule_frame_in(std::time::Duration::from_millis(45));
|
||||
|
||||
@@ -1348,8 +1348,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
if let Err(err) = app.render_startup_frame(tui, &app_event_rx) {
|
||||
return shutdown_on_startup_error(app_server, &mut other_backends, err).await;
|
||||
}
|
||||
let tui_events = tui.event_stream();
|
||||
tokio::pin!(tui_events);
|
||||
let mut tui_events = tui.input_stream();
|
||||
tracing::info!(
|
||||
duration_ms = %(startup_elapsed_before_app + startup_started_at.elapsed()).as_millis(),
|
||||
bootstrap_ms = %bootstrap_ms,
|
||||
@@ -1633,6 +1632,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
cloud_inventory_owner = cloud_owner;
|
||||
cloud_inventory_poll.reset();
|
||||
}
|
||||
tui_events.coalesce_divider_drags = app.divider_drag.is_some();
|
||||
let control = select! {
|
||||
// Leave the previous frame visible and let other app work run between batches.
|
||||
Some(transition) = std::future::ready(app.pending_input_drain), if app.pending_input_drain.is_some() => {
|
||||
|
||||
@@ -4861,7 +4861,6 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
|
||||
tui.terminal = terminal_at(wide);
|
||||
keys!(toggle);
|
||||
let path = app.local_settings.user_config_path.clone();
|
||||
let before = std::fs::read(&path).ok();
|
||||
let divider_at = |tui: &tui::Tui, y| {
|
||||
(0..wide.width)
|
||||
.find(|&x| tui.terminal.previous_buffer()[(x, y)].symbol() == "│")
|
||||
@@ -4869,6 +4868,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
|
||||
};
|
||||
let mut previews = Vec::new();
|
||||
for with_image in [false, true] {
|
||||
let before = std::fs::read(&path).ok();
|
||||
if with_image {
|
||||
let image_path = app.config.codex_home.join("divider.png");
|
||||
image::RgbaImage::from_pixel(8, 16, image::Rgba([80, 30, 20, 255]))
|
||||
@@ -4934,7 +4934,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
|
||||
.await?;
|
||||
} else {
|
||||
assert!(columns.iter().all(|x| *x == divider - 1));
|
||||
// A fresh transcript press cancels a drag whose release was lost.
|
||||
// A fresh press ends a drag whose release was lost, keeping its last width.
|
||||
for kind in [MouseEventKind::Down(left), MouseEventKind::Up(left)] {
|
||||
boxed_future!(app.handle_tui_event(
|
||||
&mut tui,
|
||||
@@ -4943,7 +4943,20 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
assert_eq!(std::fs::read(&path).ok(), before);
|
||||
side_frame(&mut app, &mut tui, wide)?;
|
||||
assert_eq!(divider_at(&tui, 0), divider - 1);
|
||||
// The release position wins even if no intervening motion was delivered.
|
||||
for (kind, x) in [
|
||||
(MouseEventKind::Down(left), divider - 1),
|
||||
(MouseEventKind::Up(left), divider),
|
||||
] {
|
||||
boxed_future!(app.handle_tui_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
mouse(kind, x, /*row*/ 4)
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
side_frame(&mut app, &mut tui, wide)?;
|
||||
assert_eq!(divider_at(&tui, 0), divider);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ pub(crate) enum DocumentPosition {
|
||||
}
|
||||
|
||||
impl TranscriptView {
|
||||
/// During a live resize, wrap the already rendered file instead of parsing it at every width.
|
||||
pub(crate) fn set_document_resize_preview(&mut self, active: bool) {
|
||||
self.cache.set_document_resize_preview(active);
|
||||
}
|
||||
|
||||
pub(crate) fn document_position(&self) -> DocumentPosition {
|
||||
match self.position {
|
||||
Position::Reading(anchor) => DocumentPosition::Offset(anchor.offset),
|
||||
|
||||
@@ -118,6 +118,7 @@ fn is_rich_user_prompt(cell: &dyn HistoryCell, mode: HistoryRenderMode) -> bool
|
||||
#[derive(Default)]
|
||||
pub(super) struct LayoutCache {
|
||||
entries: Vec<CachedLayout>,
|
||||
document_resize_preview: bool,
|
||||
frame: u64,
|
||||
render_state: Option<RenderState>,
|
||||
}
|
||||
@@ -331,6 +332,14 @@ impl TranscriptView {
|
||||
}
|
||||
|
||||
impl LayoutCache {
|
||||
pub(super) fn set_document_resize_preview(&mut self, active: bool) {
|
||||
if self.document_resize_preview && !active {
|
||||
// Markdown tables and other width-dependent content need an exact final layout.
|
||||
self.clear();
|
||||
}
|
||||
self.document_resize_preview = active;
|
||||
}
|
||||
|
||||
pub(super) fn has_mutable_source(&self) -> bool {
|
||||
self.entries.iter().any(|entry| {
|
||||
entry
|
||||
@@ -366,14 +375,20 @@ impl LayoutCache {
|
||||
let source = Arc::downgrade(cell);
|
||||
let animation_tick = cell.transcript_animation_tick();
|
||||
if let Some(index) = self.entries.iter().position(|entry| {
|
||||
entry.width == width
|
||||
(entry.width == width || self.document_resize_preview)
|
||||
&& entry.presentation == presentation
|
||||
&& entry.source.ptr_eq(&source)
|
||||
&& (entry.rendered_frame == self.frame
|
||||
|| (cell.has_stable_transcript_height()
|
||||
&& entry.animation_tick == animation_tick))
|
||||
}) {
|
||||
let layout = Arc::clone(&self.entries[index].layout);
|
||||
let entry = &mut self.entries[index];
|
||||
if entry.width != width {
|
||||
// Keep the document's styled source and links while the divider moves.
|
||||
entry.layout = Arc::new(entry.layout.rewrap(width));
|
||||
entry.width = width;
|
||||
}
|
||||
let layout = Arc::clone(&entry.layout);
|
||||
if index + 1 != self.entries.len() {
|
||||
let entry = self.entries.remove(index);
|
||||
self.entries.push(entry);
|
||||
|
||||
@@ -78,6 +78,18 @@ fn layouts_refresh_for_width_animation_and_mutable_frames() {
|
||||
cell.renders.load(Ordering::Relaxed),
|
||||
3 + usize::from(mutable)
|
||||
);
|
||||
// A document drag wraps cached text across widths. On release, restore
|
||||
// width-specific rendering even when the last preview had the same width.
|
||||
let before_drag = cell.renders.load(Ordering::Relaxed);
|
||||
cache.set_document_resize_preview(/*active*/ true);
|
||||
let narrow = get(&mut cache, /*width*/ 4);
|
||||
assert!(narrow.row_count() > 1);
|
||||
let wide = get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(wide.row_count(), 1);
|
||||
assert_eq!(cell.renders.load(Ordering::Relaxed), before_drag);
|
||||
cache.set_document_resize_preview(/*active*/ false);
|
||||
get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(cell.renders.load(Ordering::Relaxed), before_drag + 1);
|
||||
crate::terminal_palette::with_test_default_colors(
|
||||
crate::terminal_probe::DefaultColors {
|
||||
fg: (12, 34, 56),
|
||||
@@ -88,7 +100,7 @@ fn layouts_refresh_for_width_animation_and_mutable_frames() {
|
||||
get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(
|
||||
cell.renders.load(Ordering::Relaxed),
|
||||
4 + usize::from(mutable)
|
||||
5 + usize::from(mutable)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
+8
-10
@@ -1175,21 +1175,19 @@ impl Tui {
|
||||
}
|
||||
|
||||
pub fn event_stream(&self) -> Pin<Box<dyn Stream<Item = TuiEvent> + Send + 'static>> {
|
||||
#[cfg(unix)]
|
||||
let stream = TuiEventStream::new(
|
||||
Box::pin(self.input_stream())
|
||||
}
|
||||
|
||||
pub(crate) fn input_stream(&self) -> TuiEventStream {
|
||||
TuiEventStream::new(
|
||||
self.event_broker.clone(),
|
||||
self.draw_tx.subscribe(),
|
||||
self.terminal_focused.clone(),
|
||||
#[cfg(unix)]
|
||||
self.suspend_context.clone(),
|
||||
#[cfg(unix)]
|
||||
self.alt_screen_active.clone(),
|
||||
);
|
||||
#[cfg(not(unix))]
|
||||
let stream = TuiEventStream::new(
|
||||
self.event_broker.clone(),
|
||||
self.draw_tx.subscribe(),
|
||||
self.terminal_focused.clone(),
|
||||
);
|
||||
Box::pin(stream)
|
||||
)
|
||||
}
|
||||
|
||||
/// Overlays and in-place history edits can flush a replay before the scheduled draw.
|
||||
|
||||
@@ -59,6 +59,9 @@ pub struct EventBroker<S: EventSource = CrosstermEventSource> {
|
||||
|
||||
struct BrokerInput<S: EventSource> {
|
||||
source: EventBrokerState<S>,
|
||||
// The first non-drag report (or end of input) belongs to the next poll, even
|
||||
// if a different stream takes over the shared terminal.
|
||||
lookahead: Poll<Option<EventResult>>,
|
||||
// Deliver focus changes captured during a thread transition before newer input.
|
||||
pending_focus: VecDeque<Event>,
|
||||
drain_failed: bool,
|
||||
@@ -95,6 +98,7 @@ impl<S: EventSource + Default> EventBroker<S> {
|
||||
state: Mutex::new(BrokerInput {
|
||||
source: EventBrokerState::Start,
|
||||
pending_focus: VecDeque::new(),
|
||||
lookahead: Poll::Pending,
|
||||
drain_failed: false,
|
||||
}),
|
||||
resume_events_tx,
|
||||
@@ -112,6 +116,12 @@ impl<S: EventSource + Default> EventBroker<S> {
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
state.source = EventBrokerState::Paused;
|
||||
// Only focus reports survive an input boundary.
|
||||
if let Poll::Ready(Some(Ok(event @ (Event::FocusGained | Event::FocusLost)))) =
|
||||
std::mem::replace(&mut state.lookahead, Poll::Pending)
|
||||
{
|
||||
state.pending_focus.push_back(event);
|
||||
}
|
||||
}
|
||||
|
||||
/// Called with the event source paused. A terminal error must not expose stale keys.
|
||||
@@ -189,6 +199,13 @@ impl EventSource for CrosstermEventSource {
|
||||
}
|
||||
}
|
||||
|
||||
// Bound the amount of input consumed before the event loop can service a draw or backend event.
|
||||
const MAX_DRAG_REPORTS_PER_POLL: usize = 64;
|
||||
|
||||
fn is_left_drag(event: &Event) -> bool {
|
||||
matches!(event, Event::Mouse(mouse) if mouse.kind == crossterm::event::MouseEventKind::Drag(crossterm::event::MouseButton::Left))
|
||||
}
|
||||
|
||||
/// TuiEventStream is a struct for reading TUI events (draws and user input).
|
||||
/// Each instance has its own draw subscription (the draw channel is broadcast, so
|
||||
/// multiple receivers are fine), while crossterm input is funneled through a
|
||||
@@ -202,6 +219,7 @@ pub struct TuiEventStream<S: EventSource + Default + Unpin = CrosstermEventSourc
|
||||
resume_stream: WatchStream<()>,
|
||||
terminal_focused: Arc<AtomicBool>,
|
||||
poll_draw_first: bool,
|
||||
pub(crate) coalesce_divider_drags: bool,
|
||||
#[cfg(unix)]
|
||||
suspend_context: crate::tui::job_control::SuspendContext,
|
||||
#[cfg(unix)]
|
||||
@@ -223,6 +241,7 @@ impl<S: EventSource + Default + Unpin> TuiEventStream<S> {
|
||||
resume_stream,
|
||||
terminal_focused,
|
||||
poll_draw_first: false,
|
||||
coalesce_divider_drags: false,
|
||||
#[cfg(unix)]
|
||||
suspend_context,
|
||||
#[cfg(unix)]
|
||||
@@ -254,7 +273,10 @@ impl<S: EventSource + Default + Unpin> TuiEventStream<S> {
|
||||
return Poll::Ready(self.map_crossterm_event(event));
|
||||
}
|
||||
}
|
||||
let events = match state.source.active_event_source_mut() {
|
||||
let BrokerInput {
|
||||
source, lookahead, ..
|
||||
} = &mut *state;
|
||||
let events = match source.active_event_source_mut() {
|
||||
Some(events) => events,
|
||||
None => {
|
||||
drop(state);
|
||||
@@ -266,8 +288,29 @@ impl<S: EventSource + Default + Unpin> TuiEventStream<S> {
|
||||
}
|
||||
}
|
||||
};
|
||||
match Pin::new(events).poll_next(cx) {
|
||||
Poll::Ready(Some(Ok(event))) => Some(event),
|
||||
let next = match std::mem::replace(lookahead, Poll::Pending) {
|
||||
Poll::Ready(next) => Poll::Ready(next),
|
||||
Poll::Pending => Pin::new(&mut *events).poll_next(cx),
|
||||
};
|
||||
match next {
|
||||
Poll::Ready(Some(Ok(mut event))) => {
|
||||
if self.coalesce_divider_drags && is_left_drag(&event) {
|
||||
// Only a captured divider uses absolute positions. Selection and
|
||||
// scrolling need their full path. Bound work per poll for fairness.
|
||||
for _ in 1..MAX_DRAG_REPORTS_PER_POLL {
|
||||
match Pin::new(&mut *events).poll_next(cx) {
|
||||
Poll::Ready(Some(Ok(next))) if is_left_drag(&next) => {
|
||||
event = next
|
||||
}
|
||||
boundary => {
|
||||
*lookahead = boundary;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(event)
|
||||
}
|
||||
Poll::Ready(Some(Err(_))) | Poll::Ready(None) => {
|
||||
state.source = EventBrokerState::Start;
|
||||
return Poll::Ready(None);
|
||||
@@ -506,6 +549,38 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn only_captured_divider_motion_is_coalesced_and_stops_at_input_boundaries() {
|
||||
let (broker, handle, _draw_tx, draw_rx, terminal_focused) = setup();
|
||||
let mut stream = make_stream(broker, draw_rx, terminal_focused);
|
||||
let left = crossterm::event::MouseButton::Left;
|
||||
let mouse = |kind, column| MouseEvent {
|
||||
kind,
|
||||
column,
|
||||
row: 4,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
let drag = |column| mouse(MouseEventKind::Drag(left), column);
|
||||
for column in [10, 11, 12, 13] {
|
||||
handle.send(Ok(Event::Mouse(drag(column))));
|
||||
}
|
||||
handle.send(Ok(Event::FocusLost));
|
||||
handle.send(Ok(Event::Mouse(drag(14))));
|
||||
let release = mouse(MouseEventKind::Up(left), 15);
|
||||
handle.send(Ok(Event::Mouse(release)));
|
||||
handle.send(Ok(Event::Key(KeyCode::Enter.into())));
|
||||
|
||||
// Outside divider capture, even adjacent selection motions stay distinct.
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Mouse(m)) if m == drag(10)));
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Mouse(m)) if m == drag(11)));
|
||||
stream.coalesce_divider_drags = true;
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Mouse(m)) if m == drag(13)));
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::FocusLost)));
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Mouse(m)) if m == drag(14)));
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Mouse(m)) if m == release));
|
||||
assert!(matches!(stream.next().await, Some(TuiEvent::Key(k)) if k.code == KeyCode::Enter));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn focus_lost_is_forwarded_and_updates_terminal_state() {
|
||||
let (broker, handle, _draw_tx, draw_rx, terminal_focused) = setup();
|
||||
|
||||
Reference in New Issue
Block a user