diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-24 00:54:53 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 00:54:53 +0900 |
| commit | 243a76002c93b474cf8401b37670a43803a0a2d2 (patch) | |
| tree | e0972774a3e45905b140c6d4affe370cbda04991 /src/result.go | |
| parent | c71e4ddee41d3381fb9ec25cc7078bdb25ac4b27 (diff) | |
| download | fzf-243a76002c93b474cf8401b37670a43803a0a2d2.tar.gz | |
Option to prioritize file name matches (#4192)
* 'pathname' is a new tiebreak option for prioritizing matches occurring
in the file name of the path.
* `--scheme=path` will automatically set `--tiebreak=pathname,length`.
* fzf will automatically choose `path` scheme when the input is a TTY device,
where fzf would start its built-in walker or run `$FZF_DEFAULT_COMMAND`
which is usually a command for listing files.
Close #4191
Diffstat (limited to 'src/result.go')
| -rw-r--r-- | src/result.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/result.go b/src/result.go index 10e0c6d6..28d42e7d 100644 --- a/src/result.go +++ b/src/result.go @@ -69,6 +69,21 @@ func buildResult(item *Item, offsets []Offset, score int) Result { } case byLength: val = item.TrimLength() + case byPathname: + if validOffsetFound { + // lastDelim := strings.LastIndexByte(item.text.ToString(), '/') + lastDelim := -1 + s := item.text.ToString() + for i := len(s) - 1; i >= 0; i-- { + if s[i] == '/' || s[i] == '\\' { + lastDelim = i + break + } + } + if lastDelim <= minBegin { + val = util.AsUint16(minBegin - lastDelim) + } + } case byBegin, byEnd: if validOffsetFound { whitePrefixLen := 0 |
