diff --git a/kitty/line.h b/kitty/line.h index 684d3ea03..981324ceb 100644 --- a/kitty/line.h +++ b/kitty/line.h @@ -9,7 +9,6 @@ #include "text-cache.h" -// TODO: Test setting of ch_and_idx to make sure the right ch_is_idx bit is set // TODO: Test multiple OS windows with decorations also with changing font size and test on macOS and Linux for re-alloc // TODO: Test handling of calt ligatures with scale see is_group_calt_ligature() // TODO: Handle selection with multicell diff --git a/kitty/screen.c b/kitty/screen.c index 2e2508372..8c831d179 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -5260,6 +5260,20 @@ cpu_cells(Screen *self, PyObject *args) { return Py_NewRef(ans); } +static PyObject* +test_ch_and_idx(PyObject *self UNUSED, PyObject *val) { + CPUCell c = {0}; + if (PyLong_Check(val)) { + unsigned long x = PyLong_AsUnsignedLong(val); + c.ch_and_idx = x; + } else if (PyTuple_Check(val)) { + c.ch_is_idx = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(val, 0)); + c.ch_or_idx = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(val, 1)); + } + unsigned long is_idx = c.ch_is_idx, idx = c.ch_or_idx, ca = c.ch_and_idx; + return Py_BuildValue("kkk", is_idx, idx, ca); +} + static PyMethodDef methods[] = { METHODB(test_create_write_buffer, METH_NOARGS), METHODB(test_commit_write_buffer, METH_VARARGS), @@ -5411,6 +5425,7 @@ PyTypeObject Screen_Type = { static PyMethodDef module_methods[] = { {"is_emoji_presentation_base", (PyCFunction)screen_is_emoji_presentation_base, METH_O, ""}, {"truncate_point_for_length", (PyCFunction)screen_truncate_point_for_length, METH_VARARGS, ""}, + {"test_ch_and_idx", test_ch_and_idx, METH_O, ""}, {NULL} /* Sentinel */ }; diff --git a/kitty_tests/multicell.py b/kitty_tests/multicell.py index a9390ed5f..b74748f4b 100644 --- a/kitty_tests/multicell.py +++ b/kitty_tests/multicell.py @@ -2,7 +2,7 @@ # License: GPLv3 Copyright: 2024, Kovid Goyal -from kitty.fast_data_types import TEXT_SIZE_CODE, wcswidth +from kitty.fast_data_types import TEXT_SIZE_CODE, wcswidth, test_ch_and_idx from . import BaseTest, parse_bytes from . import draw_multicell as multicell @@ -37,6 +37,13 @@ def test_multicell(self: TestMulticell) -> None: if assertions[key] != val: raise AssertionError(f'{msg}{assertions[key]!r} != {val!r}') + self.ae(test_ch_and_idx(0), (0, 0, 0)) + self.ae(test_ch_and_idx(1), (0, 1, 1)) + self.ae(test_ch_and_idx(0x80000000), (1, 0, 0x80000000)) + self.ae(test_ch_and_idx(0x80000001), (1, 1, 0x80000001)) + self.ae(test_ch_and_idx((1, 0)), (1, 0, 0x80000000)) + self.ae(test_ch_and_idx((1, 3)), (1, 3, 0x80000003)) + ae('x') ae('y') ae('width')