tConstrain horizontal cursor movement during vertical navigation - ve - a minimal text editor (work in progress)
(HTM) git clone git://src.adamsgaard.dk/ve
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ff5731cf9db9e1933a13654bce29476117121ab5
(DIR) parent b6a1dc1daa16f2ce59d88fba5bf3bfdb36e61136
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 6 Aug 2019 13:22:48 +0200
Constrain horizontal cursor movement during vertical navigation
Diffstat:
M input.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/input.c b/input.c
t@@ -5,9 +5,13 @@
#define CTRL_KEY(k) ((k) & 0x1f)
+/* move cursor according to screen, file, and line limits */
void
editor_move_cursor(char key)
{
+ int row_len;
+ eRow *row;
+
switch(key) {
case 'h':
if (E.cursor_x > 0)
t@@ -22,9 +26,17 @@ editor_move_cursor(char key)
E.cursor_y--;
break;
case 'l':
- E.cursor_x++;
+ row = (E.cursor_y >= E.num_rows) ? NULL : &E.row[E.cursor_y];
+ if (row && E.cursor_x < row->size)
+ E.cursor_x++;
break;
}
+
+ /* do not allow navigation past EOL by vertical navigation */
+ row = (E.cursor_y >= E.num_rows) ? NULL : &E.row[E.cursor_y];
+ row_len = row ? row->size : 0;
+ if (E.cursor_x > row_len)
+ E.cursor_x = row_len;
}
void