diff --git a/keybinds.h b/keybinds.h index 8803f17..dab8be4 100644 --- a/keybinds.h +++ b/keybinds.h @@ -39,10 +39,6 @@ static Key keys[] = { * * mode modifier key function argument */ { 1, 0, XK_Escape, switchmode, {0} }, - { 1, 0, XK_Up, move, {.i = 1 } }, - { 1, 0, XK_Down, move, {.i = 2 } }, - { 1, 0, XK_Left, move, {.i = 3 } }, - { 1, 0, XK_Right, move, {.i = 4 } }, /* normal mode * @@ -84,8 +80,8 @@ static Key keys[] = { { 0, SHIFT, XK_g, moveend, {0} }, { 0, 0, XK_Next, movenext, {0} }, { 0, 0, XK_Prior, moveprev, {0} }, - { 0, SHIFT, XK_Left, moveword, {.i = -1 } }, - { 0, SHIFT, XK_Right, moveword, {.i = +1 } }, + { 0, CONTROL, XK_Left, moveword, {.i = -1 } }, + { 0, CONTROL, XK_Right, moveword, {.i = +1 } }, { 0, 0, XK_Left, movecursor, {.i = -1 } }, { 0, 0, XK_Right, movecursor, {.i = +1 } }, { 0, MODIFIER1, XK_p, navhistory, {.i = -1 } }, @@ -99,4 +95,9 @@ static Key keys[] = { { -1, CONTROL, XK_v, paste, {.i = 1 } }, /* primary buffer */ { -1, CONTROL|SHIFT, XK_v, paste, {.i = 2 } }, { -1, 0, XK_BackSpace, backspace, {0} }, + { -1, CONTROL, XK_BackSpace, deleteword, {0} }, + { -1, CONTROL, XK_Left, moveword, {.i = -1 } }, + { -1, CONTROL, XK_Right, moveword, {.i = +1 } }, + { -1, 0, XK_Left, movecursor, {.i = -1 } }, + { -1, 0, XK_Right, movecursor, {.i = +1 } }, }; diff --git a/libs/arg.c b/libs/arg.c index 409954b..2ee5fa6 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -193,17 +193,42 @@ viewhist(const Arg *arg) drawmenu(); } +void +deleteword(const Arg *arg) +{ + if (cursor == 0) + return; + + while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) + insert(NULL, nextrune(-1) - cursor); + while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) + insert(NULL, nextrune(-1) - cursor); + + drawmenu(); +} + void moveword(const Arg *arg) { - movewordedge(arg->i); + if (arg->i < 0) { // move cursor to the start of the word + while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) + cursor = nextrune(-1); + while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) + cursor = nextrune(-1); + } else { // move cursor to the end of the word + while (text[cursor] && strchr(worddelimiters, text[cursor])) + cursor = nextrune(+1); + while (text[cursor] && !strchr(worddelimiters, text[cursor])) + cursor = nextrune(+1); + } + drawmenu(); } void movecursor(const Arg *arg) { - cursor = arg->i ? nextrune(+1) : nextrune(-1); + cursor = nextrune(arg->i); drawmenu(); } diff --git a/libs/arg.h b/libs/arg.h index 4dd9023..17eeed1 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -16,6 +16,7 @@ static void restoresel(const Arg *arg); static void clear(const Arg *arg); static void viewhist(const Arg *arg); static void moveword(const Arg *arg); +static void deleteword(const Arg *arg); static void movecursor(const Arg *arg); static void navhistory(const Arg *arg); static void backspace(const Arg *arg); diff --git a/spmenu.c b/spmenu.c index 215559c..2e32acd 100644 --- a/spmenu.c +++ b/spmenu.c @@ -190,7 +190,6 @@ static void calcoffsets(void); static void readstdin(void); static void recalculatenumbers(void); static void usage(void); -static void movewordedge(int dir); static void insert(const char *str, ssize_t n); static void cleanup(void); static void navigatehistfile(int dir); @@ -395,22 +394,6 @@ nextrune(int inc) return n; } -void -movewordedge(int dir) -{ - if (dir < 0) { // move cursor to the start of the word - while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) - cursor = nextrune(-1); - while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) - cursor = nextrune(-1); - } else { // move cursor to the end of the word - while (text[cursor] && strchr(worddelimiters, text[cursor])) - cursor = nextrune(+1); - while (text[cursor] && !strchr(worddelimiters, text[cursor])) - cursor = nextrune(+1); - } -} - void loadhistory(void) {