Skip to content

Commit

Permalink
fix: when inserting before tab do not scroll, memory errors on resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Oct 28, 2024
1 parent 8c42dab commit 4e18543
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions headers/gapbuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void resize(gap_buf &a, unsigned size)
{
a.buffer = (char*)realloc(a.buffer, size);
if (a.gpe < a.cpt - 1) {
memmove(a.buffer + size - a.gpe - 1, a.buffer + a.gpe, a.cpt - a.gpe);
a.gpe = size - a.gpe - 1;
memmove(a.buffer + size - a.len + a.gps, a.buffer + a.gpe + 1, a.len - a.gps);
a.gpe = size - a.len + a.gps - 1;
} else
a.gpe = size - 1;
a.cpt = size;
Expand Down
15 changes: 10 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ int main(int argc, char *argv[])

// TODO: use real tab
case KEY_TAB:
winsnstr(text_win, " ", 8);
wmove(text_win, y, x + 8);
insert_s(*it, x, " ", 8);
winsnstr(text_win, " ", 8 - x % 8);
wmove(text_win, y, x + 8 - x % 8);
insert_s(*it, x, " ", 8 - x % 8);
break;

default:
Expand All @@ -260,9 +260,14 @@ int main(int argc, char *argv[])
x = 0;
wmove(text_win, y, 0);
wclrtoeol(text_win);
} if (at(*it, rx) == '\t') {
waddnwstr(text_win, s, 1);
if (x % 8 >= 7)
winsch(text_win, '\t');
} else {
wins_nwstr(text_win, s, 1);
wmove(text_win, y, x + 1);
}
wins_nwstr(text_win, s, 1);
wmove(text_win, y, x + 1);
len = wcstombs(s2, s, 4);
insert_s(*it, rx, s2, len);
if (len > 1)
Expand Down

0 comments on commit 4e18543

Please sign in to comment.