From 3b2b60466c9e701b37bb42e402cc92386b001dd7 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 24 Nov 2025 20:27:30 -0800 Subject: [PATCH] continuing region work --- main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 7156074..43db16f 100644 --- a/main.c +++ b/main.c @@ -698,13 +698,50 @@ cursor_after_mark(void) } +void +kill_region(void) +{ + int curx = editor.curx; + int cury = editor.cury; + + if (!editor.mark_set) { + return; + } + + /* kill the current killring */ + killring_flush(); + + if (!cursor_after_mark()) { + /* gotta flex sometimes */ + curx ^= cury; + cury ^= curx; + cury ^= curx; + } + + editor.curx = editor.mark_curx; + editor.cury = editor.mark_cury; + + while (editor.cury != cury) { + while (!cursor_at_eol()) { + killring_append_char(editor.row[editor.cury].line[editor.curx]); + move_cursor(ARROW_RIGHT); + } + killring_append_char('\n'); + } + + while (editor.curx != curx) { + killring_append_char(editor.row[editor.cury].line[editor.curx]); + move_cursor(ARROW_RIGHT); + } + + editor_set_status("Region killed."); + editor.mark_set = 0; +} + + void die(const char *s) { - /* - * NOTE(kyle): this is a duplication of the code in display.c - * but I would like to be able to import these files from there. - */ write(STDOUT_FILENO, "\x1b[2J", 4); write(STDOUT_FILENO, "\x1b[H", 3); @@ -1754,6 +1791,12 @@ process_escape(int16_t c) case 'm': toggle_markset(); break; + case 'w': + if (!editor.mark_set) { + editor_set_status("mark isn't set"); + break; + } + kill_region(); case BACKSPACE: delete_prev_word(); break;