You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel like I've implented this logic three different ways throughout this library, and I think the cursor_jump() implementation is probably the cleanest. Just move this into a utility maybe called cursor_snap() which will move the cursor to a specific row/column position and adjust scrolling if needed.
For reference, below is a paste of the implementation from cursor_jump()
NOTE: this was pasted directly from vim so I can't really format it...
NOTE 2: row is the new proposed row (could be less than or greater than cursor->row, or the same) and column is the proposed column.
// TODO: move the cursor scrolling logic to a utility function.3// this can be used in other places since I feel like I've implemented2// this in three different ways by now...1if (screen->lines[row][column] ==search_char)
352 {
1// NOTE: the +2 is to account for "lines" being 1-indexed and2// the bottom line is inaccessible (used to display edit mode)3if (row>screen->end_idx)
4 {
5screen->end_idx=row+2;
6screen->start_idx=screen->end_idx-screen->max_rows;
7screen->current_line=screen->max_rows-2;
8 }
9elseif (row<screen->start_idx)
10 {
11screen->start_idx=row;
12screen->end_idx=screen->start_idx+screen->max_rows;
13screen->current_line=0;
14 }
15else16 {
17if (cursor->row>row)
18screen->current_line-= (cursor->row-row);
19else20screen->current_line+= (row-cursor->row);
21 }
2223cursor->row=row;
24cursor->column=column;
2526move(screen->current_line, cursor->column+cursor->line_num_size+1);
27screen_draw(screen, cursor);
28return;
29 }
The text was updated successfully, but these errors were encountered:
I feel like I've implented this logic three different ways throughout this library, and I think the
cursor_jump()
implementation is probably the cleanest. Just move this into a utility maybe calledcursor_snap()
which will move the cursor to a specific row/column position and adjust scrolling if needed.For reference, below is a paste of the implementation from
cursor_jump()
NOTE: this was pasted directly from vim so I can't really format it...
NOTE 2:
row
is the new proposed row (could be less than or greater thancursor->row
, or the same) andcolumn
is the proposed column.The text was updated successfully, but these errors were encountered: