aboutsummaryrefslogtreecommitdiff
path: root/input_field.c
diff options
context:
space:
mode:
authorRiley Beckett <rbeckettvt@gmail.com>2025-10-23 00:07:26 -0400
committerRiley Beckett <rbeckettvt@gmail.com>2025-10-23 00:07:26 -0400
commit9d8db4146d025e3a967700414a9fc68fa186045e (patch)
tree9d0e0d6dd46a2f580f4b2fb4e1fbba2b0c6fb11e /input_field.c
parent90d6b2a866c6da29921dfae3d684203fd232ea74 (diff)
add basic cursor movement
Diffstat (limited to 'input_field.c')
-rw-r--r--input_field.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/input_field.c b/input_field.c
index 6ca9a1b..a0d5cc6 100644
--- a/input_field.c
+++ b/input_field.c
@@ -68,6 +68,7 @@ bool type_key(client_state* state, xkb_keysym_t keysym) {
array_free(state->input_buffer);
state->input_buffer = array_new(char, len);
memcpy(state->input_buffer, selected, len);
+ state->cursor_index = len;
update_text_buffer(state);
}
@@ -90,6 +91,36 @@ bool type_key(client_state* state, xkb_keysym_t keysym) {
return true;
}
+ if (keysym == XKB_KEY_e && ctrl) {
+ state->cursor_index = array_size(state->input_buffer);
+ return true;
+ }
+
+ if (keysym == XKB_KEY_a && ctrl) {
+ state->cursor_index = 0;
+ return true;
+ }
+
+ if (keysym == XKB_KEY_f && ctrl) {
+ if (state->cursor_index < array_size(state->input_buffer)) {
+ state->cursor_index++;
+ }
+ return true;
+ }
+
+ if (keysym == XKB_KEY_b && ctrl) {
+ if (state->cursor_index > 0) {
+ state->cursor_index--;
+ }
+ return true;
+ }
+
+ if (keysym == XKB_KEY_k && ctrl) {
+ array_resize(state->input_buffer, state->cursor_index);
+ update_text_buffer(state);
+ return true;
+ }
+
// paste
if (keysym == XKB_KEY_v && ctrl) {
FILE* fp = popen("wl-paste --no-newline --type text/plain 2>/dev/null", "r");
@@ -125,8 +156,12 @@ bool type_key(client_state* state, xkb_keysym_t keysym) {
if (keysym == XKB_KEY_BackSpace || keysym == XKB_KEY_Delete) {
if (ctrl) {
array_clear(state->input_buffer);
+ state->cursor_index = 0;
} else {
- array_pop(state->input_buffer);
+ if (state->cursor_index) {
+ array_erase(state->input_buffer, state->cursor_index);
+ state->cursor_index--;
+ }
}
update_text_buffer(state);
return true;
@@ -137,7 +172,8 @@ bool type_key(client_state* state, xkb_keysym_t keysym) {
int len = xkb_keysym_to_utf8(keysym, buf, sizeof(buf));
if (len > 0) {
for (int i = 0; i < strlen(buf); i++) {
- array_add(state->input_buffer, buf[i]);
+ array_insert(state->input_buffer, state->cursor_index, buf[i]);
+ state->cursor_index++;
}
update_text_buffer(state);
return true;