summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-12-31 12:54:58 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-12-31 12:57:57 +0900
commit151252e33a225fd556bc972975be81c3c9d1bdc0 (patch)
tree758215c420dbb410ea3b0de01fdfb70d3a57a7bb
parent7136cfc68bfb1b306d801ad8a5094a30c79b544d (diff)
Add preview-top and preview-bottom actions
-rw-r--r--CHANGELOG.md1
-rw-r--r--man/man1/fzf.12
-rw-r--r--src/options.go4
-rw-r--r--src/terminal.go30
4 files changed, 28 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 77296b09..5e650af9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ CHANGELOG
- Added `last` action to move the cursor to the last match
- The opposite action `top` is renamed to `first`, but `top` is still
recognized as a synonym for backward compatibility
+- Added `preview-top` and `preview-bottom` actions
- Extended support for alt key chords: alt with any case-sensitive single character
```sh
fzf --bind alt-,:first,alt-.:last
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index f0161cd9..e976a5a2 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -805,6 +805,8 @@ A key or an event can be bound to one or more of the following actions.
\fBpreview-page-up\fR
\fBpreview-half-page-down\fR
\fBpreview-half-page-up\fR
+ \fBpreview-bottom\fR
+ \fBpreview-top\fR
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
\fBprint-query\fR (print query and exit)
\fBrefresh-preview\fR
diff --git a/src/options.go b/src/options.go
index 840f1764..691934ed 100644
--- a/src/options.go
+++ b/src/options.go
@@ -907,6 +907,10 @@ func parseKeymap(keymap map[tui.Event][]action, str string) {
appendAction(actTogglePreviewWrap)
case "toggle-sort":
appendAction(actToggleSort)
+ case "preview-top":
+ appendAction(actPreviewTop)
+ case "preview-bottom":
+ appendAction(actPreviewBottom)
case "preview-up":
appendAction(actPreviewUp)
case "preview-down":
diff --git a/src/terminal.go b/src/terminal.go
index 00370b3b..e630db4e 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -253,6 +253,8 @@ const (
actTogglePreview
actTogglePreviewWrap
actPreview
+ actPreviewTop
+ actPreviewBottom
actPreviewUp
actPreviewDown
actPreviewPageUp
@@ -2143,12 +2145,11 @@ func (t *Terminal) Loop() {
}
return false
}
- scrollPreview := func(amount int) {
+ scrollPreviewTo := func(newOffset int) {
if !t.previewer.scrollable {
return
}
t.previewer.following = false
- newOffset := t.previewer.offset + amount
numLines := len(t.previewer.lines)
if t.previewOpts.cycle {
newOffset = (newOffset + numLines) % numLines
@@ -2159,6 +2160,9 @@ func (t *Terminal) Loop() {
req(reqPreviewRefresh)
}
}
+ scrollPreviewBy := func(amount int) {
+ scrollPreviewTo(t.previewer.offset + amount)
+ }
for key, ret := range t.expect {
if keyMatch(key, event) {
t.pressed = ret
@@ -2211,29 +2215,37 @@ func (t *Terminal) Loop() {
case actToggleSort:
t.sort = !t.sort
changed = true
+ case actPreviewTop:
+ if t.hasPreviewWindow() {
+ scrollPreviewTo(0)
+ }
+ case actPreviewBottom:
+ if t.hasPreviewWindow() {
+ scrollPreviewTo(len(t.previewer.lines) - t.pwindow.Height())
+ }
case actPreviewUp:
if t.hasPreviewWindow() {
- scrollPreview(-1)
+ scrollPreviewBy(-1)
}
case actPreviewDown:
if t.hasPreviewWindow() {
- scrollPreview(1)
+ scrollPreviewBy(1)
}
case actPreviewPageUp:
if t.hasPreviewWindow() {
- scrollPreview(-t.pwindow.Height())
+ scrollPreviewBy(-t.pwindow.Height())
}
case actPreviewPageDown:
if t.hasPreviewWindow() {
- scrollPreview(t.pwindow.Height())
+ scrollPreviewBy(t.pwindow.Height())
}
case actPreviewHalfPageUp:
if t.hasPreviewWindow() {
- scrollPreview(-t.pwindow.Height() / 2)
+ scrollPreviewBy(-t.pwindow.Height() / 2)
}
case actPreviewHalfPageDown:
if t.hasPreviewWindow() {
- scrollPreview(t.pwindow.Height() / 2)
+ scrollPreviewBy(t.pwindow.Height() / 2)
}
case actBeginningOfLine:
t.cx = 0
@@ -2474,7 +2486,7 @@ func (t *Terminal) Loop() {
t.vmove(me.S, true)
req(reqList)
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
- scrollPreview(-me.S)
+ scrollPreviewBy(-me.S)
}
} else if t.window.Enclose(my, mx) {
mx -= t.window.Left()