fix issues with movement

This commit is contained in:
speedie 2023-03-24 14:38:28 +01:00
parent ceec442bfe
commit eebad002cd
2 changed files with 11 additions and 2 deletions

View file

@ -256,7 +256,16 @@ moveword(const Arg *arg)
void void
movecursor(const Arg *arg) movecursor(const Arg *arg)
{ {
cursor = nextrune(arg->i); if (arg->i < 0) {
if (cursor > 0) {
cursor = nextrune(-1);
}
} else {
if (text[cursor]) {
cursor = nextrune(+1);
}
}
drawmenu(); drawmenu();
} }

View file

@ -393,7 +393,7 @@ nextrune(int inc)
// return location of next utf8 rune in the given direction (+1 or -1) // return location of next utf8 rune in the given direction (+1 or -1)
for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc) for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc)
; ;
return n; return n ? n : NULL;
} }
void void