Use iswspace for word movement

weechat-hashes
C. McEnroe 2020-02-09 07:32:35 -05:00
parent 2aa2005339
commit 02ca8e972b
1 changed files with 5 additions and 4 deletions

9
edit.c
View File

@ -20,6 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#include <wctype.h>
#include "chat.h" #include "chat.h"
@ -150,11 +151,11 @@ void edit(size_t id, enum Edit op, wchar_t ch) {
break; case EditNext: if (pos < len) pos++; break; case EditNext: if (pos < len) pos++;
break; case EditPrevWord: { break; case EditPrevWord: {
if (pos) pos--; if (pos) pos--;
while (pos && buf[pos - 1] != L' ') pos--; while (pos && !iswspace(buf[pos - 1])) pos--;
} }
break; case EditNextWord: { break; case EditNextWord: {
if (pos < len) pos++; if (pos < len) pos++;
while (pos < len && buf[pos] != L' ') pos++; while (pos < len && !iswspace(buf[pos])) pos++;
} }
break; case EditDeleteHead: delete(0, pos); pos = 0; break; case EditDeleteHead: delete(0, pos); pos = 0;
@ -164,14 +165,14 @@ void edit(size_t id, enum Edit op, wchar_t ch) {
break; case EditDeletePrevWord: { break; case EditDeletePrevWord: {
if (!pos) break; if (!pos) break;
size_t word = pos - 1; size_t word = pos - 1;
while (word && buf[word - 1] != L' ') word--; while (word && !iswspace(buf[word - 1])) word--;
delete(word, pos - word); delete(word, pos - word);
pos = word; pos = word;
} }
break; case EditDeleteNextWord: { break; case EditDeleteNextWord: {
if (pos == len) break; if (pos == len) break;
size_t word = pos + 1; size_t word = pos + 1;
while (word < len && buf[word] != L' ') word++; while (word < len && !iswspace(buf[word])) word++;
delete(pos, word - pos); delete(pos, word - pos);
} }
break; case EditPaste: { break; case EditPaste: {