From 69dc8f38a10208f68b81c097ab73440242bec246 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 21 Jul 2023 18:29:18 +1000 Subject: [PATCH] history: improve stability of search. When searching for string that matched at start of line, we would stay on the line as we typed more of the match. When searching elsewhere, we keep moving backward in the history. Fix by always starting search at end of line. Signed-off-by: NeilBrown --- DOC/TODO.md | 2 +- lib-history.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index 2711a537..190d72b3 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -26,7 +26,7 @@ the file. When searching backwards and result is just above display, the result doesn't get shown. Sometimes. - [X] visiting a new file from a 44 popup is weird. -- [ ] search in history always finds a new history line. It doesn't +- [X] search in history always finds a new history line. It doesn't check if new patterns still matches this line. - [ ] in notmuch cursor should go to query result when changing messages. diff --git a/lib-history.c b/lib-history.c index a90e4b45..b7bceb15 100644 --- a/lib-history.c +++ b/lib-history.c @@ -362,6 +362,8 @@ static void update_search(struct pane *p safe, struct pane *focus safe, call("view:changed", focus); call("Mode:set-mode", focus, 0, NULL, ":History-search"); m = mark_at_point(hi->history, NULL, MARK_UNGROUPED); + /* Alway search backwards from the end-of-line of last match */ + call("doc:EOL", hi->history, 1, m); ret = call("text-search", hi->history, 1, m, buf_final(&hi->search), hi->search_back); if (ret <= 0) { @@ -369,6 +371,7 @@ static void update_search(struct pane *p safe, struct pane *focus safe, mark_free(m); return; } + /* Leave point at start-of-line */ call("doc:EOL", hi->history, -1, m); call("Move-to", hi->history, 0, m); mark_free(m); -- 2.39.5