From f6db66051a6a0cc16f73d64a7c9ebb3e97c89a5f Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Thu, 16 Jan 2025 09:44:23 -0500 Subject: [PATCH] im at a bit of a loss right now --- src/controls.c | 29 +++++++++++++++++++++++------ src/include/controls.h | 4 ++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/controls.c b/src/controls.c index 477e724..14ecccc 100644 --- a/src/controls.c +++ b/src/controls.c @@ -64,7 +64,24 @@ int parse_input_char(char input_char) return 0; } -#define DO_FALLDOWN() if (editor.cx > editor.rows[editor.cy - 1].len) {editor.cx = editor.rows[editor.cy - 1].len;move_cursor_pos(editor.cx, editor.cy);} +void do_falldown(row_t* row) +{ + if (editor.cx > row->len) { + editor.cx = row->len; + editor.rx = row->len; + move_cursor_pos(editor.cx, editor.cy); + } +} + +/** + * TODO: for some reason the cursor is no longer respectingl ine length + * when checking where to move + * + * i imagine this might be something to do with the new functions i added to setup + * rows, and that len isn't properly being translated + * + * check this, if i can't figure it out maybe try valgrind to track everything + */ void move_cursor(movement_t dir) { @@ -76,7 +93,7 @@ void move_cursor(movement_t dir) editor.rx--; break; case RIGHT: - if (editor.cx + 1 > editor.rows[editor.cy - 1].len + if (editor.cx + 1 > editor.rows[editor.ry - 1].len && editor.cx + 1 > editor.screen_cols) break; move_cursor_pos(++editor.cx, editor.cy); @@ -94,7 +111,7 @@ void move_cursor(movement_t dir) editor.ry--; // want to fall down to the end of the line if we're moving to a shorter one - DO_FALLDOWN(); + do_falldown(&editor.rows[editor.ry - 1]); break; case DOWN: @@ -108,9 +125,9 @@ void move_cursor(movement_t dir) move_cursor_pos(editor.cx, ++editor.cy); editor.ry++; - - DO_FALLDOWN(); - + + do_falldown(&editor.rows[editor.ry - 1]); + break; case HOME: move_cursor_pos(1, 1); diff --git a/src/include/controls.h b/src/include/controls.h index 1c38d7c..b1c4635 100644 --- a/src/include/controls.h +++ b/src/include/controls.h @@ -1,3 +1,5 @@ +#include "term.h" + #ifndef CONTROLS_H #define CONTROLS_H @@ -10,6 +12,8 @@ typedef enum { int parse_input_char(char in); +void do_falldown(row_t* row); + void move_cursor(movement_t dir); #endif