From 9d8db4146d025e3a967700414a9fc68fa186045e Mon Sep 17 00:00:00 2001 From: Riley Beckett Date: Thu, 23 Oct 2025 00:07:26 -0400 Subject: add basic cursor movement --- input_field.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'input_field.c') 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; -- cgit v1.2.3