]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added a keyboard shortcut to search for previous search term (even if its been deleted)
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 4 Mar 2017 18:53:27 +0000 (13:53 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 4 Mar 2017 18:53:27 +0000 (13:53 -0500)
TODO.md
inc/x11.h
lib/win.c
xedit.c

diff --git a/TODO.md b/TODO.md
index 9e35c57fb03169481f8f2d040e53915e042dc86b..add30c8a0ca8baa2ef407dabbf795d056ff2bba0 100644 (file)
--- 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
 
index 449ae2fd69de8bf763d69d4f9be49cd46cbcda10..124e8d5894e95f188a48581e210fc65256c74188 100644 (file)
--- 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 */
index 7d0b226e7304114a09d7069dd50c3cba4816283c..b34f0a58c113c94d53badb4c2161804cb0a59351 100644 (file)
--- 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 d6a8937a387260ef3f4672b934490e6907d05e7d..ea3899d1b0db24da0c150a348cf1aee58093c94f 100644 (file)
--- 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 }
 };