aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-25 00:52:25 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-25 00:52:25 +0200
commit70a1756f0996bf96809e7eb941ff78f107a1dd87 (patch)
treeccc20dbba9c78c58be1fe4721ee0a926266a1120
parent66a153c5012f0237bdf67b79b5cc6b2f5f496879 (diff)
Bind Ctrl+W to erase word behind cursor
Added keybinds descriptions in the readme.
-rw-r--r--v2/README.md5
-rw-r--r--v2/chatty.c19
2 files changed, 24 insertions, 0 deletions
diff --git a/v2/README.md b/v2/README.md
index 17f3be5..f853630 100644
--- a/v2/README.md
+++ b/v2/README.md
@@ -50,3 +50,8 @@ M.text = ArenaPush(msgTextArena, M.text_len);
```
Notice, that this depends on knowing the text's length before allocating the memory.
+
+## Keybinds
+- `Ctrl+C` | `Ctrl+D`: quits
+- `Ctrl+U`: Erase input line
+- `Ctrl+W`: Erase word behind cursor
diff --git a/v2/chatty.c b/v2/chatty.c
index 256cc22..4074b77 100644
--- a/v2/chatty.c
+++ b/v2/chatty.c
@@ -195,6 +195,25 @@ int main(int argc, char **argv)
u8 exit = 0;
switch (ev.key) {
+ case TB_KEY_CTRL_W:
+ // delete consecutive whitespace
+ while (input_len) {
+ if (input[input_len - 1] == L' ') {
+ input[input_len - 1] = 0;
+ input_len--;
+ continue;
+ }
+ break;
+ }
+ // delete until whitespace
+ while (input_len) {
+ if (input[input_len - 1] == L' ')
+ break;
+ // erase
+ input[input_len - 1] = 0;
+ input_len--;
+ }
+ break;
case TB_KEY_CTRL_D:
case TB_KEY_CTRL_C:
exit = 1;