Lines
100 %
Functions
Branches
//! A press on the title row of the front window and the motion that follows move it, the
//! release keeps it, and the keyboard mode takes no part of it.
use super::overlap::{FRONT_AT, left_click, left_drag, left_release, overlapped, place_window};
use super::report_chart::{call_for, chart_requests, echoed, show, with_table};
use super::window_keys::drawn_kitty_chart;
use crate::app::App;
use crate::event::{Intent, apply};
use crate::focus::{FocusTarget, current_focus};
use crate::test_support::draw_into;
use crate::window::WindowId;
use ratatui::crossterm::event::{KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
use rpc::chart::ChartBackend;
use std::time::{Duration, Instant};
use tvui::{FrameMode, Place};
pub(super) fn place_of(app: &App, id: WindowId) -> Place {
let place = app.desktop.place_of(id, app.desktop_rect());
place.expect("the window is open")
}
pub(super) fn front_id(app: &App) -> WindowId {
app.front_window().expect("a front window")
fn title_cell(dx: u16) -> (u16, u16) {
let x = u16::try_from(FRONT_AT.x).unwrap_or_default() + dx;
(x, u16::try_from(FRONT_AT.y).unwrap_or_default())
#[test]
fn a_title_drag_moves_the_window_by_the_motion_and_the_release_keeps_it() {
let (mut app, _, front) = overlapped();
let (start, now) = (title_cell(10), Instant::now());
left_click(&mut app, start, now);
assert_eq!(app.frame_state(front).mode, FrameMode::Dragging);
left_drag(&mut app, (start.0 + 4, start.1 + 3), now);
assert_eq!(
place_of(&app, front),
Place {
x: 24,
y: 8,
..FRONT_AT
);
left_drag(&mut app, (start.0 + 6, start.1 + 5), now);
left_release(&mut app, (start.0 + 6, start.1 + 5), now);
x: 26,
y: 10,
assert!(!app.dragging());
assert_eq!(app.frame_state(front).mode, FrameMode::Active);
fn a_press_and_release_on_the_title_without_motion_change_nothing() {
let (at, now) = (title_cell(10), Instant::now());
left_click(&mut app, at, now);
left_release(&mut app, at, now);
assert_eq!(place_of(&app, front), FRONT_AT);
assert!(app.take_outbound().is_empty());
fn the_window_hangs_off_the_left_with_one_column_inside() {
let corner = title_cell(FRONT_AT.width - 1);
left_click(&mut app, corner, Instant::now());
left_drag(&mut app, (0, corner.1), Instant::now());
left_release(&mut app, (0, corner.1), Instant::now());
let place = place_of(&app, front);
assert_eq!(place.x, 1 - i32::from(FRONT_AT.width));
assert_eq!(place.y, FRONT_AT.y);
fn the_top_edge_stays_on_the_desktop() {
let at = title_cell(10);
left_click(&mut app, at, Instant::now());
left_drag(&mut app, (at.0, 0), Instant::now());
assert_eq!(place_of(&app, front).y, i32::from(app.desktop_rect().y));
fn the_window_stays_where_the_grab_holds_it_under_the_pointer() {
let at = title_cell(7);
left_drag(&mut app, (40, 9), Instant::now());
assert_eq!(place_of(&app, front).x, 40 - 7);
assert_eq!(place_of(&app, front).y, 9);
fn a_drag_disarms_the_double_click_of_the_press_that_began_it() {
left_drag(&mut app, (at.0 + 4, at.1), now);
left_release(&mut app, (at.0 + 4, at.1), now);
assert!(!app.desktop.window(front).is_some_and(|w| w.zoomed));
fn a_rear_title_press_raises_and_the_next_press_drags() {
let (mut app, rear, _) = overlapped();
let at = (8, 2);
assert_eq!(app.front_window(), Some(rear));
left_click(&mut app, at, Instant::now() + Duration::from_secs(2));
left_drag(&mut app, (11, 4), Instant::now());
assert_eq!(place_of(&app, rear).x, 5);
assert_eq!(place_of(&app, rear).y, 4);
fn motion_and_release_do_nothing_in_the_keyboard_mode() {
app.begin_size_move();
let before = place_of(&app, front);
left_drag(&mut app, (40, 14), Instant::now());
left_release(&mut app, (40, 14), Instant::now());
assert_eq!(place_of(&app, front), before);
assert_eq!(current_focus(&app), FocusTarget::Drag);
fn a_motion_with_no_drag_begun_by_the_mouse_does_nothing() {
fn other_buttons_do_not_move_the_held_window() {
let right = MouseEvent {
kind: MouseEventKind::Drag(MouseButton::Right),
column: 40,
row: 14,
modifiers: KeyModifiers::NONE,
};
crate::mouse::handle_mouse(&mut app, right, Instant::now());
pub(super) fn mouse_at(
app: &mut App,
kind: MouseEventKind,
(column, row): (u16, u16),
(size, when): ((u16, u16), Instant),
) {
let mouse = MouseEvent {
kind,
column,
row,
crate::mouse::handle_mouse(app, mouse, when);
draw_into(app, size.0, size.1);
#[tokio::test]
async fn the_release_fetches_the_chart_again_and_a_press_alone_does_not() {
let (mut app, sent) = with_table(60, 24, ChartBackend::Halfblocks);
show(&mut app);
let id = front_id(&app);
place_window(
&mut app,
id,
x: 10,
y: 5,
width: 30,
height: 10,
},
draw_into(&mut app, 60, 24);
let before = chart_requests(&app).len();
let (at, left) = ((20, 5), MouseButton::Left);
let (size, later) = ((60, 24), Instant::now() + Duration::from_secs(2));
let first = (size, Instant::now());
let second = (size, later);
mouse_at(&mut app, MouseEventKind::Down(left), at, first);
mouse_at(&mut app, MouseEventKind::Up(left), at, first);
assert_eq!(chart_requests(&app).len(), before);
mouse_at(&mut app, MouseEventKind::Down(left), at, second);
mouse_at(&mut app, MouseEventKind::Drag(left), (22, 6), second);
mouse_at(&mut app, MouseEventKind::Up(left), (22, 6), second);
assert_eq!(chart_requests(&app).len(), before + 1);
assert!(echoed(&mut app, &sent).await.contains(&call_for(280, 160)));
async fn the_kitty_image_goes_with_the_first_motion_not_with_the_press() {
let (mut app, image) = drawn_kitty_chart();
draw_into(&mut app, 40, 20);
let (at, left) = ((10, 1), MouseButton::Left);
let size = ((40, 20), Instant::now());
mouse_at(&mut app, MouseEventKind::Down(left), at, size);
mouse_at(&mut app, MouseEventKind::Drag(left), (11, 1), size);
assert_eq!(app.take_outbound(), vec![tvui::kitty_delete(image)]);
apply(&mut app, Intent::DragCancel);