im at a bit of a loss right now

This commit is contained in:
SuperNovaa41 2025-01-16 09:44:23 -05:00
parent 3d37584065
commit f6db66051a
2 changed files with 27 additions and 6 deletions

View File

@ -64,7 +64,24 @@ int parse_input_char(char input_char)
return 0; 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) void move_cursor(movement_t dir)
{ {
@ -76,7 +93,7 @@ void move_cursor(movement_t dir)
editor.rx--; editor.rx--;
break; break;
case RIGHT: 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) && editor.cx + 1 > editor.screen_cols)
break; break;
move_cursor_pos(++editor.cx, editor.cy); move_cursor_pos(++editor.cx, editor.cy);
@ -94,7 +111,7 @@ void move_cursor(movement_t dir)
editor.ry--; editor.ry--;
// want to fall down to the end of the line if we're moving to a shorter one // 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; break;
case DOWN: case DOWN:
@ -108,9 +125,9 @@ void move_cursor(movement_t dir)
move_cursor_pos(editor.cx, ++editor.cy); move_cursor_pos(editor.cx, ++editor.cy);
editor.ry++; editor.ry++;
DO_FALLDOWN(); do_falldown(&editor.rows[editor.ry - 1]);
break; break;
case HOME: case HOME:
move_cursor_pos(1, 1); move_cursor_pos(1, 1);

View File

@ -1,3 +1,5 @@
#include "term.h"
#ifndef CONTROLS_H #ifndef CONTROLS_H
#define CONTROLS_H #define CONTROLS_H
@ -10,6 +12,8 @@ typedef enum {
int parse_input_char(char in); int parse_input_char(char in);
void do_falldown(row_t* row);
void move_cursor(movement_t dir); void move_cursor(movement_t dir);
#endif #endif