can scroll up and down in a file

This commit is contained in:
2026-04-22 15:48:37 -04:00
parent 0dd6516726
commit 0dc25adb8b

View File

@@ -200,15 +200,15 @@ handle_enter :: () {
new_line := [..]u8.{};
array_add(*new_line, array_view(current_line.*, cursor_x));
array_insert_at(*lines, new_line, cursor_y + 1);
array_insert_at(*lines, new_line, cursor_line_index + 1);
current_line.count = cursor_x;
cursor_y += 1;
handle_arrow(.ARROW_DOWN);
cursor_x = 0;
}
handle_backspace :: () {
if cursor_x == 0 && cursor_y == 0 {
if cursor_x == 0 && cursor_y == 0 && first_line == 0 {
return;
}
@@ -219,7 +219,7 @@ handle_backspace :: () {
prev_count := prev_line.count;
array_add(prev_line, current_line.*);
array_remove_at(*lines, cursor_line_index);
cursor_y -= 1;
handle_arrow(.ARROW_UP);
cursor_x = prev_count;
} else {
array_remove_at(current_line, cursor_x - 1);
@@ -232,13 +232,19 @@ handle_arrow :: (key_code: Input.Key_Code) {
if key_code == {
case .ARROW_UP;
cursor_y = ifx cursor_y == 0
then 0
else cursor_y - 1;
if cursor_y == 0 && first_line == 0 return;
if cursor_y == 0 {
first_line -= 1;
} else {
cursor_y -= 1;
}
case .ARROW_DOWN;
cursor_y = ifx cursor_y == visible_lines.count - 1
then visible_lines.count - 1
else cursor_y + 1;
if cursor_y == visible_lines.count - 1 {
first_line = min(first_line + 1, lines.count);
} else {
cursor_y += 1;
}
case .ARROW_LEFT;
if cursor_x == 0 && cursor_y != 0 {