Skip to content

Commit

Permalink
fix: go to EOL with non-sequencial tabs (completed d28b970)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Oct 27, 2024
1 parent 782b3a4 commit 8c42dab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
25 changes: 9 additions & 16 deletions utils/key_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,18 @@ void eol()
if (it->len - ofx <= maxx) // line fits in screen
wmove(text_win, y, it->len - ofx - 1);
else { // wrap line
unsigned bytes = 0;
while (bytes < it->len) {
unsigned nbytes = dchar2bytes(maxx - 1, bytes, *it) - bytes;
if (nbytes + bytes >= it->len)
break;
wrap.push_back(rx); // rx was changed
ofx += (long)wrap.back();
bytes += nbytes;
}
wmove(text_win, y, 0);
wclrtoeol(text_win);

// estimation without accounting first tab in line
unsigned vis = (it->len - ofx) % (maxx - 1);
// get how many bytes leave 'vis' displayed characters to be printed
// it->len - ofx - vis = maxx - 1 (mul by wrapped times)
unsigned bytes = dchar2bytes(it->len - ofx - vis, 0, *it);
// preliminary calculation of displayed characters in line
wrap.push_back(bytes - calc_offset_act(bytes, 0, *it));
// tab was cut in wrapping, go back to print
if (at(*it, bytes - 1) == '\t' && maxx - wrap.back() > 0) {
--bytes;
vis += 8;
}
print_line(*it, bytes, it->len);
ofx = it->len - vis + maxx - 1 - wrap.back();
//ofx = calc_offset_dis(maxx - 1, 0, *it) + maxx - 1;
//ofx += wrap;
}
}

Expand Down
14 changes: 11 additions & 3 deletions utils/sizes.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ long calc_offset_dis(unsigned dx, const gap_buf &buf)
// displayed characters dx to bytes
unsigned dchar2bytes(unsigned dx, unsigned from, const gap_buf &buf)
{
unsigned x = 0, i = from;
while (x < dx && i < buf.len)
get_off(x, i, buf);
unsigned x = 0, nx = 0, ni = from, i = from;
while (x < dx && i < buf.len) {
get_off(nx, ni, buf);
if (nx <= dx && ni <= buf.len) {
rx = x = nx;
i = ni;
} else {
rx--;
break;
}
}
return i;
}

Expand Down

0 comments on commit 8c42dab

Please sign in to comment.