Skip to content

Commit

Permalink
fix: go back from tab
Browse files Browse the repository at this point in the history
by creating prevword(), which will be used later what the function says it does

Also create release definition, seperately from the debug
  • Loading branch information
ikozyris committed Oct 24, 2024
1 parent 28ad86c commit cea7f27
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CC = g++ --std=c++20
# -DHIGHLIGHT Enable syntax highlighting
# -lncursesw Links to ncurses library for wide characters (unicode)

OPTIM = -Ofast -flto -march=native
OPTIM = -Ofast -flto -march=native -DRELEASE
DEBUG = -g #-DDEBUG
#CXXFLAGS = -Wall -Wextra -pedantic-errors $(DEBUG) -DHIGHLIGHT -lncursesw # Debug only
CXXFLAGS = -Wall -Wextra -pedantic $(OPTIM) -DHIGHLIGHT -lncursesw
Expand Down
4 changes: 3 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ int main(int argc, char *argv[])
rx = x + ofx;
mv_curs(*it, rx);

#ifndef RELEASE
stats();
#endif
#ifdef DEBUG
print_text(y); // debug only
stats();
wmove(text_win, y, x);
#endif
//goto stop;
Expand Down
11 changes: 6 additions & 5 deletions utils/key_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ void stats()
unsigned sumlen = 0;
for (auto &i : text)
sumlen += i.len;
//snprintf(_tmp, min(maxx, 256), "maxx %u len %u ofx %ld wrap %u x: %u | y: %u ",
// maxx, it->len, ofx, !wrap.empty() ? wrap.back() : 0, x, y);
#ifndef RELEASE
snprintf(_tmp, min(maxx, 256), "maxx %u len %u ofx %ld wrap %u x: %u | y: %u ",
maxx, it->len, ofx, !wrap.empty() ? wrap.back() : 0, x, y);
#else
snprintf(_tmp, min(maxx, 256), "length %u y %u x %u sum len %u lines %lu ofx %ld ",
it->len, ry, x, sumlen, curnum, ofx);
#endif
print2header(_tmp, 1);
free(_tmp);
wmove(text_win, y, x);
Expand Down Expand Up @@ -226,10 +229,8 @@ void left()
#endif
wmove(text_win, y, maxx - 1);
} else if (x > 0) {
// TODO: use prevword() to get actual offset
if (it->buffer[it->gps - 1] == '\t') {
wmove(text_win, y, x - 8);
ofx += 7;
ofx += prevword(x, y);
return;
}
wmove(text_win, y, x - 1);
Expand Down
17 changes: 17 additions & 0 deletions utils/sizes.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ long calc_offset_act(unsigned pos, unsigned i, const gap_buf &buf)
get_off(x, i, buf);
return (long)i - (long)x;
}

// Go to end of previous word and return
unsigned prevword(unsigned x, unsigned y)
{
unsigned i = x;
// skip current word
while ((winch(text_win) & A_CHARTEXT) != ' ' && i > 0)
wmove(text_win, y, --i);
// go past any spaces
while ((winch(text_win) & A_CHARTEXT) == ' ' && i > 0)
wmove(text_win, y, --i);
if ((winch(text_win) & A_CHARTEXT) == ' ') {
return x - 1;
}
wmove(text_win, y, ++i);
return x - i - 1;
}

0 comments on commit cea7f27

Please sign in to comment.