summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-31 14:52:00 +0100
committerAnton Kling <anton@kling.gg>2023-10-31 14:52:00 +0100
commitee0b650da5ecf8778de560ee221200fb69beb791 (patch)
treeca09078be1fbcd455a5f9d4cce3834b611c3f96b
parent6c227820a80fb18c9c04b588aa1cb7aa23fbc4ac (diff)
ante: Adjust X position of cursor so it can always land on a line.
If a y position is found for the cursor we will adjust the X position to the optimial position. Previously if you tried to move from the end of a long line to a short line it would not work since a valid X position could not be found.
-rw-r--r--userland/ante/ante.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/userland/ante/ante.c b/userland/ante/ante.c
index 7fc1315..b5f4eab 100644
--- a/userland/ante/ante.c
+++ b/userland/ante/ante.c
@@ -83,7 +83,8 @@ void delete_char(int pos, int *deleted_newline) {
file_size--;
}
-uint64_t cursor_to_real(int x, int y, int *is_valid) {
+uint64_t cursor_to_real(int *px, int y, int *is_valid) {
+ int x = *px;
*is_valid = 0;
if (clamp(&x, &y))
return file_real_position;
@@ -98,11 +99,17 @@ uint64_t cursor_to_real(int x, int y, int *is_valid) {
int cx = 0;
int cy = 0;
for (; p < file_size; p++) {
- if (cx == x && cy == y) {
+ if (cy == y) {
*is_valid = 1;
- break;
+ *px = cx;
+ if (cx == x) {
+ break;
+ }
}
if ('\n' == file_buffer[p]) {
+ if (cy == y) {
+ break;
+ }
cx = 0;
cy++;
continue;
@@ -187,15 +194,15 @@ void key_event(char c) {
}
int is_valid_position = 0;
+ cursor_pos_x += x;
file_real_position =
- cursor_to_real(cursor_pos_x + x, cursor_pos_y + y, &is_valid_position);
+ cursor_to_real(&cursor_pos_x, cursor_pos_y + y, &is_valid_position);
if (!is_valid_position) {
return;
}
GUI_OverwriteFont(global_w, cursor_pos_x * 8, cursor_pos_y * 8,
BACKGROUND_COLOR);
draw_file();
- cursor_pos_x += x;
cursor_pos_y += y;
GUI_OverwriteFont(global_w, cursor_pos_x * 8, cursor_pos_y * 8, 0xFFFFFF);