Compare commits
2 Commits
a8d21b2d67
...
cbc0bf4452
| Author | SHA1 | Date | |
|---|---|---|---|
| cbc0bf4452 | |||
| f74f8ab122 |
21
ce/edit.c
21
ce/edit.c
@@ -227,6 +227,24 @@ void edit_start (const char* file_path, const char* text) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
editor.cursor.col--;
|
||||
gapbuffer_backspace (&editor.current_line->gb);
|
||||
} else {
|
||||
if (editor.cursor.line > 0) {
|
||||
struct list_node_link* prev = editor.current_line->lines_link.prev;
|
||||
struct edit_line* prev_line = list_entry (prev, struct edit_line, lines_link);
|
||||
|
||||
size_t prev_len = gapbuffer_length (&prev_line->gb);
|
||||
|
||||
gapbuffer_concat (&wrealloc, NULL, &prev_line->gb, &editor.current_line->gb);
|
||||
|
||||
list_remove (editor.lines, &editor.current_line->lines_link);
|
||||
free (editor.current_line->gb.buffer);
|
||||
free (editor.current_line);
|
||||
editor.current_line = prev_line;
|
||||
|
||||
editor.cursor.col = prev_len;
|
||||
editor.cursor.line--;
|
||||
editor.total_lines--;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -272,16 +290,15 @@ void edit_start (const char* file_path, const char* text) {
|
||||
case KB_DELETE:
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
size_t len = gapbuffer_length (&editor.current_line->gb);
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
|
||||
if (editor.cursor.col < len) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
if (editor.current_line->gb.gap_end < editor.current_line->gb.size)
|
||||
editor.current_line->gb.gap_end++;
|
||||
} else {
|
||||
if (editor.cursor.line > 0) {
|
||||
struct list_node_link* next = editor.current_line->lines_link.next;
|
||||
struct edit_line* next_line = list_entry (next, struct edit_line, lines_link);
|
||||
size_t next_len = gapbuffer_length (&next_line->gb);
|
||||
|
||||
gapbuffer_concat (&wrealloc, NULL, &editor.current_line->gb, &next_line->gb);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user