From 0144461924c4039a5f56f1b5250097a77fbf3ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Thu, 12 Jul 2018 18:47:46 -0300 Subject: [PATCH] Erase previous or next word if ctrl is held when, respectively, pressing backspace or delete. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/global.c | 2 ++ src/proto.h | 1 + src/text.c | 10 ++++++++++ src/winio.c | 8 ++++++++ 4 files changed, 21 insertions(+) diff --git a/src/global.c b/src/global.c index 89cb580..eee46ba 100644 --- a/src/global.c +++ b/src/global.c @@ -40,6 +40,8 @@ bool meta_key; /* Whether the current keystroke is a Meta key. */ bool shift_held; /* Whether Shift was being held together with a movement key. */ +bool ctrl_held; + /* Whether Ctrl was being held together with backspace or delete. */ bool focusing = TRUE; /* Whether an update of the edit window should center the cursor. */ diff --git a/src/proto.h b/src/proto.h index 7e74eae..90623d2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -35,6 +35,7 @@ extern bool on_a_vt; extern bool meta_key; extern bool shift_held; +extern bool ctrl_held; extern bool focusing; diff --git a/src/text.c b/src/text.c index 8ed330d..ec64fa1 100644 --- a/src/text.c +++ b/src/text.c @@ -178,6 +178,11 @@ void do_deletion(undo_type action) /* Delete the character under the cursor. */ void do_delete(void) { + if (ctrl_held) { + do_cut_next_word(); + return; + } + do_deletion(DEL); } @@ -185,6 +190,11 @@ void do_delete(void) * character, and then delete the character under the cursor. */ void do_backspace(void) { + if (ctrl_held) { + do_cut_prev_word(); + return; + } + if (openfile->current != openfile->fileage || openfile->current_x > 0) { do_left(); do_deletion(BACK); diff --git a/src/winio.c b/src/winio.c index 281488a..58caf11 100644 --- a/src/winio.c +++ b/src/winio.c @@ -358,6 +358,7 @@ int parse_kbinput(WINDOW *win) meta_key = FALSE; shift_held = FALSE; + ctrl_held = FALSE; /* Read in a character. */ kbinput = get_input(win, 1); @@ -523,6 +524,9 @@ int parse_kbinput(WINDOW *win) if (retval == ERR) return ERR; + if (retval == 0x08 || retval == 0x207) + ctrl_held = TRUE; + if (retval == controlleft) return CONTROL_LEFT; else if (retval == controlright) @@ -594,6 +598,7 @@ int parse_kbinput(WINDOW *win) #endif /* Is Ctrl being held? */ if (modifiers & 0x04) { + ctrl_held = TRUE; if (retval == KEY_UP) return CONTROL_UP; else if (retval == KEY_DOWN) @@ -699,6 +704,9 @@ int parse_kbinput(WINDOW *win) #ifdef KEY_SDC /* Slang doesn't support KEY_SDC. */ case KEY_SDC: #endif + case 0x207: + ctrl_held = TRUE; + return KEY_DC; case DEL_CODE: if (ISSET(REBIND_DELETE)) return the_code_for(do_delete, KEY_DC); -- 2.7.4