summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-08-23 15:57:49 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-08-23 15:57:49 +0900
commit1cb19dbf65590ffe44b60ac4d5ff7a957de0628f (patch)
tree9747349c9d5755a08c7c98641f95eedece6f9289 /src
parent1ab4289ad64a60a88c44dcfe7d032c5d028df6bf (diff)
Support preview scroll offset relative to window height
Related: https://github.com/junegunn/fzf.vim/issues/1092
Diffstat (limited to 'src')
-rw-r--r--src/options.go2
-rw-r--r--src/terminal.go14
2 files changed, 12 insertions, 4 deletions
diff --git a/src/options.go b/src/options.go
index 699e8a55..a916e806 100644
--- a/src/options.go
+++ b/src/options.go
@@ -995,7 +995,7 @@ func parsePreviewWindow(opts *previewOpts, input string) {
tokens := strings.Split(input, ":")
sizeRegex := regexp.MustCompile("^[1-9][0-9]*%?$")
- offsetRegex := regexp.MustCompile("^\\+([0-9]+|{-?[0-9]+})(-[0-9]+)?$")
+ offsetRegex := regexp.MustCompile("^\\+([0-9]+|{-?[0-9]+})(-[0-9]+|-/[1-9][0-9]*)?$")
for _, token := range tokens {
switch token {
case "":
diff --git a/src/terminal.go b/src/terminal.go
index a7e9e9b2..2fa13984 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1374,7 +1374,7 @@ func atopi(s string) int {
return n
}
-func (t *Terminal) evaluateScrollOffset(list []*Item) int {
+func (t *Terminal) evaluateScrollOffset(list []*Item, height int) int {
offsetExpr := t.replacePlaceholder(t.preview.scroll, false, "", list)
nums := strings.Split(offsetExpr, "-")
switch len(nums) {
@@ -1387,6 +1387,13 @@ func (t *Terminal) evaluateScrollOffset(list []*Item) int {
} else if len(nums) == 1 {
return base - 1
}
+ if nums[1][0] == '/' {
+ denom := atopi(nums[1][1:])
+ if denom == 0 {
+ return base
+ }
+ return base - height/denom
+ }
return base - atopi(nums[1]) - 1
default:
return 0
@@ -1676,11 +1683,12 @@ func (t *Terminal) Loop() {
// We don't display preview window if no match
if items[0] != nil {
command := t.replacePlaceholder(commandTemplate, false, string(t.Input()), items)
- offset := t.evaluateScrollOffset(items)
+ height := t.pwindow.Height()
+ offset := t.evaluateScrollOffset(items, height)
cmd := util.ExecCommand(command, true)
if t.pwindow != nil {
env := os.Environ()
- lines := fmt.Sprintf("LINES=%d", t.pwindow.Height())
+ lines := fmt.Sprintf("LINES=%d", height)
columns := fmt.Sprintf("COLUMNS=%d", t.pwindow.Width())
env = append(env, lines)
env = append(env, "FZF_PREVIEW_"+lines)