tAllow single character delete from insert and normal mode - 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 2485a4471857acd56602b5069e6f08f388bed7aa
(DIR) parent 42a8291950dcb96ec855afa221e71e06c6ef8e88
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 6 Aug 2019 16:53:07 +0200
Allow single character delete from insert and normal mode
Diffstat:
M edit.c | 21 +++++++++++++++++++++
M edit.h | 2 ++
M input.c | 6 +++++-
3 files changed, 28 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/edit.c b/edit.c
t@@ -9,3 +9,24 @@ editor_insert_char(int c)
editor_row_insert_char(&E.row[E.cursor_y], E.cursor_x, c);
E.cursor_x++;
}
+
+void
+editor_delete_char_left()
+{
+ if (E.cursor_y == E.num_rows)
+ return;
+ eRow *row = &E.row[E.cursor_y];
+ if (E.cursor_x > 0) {
+ editor_row_delete_char(row, E.cursor_x - 1);
+ E.cursor_x--;
+ }
+}
+
+void
+editor_delete_char_right()
+{
+ if (E.cursor_y == E.num_rows)
+ return;
+ eRow *row = &E.row[E.cursor_y];
+ editor_row_delete_char(row, E.cursor_x);
+}
(DIR) diff --git a/edit.h b/edit.h
t@@ -2,5 +2,7 @@
#define EDIT_H_
void editor_insert_char(int c);
+void editor_delete_char_left();
+void editor_delete_char_right();
#endif
(DIR) diff --git a/input.c b/input.c
t@@ -130,6 +130,10 @@ editor_process_keypress()
E.cursor_y = E.num_rows - 1;
break;
+ case 'x':
+ editor_delete_char_right();
+ break;
+
case 'I':
E.cursor_x = 0;
E.mode = 1;
t@@ -153,7 +157,7 @@ editor_process_keypress()
case 127: /* backspace */
case CTRL_KEY('h'):
- /* TODO */
+ editor_delete_char_left();
break;
case CTRL_KEY('l'):