Add C-w and M-d

master
C. McEnroe 2020-02-09 04:32:32 -05:00
parent 3cd830681e
commit 5e637324c9
4 changed files with 26 additions and 4 deletions

View File

@ -211,8 +211,12 @@ Move right.
Delete to end of line. Delete to end of line.
.It Ic C-u .It Ic C-u
Delete to beginning of line. Delete to beginning of line.
.It Ic C-w
Delete previous word.
.It Ic M-b .It Ic M-b
Move to previous word. Move to previous word.
.It Ic M-d
Delete next word.
.It Ic M-f .It Ic M-f
Move to next word. Move to next word.
.El .El

2
chat.h
View File

@ -155,6 +155,8 @@ enum Edit {
EditDeleteTail, EditDeleteTail,
EditDeletePrev, EditDeletePrev,
EditDeleteNext, EditDeleteNext,
EditDeletePrevWord,
EditDeleteNextWord,
EditInsert, EditInsert,
EditComplete, EditComplete,
EditEnter, EditEnter,

17
edit.c
View File

@ -146,10 +146,23 @@ void edit(size_t id, enum Edit op, wchar_t ch) {
while (pos < len && buf[pos] != L' ') pos++; while (pos < len && buf[pos] != L' ') pos++;
} }
break; case EditDeletePrev: if (pos) delete(--pos, 1);
break; case EditDeleteNext: delete(pos, 1);
break; case EditDeleteHead: delete(0, pos); pos = 0; break; case EditDeleteHead: delete(0, pos); pos = 0;
break; case EditDeleteTail: delete(pos, len - pos); break; case EditDeleteTail: delete(pos, len - pos);
break; case EditDeletePrev: if (pos) delete(--pos, 1);
break; case EditDeleteNext: delete(pos, 1);
break; case EditDeletePrevWord: {
if (!pos) break;
size_t word = pos - 1;
while (word && buf[word - 1] != L' ') word--;
delete(word, pos - word);
pos = word;
}
break; case EditDeleteNextWord: {
if (pos == len) break;
size_t word = pos + 1;
while (word < len && buf[word] != L' ') word++;
delete(pos, word - pos);
}
break; case EditInsert: { break; case EditInsert: {
reserve(pos, 1); reserve(pos, 1);

7
ui.c
View File

@ -192,8 +192,9 @@ static void errExit(void) {
X(KeyMeta7, "\0337") \ X(KeyMeta7, "\0337") \
X(KeyMeta8, "\0338") \ X(KeyMeta8, "\0338") \
X(KeyMeta9, "\0339") \ X(KeyMeta9, "\0339") \
X(KeyMetaB, "\033b") \ X(KeyMetaB, "\33b") \
X(KeyMetaF, "\033f") \ X(KeyMetaD, "\33d") \
X(KeyMetaF, "\33f") \
X(KeyMetaM, "\33m") \ X(KeyMetaM, "\33m") \
X(KeyFocusIn, "\33[I") \ X(KeyFocusIn, "\33[I") \
X(KeyFocusOut, "\33[O") \ X(KeyFocusOut, "\33[O") \
@ -625,6 +626,7 @@ static void keyCode(int code) {
break; case KeyPasteOff:; // TODO break; case KeyPasteOff:; // TODO
break; case KeyMetaB: edit(id, EditPrevWord, 0); break; case KeyMetaB: edit(id, EditPrevWord, 0);
break; case KeyMetaD: edit(id, EditDeleteNextWord, 0);
break; case KeyMetaF: edit(id, EditNextWord, 0); break; case KeyMetaF: edit(id, EditNextWord, 0);
break; case KeyMetaM: waddch(windows.active->pad, '\n'); break; case KeyMetaM: waddch(windows.active->pad, '\n');
@ -659,6 +661,7 @@ static void keyCtrl(wchar_t ch) {
break; case L'K': edit(id, EditDeleteTail, 0); break; case L'K': edit(id, EditDeleteTail, 0);
break; case L'L': clearok(curscr, true); break; case L'L': clearok(curscr, true);
break; case L'U': edit(id, EditDeleteHead, 0); break; case L'U': edit(id, EditDeleteHead, 0);
break; case L'W': edit(id, EditDeletePrevWord, 0);
} }
} }