Commit 678cbce5579984eaa94e22c2d83d2a657b156238

Stefan Sperling 2019-07-28T13:10:25

allow aborting search in 'tog log' with backspace key

diff --git a/TODO b/TODO
index df3304b..ae70add 100644
--- a/TODO
+++ b/TODO
@@ -21,4 +21,3 @@ tog:
 - allow moving to prev/next blamed line in diff view if opened from blame view,
   similar to how the diff view can switch commits if opened from log view
 - tog should have a command to list and log/browse references
-- it should be possible to abort a running search in the log view
diff --git a/tog/tog.1 b/tog/tog.1
index 98b6346..0e9a3f0 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -103,7 +103,10 @@ Open a
 .Cm tree
 view showing the tree for the currently selected commit.
 .It Cm Backspace
-Show log entries for the parent directory of the currently selected path.
+Show log entries for the parent directory of the currently selected path,
+unless an active search is in progress in which case
+.Cm Backspace
+aborts the search.
 .It Cm /
 Prompt for a search pattern and start searching for matching commits.
 The search pattern is an extended regular expression which is matched
@@ -113,8 +116,14 @@ Regular expression syntax is documented in
 .Xr re_format 7 .
 .It Cm n
 Find the next commit which matches the current search pattern.
+Searching continues until either a match is found or the
+.Cm Backspace
+key is pressed.
 .It Cm N
 Find the previous commit which matches the current search pattern.
+Searching continues until either a match is found or the
+.Cm Backspace
+key is pressed.
 .It Cm Ctrl+l
 Reload the log view with new commits found in the repository.
 .El
diff --git a/tog/tog.c b/tog/tog.c
index 419435b..4516ca1 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1755,6 +1755,10 @@ search_next_log_view(struct tog_view *view)
 	}
 
 	if (s->search_entry) {
+		if (wgetch(view->window) == KEY_BACKSPACE) {
+			view->search_next_done = 1;
+			return NULL;
+		}
 		if (view->searching == TOG_SEARCH_FORWARD)
 			entry = TAILQ_NEXT(s->search_entry, entry);
 		else