From: Michael D. Lowis Date: Sat, 4 Mar 2017 18:53:27 +0000 (-0500) Subject: Added a keyboard shortcut to search for previous search term (even if its been deleted) X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4a527f917e55f89be22966ad6a9ceb1ba7d0f6ae;p=projs%2Ftide.git Added a keyboard shortcut to search for previous search term (even if its been deleted) --- diff --git a/TODO.md b/TODO.md index 9e35c57..add30c8 100644 --- a/TODO.md +++ b/TODO.md @@ -2,11 +2,10 @@ Up Next: -* implement 9term-like scrollbar +* Make Fn keys execute nth command in the tags buffer * check for file changes on save * check for file changes when window regains focus * Right click in tags region should search edit region -* ctrl+alt+f should find next occurence of previous search term * Add keyboard shortcut to highlight the thing under the cursor * 100% coverage with unit and unit-integration tests diff --git a/inc/x11.h b/inc/x11.h index 449ae2f..124e8d5 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -118,7 +118,7 @@ enum { ModNumLock = (1 << 4), ModScrollLock = (1 << 5), ModWindows = (1 << 6), - ModAny = (ModShift|ModCtrl|ModAlt) + ModAny = -1 }; /* Selection identifiers */ diff --git a/lib/win.c b/lib/win.c index 7d0b226..b34f0a5 100644 --- a/lib/win.c +++ b/lib/win.c @@ -198,6 +198,8 @@ static void onredraw(int width, int height) { } static void oninput(int mods, Rune key) { + /* mask of modifiers we don't care about */ + mods = mods & (ModCtrl|ModAlt|ModShift); /* handle the proper line endings */ if (key == '\r') key = '\n'; if (key == '\n' && win_view(FOCUSED)->buffer.crlf) key = RUNE_CRLF; diff --git a/xedit.c b/xedit.c index d6a8937..ea3899d 100644 --- a/xedit.c +++ b/xedit.c @@ -19,8 +19,9 @@ static char* SedCmd[] = { "sed", "-e", NULL, NULL }; static char* PickFileCmd[] = { "xfilepick", ".", NULL }; static char* PickTagCmd[] = { "xtagpick", "tags", NULL, NULL }; static char* OpenCmd[] = { "xedit", NULL, NULL }; -static int SearchDir = DOWN; static Tag Builtins[]; +static int SearchDir = DOWN; +static char* SearchTerm = NULL; /* Tag/Cmd Execution *****************************************************************************/ @@ -178,12 +179,15 @@ void onmouseright(WinRegion id, size_t count, size_t row, size_t col) { paste(); } else { SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); + free(SearchTerm); view_find(win_view(id), SearchDir, row, col); + SearchTerm = view_getstr(win_view(id), NULL); win_warpptr(id); } } -/* Keyboard Handling */ +/* Keyboard Handling + *****************************************************************************/ static void del_to_bol(void) { view_bol(win_view(FOCUSED), true); if (view_selsize(win_view(FOCUSED)) > 0) @@ -290,10 +294,15 @@ static void tag_redo(void) { } static void search(void) { + char* str; SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); - char* str = view_getctx(win_view(FOCUSED)); + if (x11_keymodsset(ModAlt) && SearchTerm) + str = stringdup(SearchTerm); + else + str = view_getctx(win_view(FOCUSED)); view_findstr(win_view(EDIT), SearchDir, str); - free(str); + free(SearchTerm); + SearchTerm = str; win_setregion(EDIT); win_warpptr(EDIT); } @@ -459,18 +468,20 @@ static KeyBinding Bindings[] = { { ModAny, KEY_BACKSPACE, backspace }, /* Implementation Specific */ - { ModNone, KEY_ESCAPE, select_prev }, - { ModCtrl, 't', change_focus }, - { ModCtrl, 'q', quit }, - { ModCtrl, 'f', search }, - { ModCtrl|ModShift, 'f', search }, - { ModCtrl, 'd', execute }, - { ModCtrl, 'o', open_file }, - { ModCtrl, 'p', pick_ctag }, - { ModCtrl, 'g', goto_ctag }, - { ModCtrl, 'n', new_win }, - { ModCtrl, '\n', newline }, - { ModCtrl|ModShift, '\n', newline }, + { ModNone, KEY_ESCAPE, select_prev }, + { ModCtrl, 't', change_focus }, + { ModCtrl, 'q', quit }, + { ModCtrl, 'f', search }, + { ModCtrl|ModShift, 'f', search }, + { ModCtrl|ModAlt, 'f', search }, + { ModCtrl|ModAlt|ModShift, 'f', search }, + { ModCtrl, 'd', execute }, + { ModCtrl, 'o', open_file }, + { ModCtrl, 'p', pick_ctag }, + { ModCtrl, 'g', goto_ctag }, + { ModCtrl, 'n', new_win }, + { ModCtrl, '\n', newline }, + { ModCtrl|ModShift, '\n', newline }, { 0, 0, 0 } };