mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-09 08:32:01 -07:00
Support preview scroll offset relative to window height
Related: https://github.com/junegunn/fzf.vim/issues/1092
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user