mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-06-03 07:50:49 +00:00
Add preview-top and preview-bottom actions
This commit is contained in:
parent
7136cfc68b
commit
151252e33a
|
@ -26,6 +26,7 @@ CHANGELOG
|
||||||
- Added `last` action to move the cursor to the last match
|
- Added `last` action to move the cursor to the last match
|
||||||
- The opposite action `top` is renamed to `first`, but `top` is still
|
- The opposite action `top` is renamed to `first`, but `top` is still
|
||||||
recognized as a synonym for backward compatibility
|
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
|
- Extended support for alt key chords: alt with any case-sensitive single character
|
||||||
```sh
|
```sh
|
||||||
fzf --bind alt-,:first,alt-.:last
|
fzf --bind alt-,:first,alt-.:last
|
||||||
|
|
|
@ -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-page-up\fR
|
||||||
\fBpreview-half-page-down\fR
|
\fBpreview-half-page-down\fR
|
||||||
\fBpreview-half-page-up\fR
|
\fBpreview-half-page-up\fR
|
||||||
|
\fBpreview-bottom\fR
|
||||||
|
\fBpreview-top\fR
|
||||||
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
||||||
\fBprint-query\fR (print query and exit)
|
\fBprint-query\fR (print query and exit)
|
||||||
\fBrefresh-preview\fR
|
\fBrefresh-preview\fR
|
||||||
|
|
|
@ -907,6 +907,10 @@ func parseKeymap(keymap map[tui.Event][]action, str string) {
|
||||||
appendAction(actTogglePreviewWrap)
|
appendAction(actTogglePreviewWrap)
|
||||||
case "toggle-sort":
|
case "toggle-sort":
|
||||||
appendAction(actToggleSort)
|
appendAction(actToggleSort)
|
||||||
|
case "preview-top":
|
||||||
|
appendAction(actPreviewTop)
|
||||||
|
case "preview-bottom":
|
||||||
|
appendAction(actPreviewBottom)
|
||||||
case "preview-up":
|
case "preview-up":
|
||||||
appendAction(actPreviewUp)
|
appendAction(actPreviewUp)
|
||||||
case "preview-down":
|
case "preview-down":
|
||||||
|
|
|
@ -253,6 +253,8 @@ const (
|
||||||
actTogglePreview
|
actTogglePreview
|
||||||
actTogglePreviewWrap
|
actTogglePreviewWrap
|
||||||
actPreview
|
actPreview
|
||||||
|
actPreviewTop
|
||||||
|
actPreviewBottom
|
||||||
actPreviewUp
|
actPreviewUp
|
||||||
actPreviewDown
|
actPreviewDown
|
||||||
actPreviewPageUp
|
actPreviewPageUp
|
||||||
|
@ -2143,12 +2145,11 @@ func (t *Terminal) Loop() {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
scrollPreview := func(amount int) {
|
scrollPreviewTo := func(newOffset int) {
|
||||||
if !t.previewer.scrollable {
|
if !t.previewer.scrollable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.previewer.following = false
|
t.previewer.following = false
|
||||||
newOffset := t.previewer.offset + amount
|
|
||||||
numLines := len(t.previewer.lines)
|
numLines := len(t.previewer.lines)
|
||||||
if t.previewOpts.cycle {
|
if t.previewOpts.cycle {
|
||||||
newOffset = (newOffset + numLines) % numLines
|
newOffset = (newOffset + numLines) % numLines
|
||||||
|
@ -2159,6 +2160,9 @@ func (t *Terminal) Loop() {
|
||||||
req(reqPreviewRefresh)
|
req(reqPreviewRefresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scrollPreviewBy := func(amount int) {
|
||||||
|
scrollPreviewTo(t.previewer.offset + amount)
|
||||||
|
}
|
||||||
for key, ret := range t.expect {
|
for key, ret := range t.expect {
|
||||||
if keyMatch(key, event) {
|
if keyMatch(key, event) {
|
||||||
t.pressed = ret
|
t.pressed = ret
|
||||||
|
@ -2211,29 +2215,37 @@ func (t *Terminal) Loop() {
|
||||||
case actToggleSort:
|
case actToggleSort:
|
||||||
t.sort = !t.sort
|
t.sort = !t.sort
|
||||||
changed = true
|
changed = true
|
||||||
|
case actPreviewTop:
|
||||||
|
if t.hasPreviewWindow() {
|
||||||
|
scrollPreviewTo(0)
|
||||||
|
}
|
||||||
|
case actPreviewBottom:
|
||||||
|
if t.hasPreviewWindow() {
|
||||||
|
scrollPreviewTo(len(t.previewer.lines) - t.pwindow.Height())
|
||||||
|
}
|
||||||
case actPreviewUp:
|
case actPreviewUp:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(-1)
|
scrollPreviewBy(-1)
|
||||||
}
|
}
|
||||||
case actPreviewDown:
|
case actPreviewDown:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(1)
|
scrollPreviewBy(1)
|
||||||
}
|
}
|
||||||
case actPreviewPageUp:
|
case actPreviewPageUp:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(-t.pwindow.Height())
|
scrollPreviewBy(-t.pwindow.Height())
|
||||||
}
|
}
|
||||||
case actPreviewPageDown:
|
case actPreviewPageDown:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(t.pwindow.Height())
|
scrollPreviewBy(t.pwindow.Height())
|
||||||
}
|
}
|
||||||
case actPreviewHalfPageUp:
|
case actPreviewHalfPageUp:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(-t.pwindow.Height() / 2)
|
scrollPreviewBy(-t.pwindow.Height() / 2)
|
||||||
}
|
}
|
||||||
case actPreviewHalfPageDown:
|
case actPreviewHalfPageDown:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(t.pwindow.Height() / 2)
|
scrollPreviewBy(t.pwindow.Height() / 2)
|
||||||
}
|
}
|
||||||
case actBeginningOfLine:
|
case actBeginningOfLine:
|
||||||
t.cx = 0
|
t.cx = 0
|
||||||
|
@ -2474,7 +2486,7 @@ func (t *Terminal) Loop() {
|
||||||
t.vmove(me.S, true)
|
t.vmove(me.S, true)
|
||||||
req(reqList)
|
req(reqList)
|
||||||
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
|
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
|
||||||
scrollPreview(-me.S)
|
scrollPreviewBy(-me.S)
|
||||||
}
|
}
|
||||||
} else if t.window.Enclose(my, mx) {
|
} else if t.window.Enclose(my, mx) {
|
||||||
mx -= t.window.Left()
|
mx -= t.window.Left()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user