mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
More mouse interaction tests
This commit is contained in:
@@ -349,6 +349,11 @@ distance(double x1, double y1, double x2, double y2) {
|
||||
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
|
||||
}
|
||||
|
||||
static inline void
|
||||
clear_click_queue(Window *w) {
|
||||
w->click_queue.length = 0;
|
||||
}
|
||||
|
||||
HANDLER(add_click) {
|
||||
ClickQueue *q = &w->click_queue;
|
||||
if (q->length == CLICK_QUEUE_SZ) { memmove(q->clicks, q->clicks + 1, sizeof(Click) * (CLICK_QUEUE_SZ - 1)); q->length--; }
|
||||
@@ -683,12 +688,14 @@ test_encode_mouse(PyObject *self UNUSED, PyObject *args) {
|
||||
static PyObject*
|
||||
send_mock_mouse_event_to_window(PyObject *self UNUSED, PyObject *args) {
|
||||
PyObject *capsule;
|
||||
int button, modifiers, is_release;
|
||||
int button, modifiers, is_release, clear_clicks;
|
||||
unsigned int x, y;
|
||||
if (!PyArg_ParseTuple(args, "O!iipII", &PyCapsule_Type, &capsule, &button, &modifiers, &is_release, &x, &y)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "O!iipIIp", &PyCapsule_Type, &capsule, &button, &modifiers, &is_release, &x, &y, &clear_clicks)) return NULL;
|
||||
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;
|
||||
w->mouse_pos.x = 10 * x; w->mouse_pos.y = 20 * y;
|
||||
w->mouse_pos.cell_x = x; w->mouse_pos.cell_y = y;
|
||||
if (button < 0) {
|
||||
if (button == -2) do_drag_scroll(w, true);
|
||||
|
||||
@@ -76,7 +76,7 @@ class BaseTest(TestCase):
|
||||
|
||||
def create_screen(self, cols=5, lines=5, scrollback=5, cell_width=10, cell_height=20, options=None):
|
||||
if options is None:
|
||||
options = {'scrollback_pager_history_size': 1024}
|
||||
options = {'scrollback_pager_history_size': 1024, 'click_interval': 0.5}
|
||||
options = Options(merge_configs(defaults._asdict(), options))
|
||||
set_options(options)
|
||||
c = Callbacks()
|
||||
|
||||
@@ -11,8 +11,8 @@ from kitty.fast_data_types import (
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
def send_mouse_event(window, button=-1, modifiers=0, is_release=False, x=0, y=0):
|
||||
send_mock_mouse_event_to_window(window, button, modifiers, is_release, x, y)
|
||||
def send_mouse_event(window, button=-1, modifiers=0, is_release=False, x=0, y=0, clear_click_queue=False):
|
||||
send_mock_mouse_event_to_window(window, button, modifiers, is_release, x, y, clear_click_queue)
|
||||
|
||||
|
||||
class TestMouse(BaseTest):
|
||||
@@ -23,7 +23,7 @@ class TestMouse(BaseTest):
|
||||
ev = partial(send_mouse_event, w)
|
||||
|
||||
def sel():
|
||||
return s.text_for_selection()[0]
|
||||
return ''.join(s.text_for_selection())
|
||||
|
||||
def init():
|
||||
s.reset()
|
||||
@@ -33,9 +33,43 @@ class TestMouse(BaseTest):
|
||||
s.draw('fghij')
|
||||
s.draw('klmno')
|
||||
|
||||
def press(x=0, y=0):
|
||||
ev(GLFW_MOUSE_BUTTON_LEFT, x=x, y=y)
|
||||
|
||||
def release(x=0, y=0):
|
||||
ev(GLFW_MOUSE_BUTTON_LEFT, x=x, y=y, is_release=True, clear_click_queue=True)
|
||||
|
||||
def move(x=0, y=0):
|
||||
ev(x=x, y=y)
|
||||
|
||||
def multi_click(x=0, y=0, count=2):
|
||||
while count > 0:
|
||||
count -= 1
|
||||
ev(GLFW_MOUSE_BUTTON_LEFT, x=x, y=y)
|
||||
|
||||
# Simple, click, move, release test
|
||||
init()
|
||||
ev(GLFW_MOUSE_BUTTON_LEFT)
|
||||
ev(x=3)
|
||||
press()
|
||||
move(x=3)
|
||||
self.ae(sel(), '1234')
|
||||
ev(GLFW_MOUSE_BUTTON_LEFT, x=3, is_release=True)
|
||||
release(x=3)
|
||||
self.ae(sel(), '1234')
|
||||
|
||||
# Multi-line click release
|
||||
init()
|
||||
press(1, 1), release(3, 2)
|
||||
self.ae(sel(), '7890abcd')
|
||||
press(3, 4), release(2, 2)
|
||||
self.ae(sel(), 'cdefghijklmn')
|
||||
|
||||
# Word select with drag
|
||||
s.reset()
|
||||
s.draw('ab cd')
|
||||
s.draw(' f gh')
|
||||
s.draw(' stuv')
|
||||
multi_click(x=1)
|
||||
self.ae(sel(), 'ab')
|
||||
move(3)
|
||||
self.ae(sel(), 'ab cd')
|
||||
release(3, 1)
|
||||
self.ae(sel(), 'ab cd f gh')
|
||||
|
||||
Reference in New Issue
Block a user