summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-28 18:04:49 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-28 18:04:49 -0500
commit7cf306d26d710dd551575a32b4f492e7a13a9610 (patch)
tree7e58e6fc636c4061df40fe2c439d907ef6cfb6d6 /main.c
parent52ac1f9d10d8752aa99698c0ee80c4f9420de389 (diff)
more selection, improved buffer_pos_move_left_words
Diffstat (limited to 'main.c')
-rw-r--r--main.c69
1 files changed, 54 insertions, 15 deletions
diff --git a/main.c b/main.c
index d1ad1c4..b115196 100644
--- a/main.c
+++ b/main.c
@@ -92,6 +92,7 @@ int main(void) {
Uint8 const *keyboard_state = SDL_GetKeyboardState(NULL);
bool ctrl = keyboard_state[SDL_SCANCODE_LCTRL] || keyboard_state[SDL_SCANCODE_RCTRL];
bool shift = keyboard_state[SDL_SCANCODE_LSHIFT] || keyboard_state[SDL_SCANCODE_RSHIFT];
+ bool alt = keyboard_state[SDL_SCANCODE_LALT] || keyboard_state[SDL_SCANCODE_RALT];
while (SDL_PollEvent(&event)) {
// @TODO: make a function to handle text buffer events
@@ -123,26 +124,64 @@ int main(void) {
buffer_scroll(buffer, 0, +buffer_display_lines(buffer));
break;
case SDLK_RIGHT:
- if (shift) {
- buffer_select_right(buffer, 1);
- } else {
- if (ctrl)
- buffer_cursor_move_right_words(buffer, 1);
- else
- buffer_cursor_move_right(buffer, 1);
+ if (!alt) {
+ if (shift) {
+ if (ctrl)
+ buffer_select_right_words(buffer, 1);
+ else
+ buffer_select_right(buffer, 1);
+ } else {
+ if (ctrl)
+ buffer_cursor_move_right_words(buffer, 1);
+ else
+ buffer_cursor_move_right(buffer, 1);
+ }
}
break;
case SDLK_LEFT:
- if (ctrl)
- buffer_cursor_move_left_words(buffer, 1);
- else
- buffer_cursor_move_left(buffer, 1);
+ if (!alt) {
+ if (shift) {
+ if (ctrl)
+ buffer_select_left_words(buffer, 1);
+ else
+ buffer_select_left(buffer, 1);
+ } else {
+ if (ctrl)
+ buffer_cursor_move_left_words(buffer, 1);
+ else
+ buffer_cursor_move_left(buffer, 1);
+ }
+ }
break;
case SDLK_UP:
- buffer_cursor_move_up(buffer, 1);
+ if (!alt) {
+ if (shift) {
+ if (ctrl)
+ buffer_select_up(buffer, 10);
+ else
+ buffer_select_up(buffer, 1);
+ } else {
+ if (ctrl)
+ buffer_cursor_move_up(buffer, 10);
+ else
+ buffer_cursor_move_up(buffer, 1);
+ }
+ }
break;
case SDLK_DOWN:
- buffer_cursor_move_down(buffer, 1);
+ if (!alt) {
+ if (shift) {
+ if (ctrl)
+ buffer_select_down(buffer, 10);
+ else
+ buffer_select_down(buffer, 1);
+ } else {
+ if (ctrl)
+ buffer_cursor_move_down(buffer, 10);
+ else
+ buffer_cursor_move_down(buffer, 1);
+ }
+ }
break;
case SDLK_RETURN:
buffer_insert_char_at_cursor(buffer, U'\n');
@@ -194,8 +233,8 @@ int main(void) {
time_at_last_frame = time_this_frame;
}
- if (ctrl) {
- // control + arrow keys to scroll
+ if (alt) {
+ // alt + arrow keys to scroll
double scroll_speed = 20.0;
double scroll_amount_x = scroll_speed * frame_dt * 1.5; // characters are taller than they are wide
double scroll_amount_y = scroll_speed * frame_dt;