Skip to content

Commit

Permalink
fix: move to mid of tab
Browse files Browse the repository at this point in the history
now the cursor is moved to the end of tab
  • Loading branch information
ikozyris committed Oct 27, 2024
1 parent e4cc093 commit 782b3a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ int main(int argc, char *argv[])
++it;
wrap.clear();
ofx = 0; // invalidated
if (y == (maxy - 1) && ry < curnum)
if (y == maxy - 1 && ry < curnum)
scrolldown();
else {
wmove(text_win, y + 1, x);
ofx = calc_offset_dis(x, 0, *it);
ofx = calc_offset_dis(x, *it);
wmove(text_win, y + 1, x = rx);
}
break;

Expand All @@ -112,9 +112,9 @@ int main(int argc, char *argv[])
} if (y == 0 && ofy != 0)
scrollup();
else if (y != 0) {
wmove(text_win, y - 1, x);
--it;
ofx = calc_offset_dis(x, 0, *it);
--it;
ofx = calc_offset_dis(x, *it);
wmove(text_win, y - 1, x = rx);
}
wrap.clear();
break;
Expand Down
10 changes: 6 additions & 4 deletions utils/sizes.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ inline void get_off(unsigned &x, unsigned &i, const gap_buf &buf)
i++;
}

// offset until displayed x from from bytes in buf
long calc_offset_dis(unsigned dx, unsigned from, const gap_buf &buf)
// returns offset until displayed x from from bytes in buf (bytes - dx)
// global rx becomes the dx where counting stopped at
long calc_offset_dis(unsigned dx, const gap_buf &buf)
{
unsigned x = 0, i = from;
unsigned x = 0, i = 0;
while (x < dx && i < buf.len)
get_off(x, i, buf);
return (long)i - (long)from - (long)x;
rx = x;
return (long)i - (long)x;
}

// displayed characters dx to bytes
Expand Down

0 comments on commit 782b3a4

Please sign in to comment.