diff options
| author | Albert Cervin <albert@acervin.com> | 2023-10-19 23:41:04 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-10-19 23:41:04 +0200 |
| commit | 8147ecac32f8737c76c6d686d69936a9d914088b (patch) | |
| tree | b25007ca5f15cecf6b2af39b01f8f6284af07850 /src/main | |
| parent | 05f61f7e7ab314187ff5d28281a6d6d7facb17ae (diff) | |
| download | dged-8147ecac32f8737c76c6d686d69936a9d914088b.tar.gz dged-8147ecac32f8737c76c6d686d69936a9d914088b.tar.xz dged-8147ecac32f8737c76c6d686d69936a9d914088b.zip | |
Fix search result score
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/search-replace.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/search-replace.c b/src/main/search-replace.c index a94e2b1..c1b812f 100644 --- a/src/main/search-replace.c +++ b/src/main/search-replace.c @@ -33,7 +33,13 @@ uint64_t matchdist(struct region *match, struct location loc) { struct location begin = match->begin; int64_t linedist = (int64_t)begin.line - (int64_t)loc.line; - int64_t coldist = (int64_t)begin.col - (int64_t)loc.col; + + // if the match is on a different line, score it by how far + // into the line it is, otherwise check the distance from location + int64_t coldist = begin.col; + if (linedist == 0) { + int64_t coldist = (int64_t)begin.col - (int64_t)loc.col; + } // arbitrary row scaling, best effort to avoid counting line length return (linedist * linedist) * 1e6 + coldist * coldist; @@ -323,6 +329,7 @@ COMMAND_FN("search-backward", search_backward, search_interactive, int32_t find(struct command_ctx ctx, int argc, const char *argv[]) { bool reverse = *(bool *)ctx.userdata; if (argc == 0) { + g_last_search_interactive = false; struct binding bindings[] = { ANONYMOUS_BINDING(Ctrl, 'S', &search_forward_command), ANONYMOUS_BINDING(Ctrl, 'R', &search_backward_command), |
