From 57a542f83dc25d8684c5512e64f5d52ea01c41bb Mon Sep 17 00:00:00 2001 From: resolritter Date: Mon, 7 Sep 2020 19:01:55 -0300 Subject: [PATCH 1/2] implement match clearing and add a keybinding for it --- les.h | 1 + main.c | 3 +++ search.c | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/les.h b/les.h index b28e60e..5e3a19a 100644 --- a/les.h +++ b/les.h @@ -227,6 +227,7 @@ void next_match (); void prev_match (); void load_search_history (); void save_search_history (); +void clear_matches (); #endif diff --git a/main.c b/main.c index c46691e..da1efb9 100644 --- a/main.c +++ b/main.c @@ -312,6 +312,9 @@ int read_key (char *buf, int len) { case '/': search(); break; + case 'c': + clear_matches(); + break; case -0x40 + 'D': move_forward(10000); break; diff --git a/search.c b/search.c index 66067ba..202e7e8 100644 --- a/search.c +++ b/search.c @@ -191,6 +191,18 @@ void save_search_history () { fclose(fp); } +void clear_matches() { + tabb->matches = NULL; + tabb->matches_len = 0; + tabb->matches_size = 0; + tabb->current_match = 0; + tabb->highlights = NULL; + tabb->highlights_len = 0; + tabb->highlights_size = 0; + tabb->highlights_processed = 0; + draw_tab(); +} + void search2 (char *pattern) { active_search = 0; search_version++; From 1e4857362bde95dc121e28696e0506294573540e Mon Sep 17 00:00:00 2001 From: resolritter Date: Mon, 7 Sep 2020 19:06:24 -0300 Subject: [PATCH 2/2] add documentation for 'clear_matches' --- README.md | 1 + main.c | 1 + search.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba7db2e..9ecb6a6 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ Key Binds U,⇞ go up a screen w toggle line wrap / search + c clear search matches F1 view help F2 view recently opened files diff --git a/main.c b/main.c index da1efb9..dfe556b 100644 --- a/main.c +++ b/main.c @@ -147,6 +147,7 @@ char *usage_text () { " U,⇞ go up a screen\n" " w toggle line wrap\n" " / search\n" + " c clear search matches\n" " F1 view help\n" " F2 view recently opened files\n"; return str; diff --git a/search.c b/search.c index 202e7e8..02f7264 100644 --- a/search.c +++ b/search.c @@ -191,7 +191,7 @@ void save_search_history () { fclose(fp); } -void clear_matches() { +void clear_matches () { tabb->matches = NULL; tabb->matches_len = 0; tabb->matches_size = 0;