mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-28 04:13:44 +00:00
Add some basic tests for multicell rewrap
This commit is contained in:
parent
2e4bab6f49
commit
cf5f6e97e8
2 changed files with 66 additions and 24 deletions
|
|
@ -155,30 +155,6 @@ update_tracked_cursors(Rewrap *r, index_type num_cells, index_type y, index_type
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fast_copy_src_to_dest(Rewrap *r) {
|
||||
CPUCell *c; index_type mc_width;
|
||||
while (r->src_x < r->src_x_limit) {
|
||||
if (r->dest_x >= r->dest_xnum) next_dest_line(r, true);
|
||||
index_type num = MIN(r->src_x_limit - r->src_x, r->dest_xnum - r->dest_x);
|
||||
bool do_copy = true;
|
||||
if (num && (c = &r->src.cpu_cells[r->src_x + num - 1])->is_multicell && c->x != (mc_width = mcd_x_limit(c)) - 1) {
|
||||
// we have a split multicell at the right edge of the copy region
|
||||
if (num > mc_width) num -= mc_width;
|
||||
else {
|
||||
if (mc_width > r->dest_xnum) do_copy = false;
|
||||
else {
|
||||
r->dest_x = r->dest_xnum;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (do_copy) copy_range(&r->src, r->src_x, &r->dest, r->dest_x, num);
|
||||
update_tracked_cursors(r, num, r->src_y, r->src_x_limit);
|
||||
r->src_x += num; r->dest_x += num;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
find_space_in_dest_line(Rewrap *r, index_type num_cells) {
|
||||
while (r->dest_x + num_cells <= r->dest_xnum) {
|
||||
|
|
@ -210,6 +186,7 @@ copy_multiline_extra_lines(Rewrap *r, CPUCell *src_cell, index_type mc_width) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
multiline_copy_src_to_dest(Rewrap *r) {
|
||||
CPUCell *c; index_type mc_width;
|
||||
|
|
@ -231,6 +208,37 @@ multiline_copy_src_to_dest(Rewrap *r) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fast_copy_src_to_dest(Rewrap *r) {
|
||||
CPUCell *c; index_type mc_width;
|
||||
while (r->src_x < r->src_x_limit) {
|
||||
if (r->dest_x >= r->dest_xnum) {
|
||||
next_dest_line(r, true);
|
||||
if (r->current_dest_line_has_multiline_cells) {
|
||||
multiline_copy_src_to_dest(r);
|
||||
return;
|
||||
}
|
||||
}
|
||||
index_type num = MIN(r->src_x_limit - r->src_x, r->dest_xnum - r->dest_x);
|
||||
bool do_copy = true;
|
||||
if (num && (c = &r->src.cpu_cells[r->src_x + num - 1])->is_multicell && c->x != (mc_width = mcd_x_limit(c)) - 1) {
|
||||
// we have a split multicell at the right edge of the copy region
|
||||
if (num > mc_width) num = MIN(r->src_x_limit - r->src_x - mc_width, num);
|
||||
else {
|
||||
if (mc_width > r->dest_xnum) do_copy = false;
|
||||
else {
|
||||
r->dest_x = r->dest_xnum;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (do_copy) copy_range(&r->src, r->src_x, &r->dest, r->dest_x, num);
|
||||
update_tracked_cursors(r, num, r->src_y, r->src_x_limit);
|
||||
r->src_x += num; r->dest_x += num;
|
||||
}
|
||||
}
|
||||
|
||||
static index_type
|
||||
rewrap_inner(Rewrap *r) {
|
||||
setup_line(r->text_cache, r->src_xnum, &r->src); setup_line(r->text_cache, r->dest_xnum, &r->dest);
|
||||
|
|
|
|||
|
|
@ -459,3 +459,37 @@ def test_multicell(self: TestMulticell) -> None:
|
|||
multicell(s, 'a', scale=3)
|
||||
multicell(s, 'b', scale=2)
|
||||
ta('\x1b]66;w=1:s=3;a\x07\x1b]66;w=1:s=2;b\x07')
|
||||
|
||||
# rewrap with multicells
|
||||
o = s.lines, s.columns
|
||||
def reset():
|
||||
s.resize(*o)
|
||||
s.reset()
|
||||
|
||||
reset()
|
||||
multicell(s, 'a', scale=2)
|
||||
before = as_ansi()
|
||||
s.resize(s.lines + 1, s.columns)
|
||||
self.ae(before.rstrip(), as_ansi().rstrip())
|
||||
|
||||
reset()
|
||||
s.draw('a' * (s.columns - 2) + '😛' + 'bb')
|
||||
s.resize(s.lines, s.columns-1)
|
||||
self.ae('\x1b[maaaa\x1b[m😛bb', as_ansi().rstrip())
|
||||
reset()
|
||||
s.draw('a' * (s.columns - 2) + '😛' + 'bb')
|
||||
s.resize(s.lines, s.columns-2)
|
||||
self.ae('\x1b[maaaa\x1b[m😛bb', as_ansi().rstrip())
|
||||
reset()
|
||||
s.draw('a' * (s.columns - 2) + '😛' + 'bb')
|
||||
s.resize(s.lines, s.columns-3)
|
||||
self.ae('\x1b[maaa\x1b[ma😛\x1b[mbb', as_ansi().rstrip()) # ]]]]]]]
|
||||
|
||||
reset()
|
||||
multicell(s, 'a', scale=3)
|
||||
s.draw('b'*(s.columns-3))
|
||||
s.resize(s.lines, s.columns-1)
|
||||
self.ae('\x1b[m\x1b]66;w=1:s=3;a\x07bb\x1b[mb', as_ansi().rstrip()) # ]]
|
||||
ac(0, 0, is_multicell=True)
|
||||
ac(0, 1, is_multicell=True)
|
||||
ac(3, 1, is_multicell=False, text='b')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue