summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaydee-coder <187227976+jaydee-coder@users.noreply.github.com>2024-11-04 05:27:59 -0800
committerGitHub <noreply@github.com>2024-11-04 22:27:59 +0900
commitd4d9b99879d7f870264d4e2e9358c81b5e59981d (patch)
tree657caf8396cd703efe7aa29b16662c8cb3b11355
parent6816b7d95b54330224020b4304db7fd5a5ea1ba1 (diff)
downloadfzf-d4d9b99879d7f870264d4e2e9358c81b5e59981d.tar.gz
Allow specifying '{n}' as the OFFSET in the preview-window flag (#4079)
* fzf: Allow '{n}' to be used as the OFFSET in the preview-window flag * man: Document using '{n}' as the OFFSET in the preview-window flag
-rw-r--r--man/man1/fzf.12
-rw-r--r--src/options.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index 9547d3db..2e4bb92f 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -805,7 +805,7 @@ e.g. \fBborder\-rounded\fR (border with rounded edges, default),
* \fB[:+SCROLL[OFFSETS][/DENOM]]\fR determines the initial scroll offset of the
preview window.
- - \fBSCROLL\fR can be either a numeric integer or a single-field index expression that refers to a numeric integer.
+ - \fBSCROLL\fR can be either a numeric integer or a single-field index expression that refers to a numeric integer or {n} to refer to the zero-based ordinal index of the current item.
- The optional \fBOFFSETS\fR part is for adjusting the base offset. It should be given as a series of signed integers (\fB\-INTEGER\fR or \fB+INTEGER\fR).
diff --git a/src/options.go b/src/options.go
index b0ab6b1d..c42acce3 100644
--- a/src/options.go
+++ b/src/options.go
@@ -1726,7 +1726,7 @@ func parsePreviewWindowImpl(opts *previewOpts, input string) error {
var err error
tokenRegex := regexp.MustCompile(`[:,]*(<([1-9][0-9]*)\(([^)<]+)\)|[^,:]+)`)
sizeRegex := regexp.MustCompile("^[0-9]+%?$")
- offsetRegex := regexp.MustCompile(`^(\+{-?[0-9]+})?([+-][0-9]+)*(-?/[1-9][0-9]*)?$`)
+ offsetRegex := regexp.MustCompile(`^(\+{(-?[0-9]+|n)})?([+-][0-9]+)*(-?/[1-9][0-9]*)?$`)
headerRegex := regexp.MustCompile("^~(0|[1-9][0-9]*)$")
tokens := tokenRegex.FindAllStringSubmatch(input, -1)
var alternative string