Add tests for multiline movement

This commit is contained in:
Kovid Goyal 2020-02-25 11:24:17 +05:30
parent 1690e6933f
commit 42d1a4755a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 27 additions and 9 deletions

View File

@ -312,6 +312,7 @@ HANDLER(handle_move_event) {
Screen *screen = w->render_data.screen;
detect_url(screen, x, y);
bool mouse_cell_changed = x != w->mouse_pos.cell_x || y != w->mouse_pos.cell_y;
bool cell_half_changed = in_left_half_of_cell != w->mouse_pos.in_left_half_of_cell;
w->mouse_pos.cell_x = x; w->mouse_pos.cell_y = y;
w->mouse_pos.in_left_half_of_cell = in_left_half_of_cell;
bool in_tracking_mode = (
@ -320,7 +321,7 @@ HANDLER(handle_move_event) {
bool has_terminal_select_modifiers = modifiers == (int)OPT(terminal_select_modifiers) || modifiers == ((int)OPT(rectangle_select_modifiers) | (int)OPT(terminal_select_modifiers));
bool handle_in_kitty = !in_tracking_mode || has_terminal_select_modifiers;
if (handle_in_kitty) {
handle_mouse_movement_in_kitty(w, button, mouse_cell_changed);
handle_mouse_movement_in_kitty(w, button, mouse_cell_changed | cell_half_changed);
} else {
if (!mouse_cell_changed) return;
int sz = encode_mouse_event(w, MAX(0, button), button >=0 ? DRAG : MOVE, 0);
@ -700,7 +701,7 @@ send_mock_mouse_event_to_window(PyObject *self UNUSED, PyObject *args) {
Window *w = PyCapsule_GetPointer(capsule, "Window");
if (!w) return NULL;
if (clear_clicks) clear_click_queue(w);
bool mouse_cell_changed = x != w->mouse_pos.cell_x || y != w->mouse_pos.cell_y;
bool mouse_cell_changed = x != w->mouse_pos.cell_x || y != w->mouse_pos.cell_y || w->mouse_pos.in_left_half_of_cell != in_left_half_of_cell;
w->mouse_pos.x = 10 * x; w->mouse_pos.y = 20 * y;
w->mouse_pos.cell_x = x; w->mouse_pos.cell_y = y;
w->mouse_pos.in_left_half_of_cell = in_left_half_of_cell;

View File

@ -1603,13 +1603,13 @@ iteration_data(const Screen *self, const Selection *sel, IterationData *ans, int
// empty selection
if (start->x == end->x && start_y == end_y && start->in_left_half_of_cell == end->in_left_half_of_cell) return;
bool left_to_right = selection_is_left_to_right(sel);
if (sel->rectangle_select) {
// empty selection
if (start->x == end->x && (!start->in_left_half_of_cell || end->in_left_half_of_cell)) return;
ans->y = MIN(start_y, end_y); ans->y_limit = MAX(start_y, end_y) + 1;
index_type x, x_limit;
bool left_to_right = selection_is_left_to_right(sel);
if (start->x == end->x) {
x = start->x; x_limit = start->x + 1;
@ -1643,12 +1643,12 @@ iteration_data(const Screen *self, const Selection *sel, IterationData *ans, int
ans->first.x = end->x + (end->in_left_half_of_cell ? 0 : 1);
ans->first.x_limit = 1 + start->x + (start->in_left_half_of_cell ? -1 : 0);
}
} else if (start_y < end_y) {
} else if (start_y < end_y) { // downwards
ans->body.x_limit = line_limit;
ans->first.x_limit = line_limit;
ans->first.x = start->x + (start->in_left_half_of_cell ? 0 : 1);
ans->last.x_limit = 1 + end->x + (end->in_left_half_of_cell ? -1 : 0);
} else {
} else { // upwards
ans->body.x_limit = line_limit;
ans->first.x_limit = line_limit;
ans->first.x = end->x + (end->in_left_half_of_cell ? 0 : 1);

View File

@ -67,8 +67,11 @@ class TestMouse(BaseTest):
clear_click_queue=True
)
def move(x=0, y=0, button=-1):
def move(x=0, y=0, button=-1, q=None):
ev(x=x, y=y, button=button)
if q is not None:
s = sel()
self.ae(s, q, '{!r} != {!r} after movement to x={} y={}'.format(s, q, x, y))
def multi_click(x=0, y=0, count=2):
while count > 0:
@ -78,16 +81,30 @@ class TestMouse(BaseTest):
def scroll(x=0, y=0, up=True):
move(x=x, y=y, button=-2 if up else -3)
# Simple, click, move, release test
# Single line click, move, release test
init()
press()
move(x=3.6)
self.ae(sel(), '1234')
move(x=3.6, q='1234')
release(x=3.6)
self.ae(sel(), '1234')
press(x=4), release(x=0.6)
self.ae(sel(), '234')
# multi line movement
init()
press(x=2, y=2)
move(x=2, y=1, q='890ab')
move(x=2.6, y=1, q='90ab')
move(y=1, q='67890ab')
move(x=4, y=1, q='0ab')
move(x=4.6, y=1, q='ab')
move(q='1234567890ab')
move(x=2, y=3, q='cdefg')
move(y=3, q='cde')
move(x=0.6, y=3, q='cdef')
move(x=2.6, y=3, q='cdefgh')
move(x=4.6, y=3, q='cdefghij')
# Single cell select
init()
press(), release(1)