Add "last" action to move the cursor to the last match

This is the opposite of "first" (previously known as "top").
This commit is contained in:
Junegunn Choi 2020-12-30 01:51:25 +09:00
parent e9bc7331bd
commit 0de7ab18f6
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
5 changed files with 20 additions and 10 deletions

View File

@ -23,6 +23,9 @@ CHANGELOG
# Write "regular" if you want to clear the attributes # Write "regular" if you want to clear the attributes
fzf --color hl:176:regular,hl+:177:regular fzf --color hl:176:regular,hl+:177:regular
``` ```
- 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
0.24.4 0.24.4
------ ------

View File

@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
.. ..
.TH fzf 1 "Dec 2020" "fzf 0.24.4" "fzf - a command-line fuzzy finder" .TH fzf 1 "Dec 2020" "fzf 0.24.5" "fzf - a command-line fuzzy finder"
.SH NAME .SH NAME
fzf - a command-line fuzzy finder fzf - a command-line fuzzy finder
@ -750,8 +750,8 @@ or any single character
Triggered whenever the query string is changed Triggered whenever the query string is changed
e.g. e.g.
\fB# Moves cursor to the top (or bottom depending on --layout) whenever the query is changed \fB# Move cursor to the first entry whenever the query is changed
fzf --bind change:top\fR fzf --bind change:first\fR
.RE .RE
\fIbackward-eof\fR \fIbackward-eof\fR
@ -788,6 +788,7 @@ A key or an event can be bound to one or more of the following actions.
\fBend-of-line\fR \fIctrl-e end\fR \fBend-of-line\fR \fIctrl-e end\fR
\fBexecute(...)\fR (see below for the details) \fBexecute(...)\fR (see below for the details)
\fBexecute-silent(...)\fR (see below for the details) \fBexecute-silent(...)\fR (see below for the details)
\fBfirst\fR (move to the first match)
\fBforward-char\fR \fIctrl-f right\fR \fBforward-char\fR \fIctrl-f right\fR
\fBforward-word\fR \fIalt-f shift-right\fR \fBforward-word\fR \fIalt-f shift-right\fR
\fBignore\fR \fBignore\fR
@ -795,6 +796,7 @@ A key or an event can be bound to one or more of the following actions.
\fBjump-accept\fR (jump and accept) \fBjump-accept\fR (jump and accept)
\fBkill-line\fR \fBkill-line\fR
\fBkill-word\fR \fIalt-d\fR \fBkill-word\fR \fIalt-d\fR
\fBlast\fR (move to the last match)
\fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR) \fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)
\fBpage-down\fR \fIpgdn\fR \fBpage-down\fR \fIpgdn\fR
\fBpage-up\fR \fIpgup\fR \fBpage-up\fR \fIpgup\fR
@ -822,7 +824,6 @@ A key or an event can be bound to one or more of the following actions.
\fBtoggle-preview-wrap\fR \fBtoggle-preview-wrap\fR
\fBtoggle-sort\fR \fBtoggle-sort\fR
\fBtoggle+up\fR \fIbtab (shift-tab)\fR \fBtoggle+up\fR \fIbtab (shift-tab)\fR
\fBtop\fR (move to the top result)
\fBunix-line-discard\fR \fIctrl-u\fR \fBunix-line-discard\fR \fIctrl-u\fR
\fBunix-word-rubout\fR \fIctrl-w\fR \fBunix-word-rubout\fR \fIctrl-w\fR
\fBup\fR \fIctrl-k ctrl-p up\fR \fBup\fR \fIctrl-k ctrl-p up\fR

View File

@ -879,8 +879,10 @@ func parseKeymap(keymap map[int][]action, str string) {
appendAction(actDown) appendAction(actDown)
case "up": case "up":
appendAction(actUp) appendAction(actUp)
case "top": case "first", "top":
appendAction(actTop) appendAction(actFirst)
case "last":
appendAction(actLast)
case "page-up": case "page-up":
appendAction(actPageUp) appendAction(actPageUp)
case "page-down": case "page-down":

View File

@ -246,7 +246,7 @@ func TestBind(t *testing.T) {
"f1:execute(ls {+})+abort+execute(echo {+})+select-all,f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+ "f1:execute(ls {+})+abort+execute(echo {+})+select-all,f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
"alt-a:execute-Multi@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};,"+ "alt-a:execute-Multi@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};,"+
"x:Execute(foo+bar),X:execute/bar+baz/"+ "x:Execute(foo+bar),X:execute/bar+baz/"+
",f1:+top,f1:+top"+ ",f1:+first,f1:+top"+
",,:abort,::accept,+:execute:++\nfoobar,Y:execute(baz)+up") ",,:abort,::accept,+:execute:++\nfoobar,Y:execute(baz)+up")
check(tui.CtrlA, "", actKillLine) check(tui.CtrlA, "", actKillLine)
check(tui.CtrlB, "", actToggleSort, actUp, actDown) check(tui.CtrlB, "", actToggleSort, actUp, actDown)
@ -254,7 +254,7 @@ func TestBind(t *testing.T) {
check(tui.AltZ+',', "", actAbort) check(tui.AltZ+',', "", actAbort)
check(tui.AltZ+':', "", actAccept) check(tui.AltZ+':', "", actAccept)
check(tui.AltZ, "", actPageDown) check(tui.AltZ, "", actPageDown)
check(tui.F1, "ls {+}", actExecute, actAbort, actExecute, actSelectAll, actTop, actTop) check(tui.F1, "ls {+}", actExecute, actAbort, actExecute, actSelectAll, actFirst, actFirst)
check(tui.F2, "echo {}, {}, {}", actExecute) check(tui.F2, "echo {}, {}, {}", actExecute)
check(tui.F3, "echo '({})'", actExecute) check(tui.F3, "echo '({})'", actExecute)
check(tui.F4, "less {}", actExecute) check(tui.F4, "less {}", actExecute)

View File

@ -265,7 +265,8 @@ const (
actExecuteSilent actExecuteSilent
actExecuteMulti // Deprecated actExecuteMulti // Deprecated
actSigStop actSigStop
actTop actFirst
actLast
actReload actReload
) )
@ -2366,9 +2367,12 @@ func (t *Terminal) Loop() {
t.version++ t.version++
req(reqList, reqInfo) req(reqList, reqInfo)
} }
case actTop: case actFirst:
t.vset(0) t.vset(0)
req(reqList) req(reqList)
case actLast:
t.vset(t.merger.Length() - 1)
req(reqList)
case actUnixLineDiscard: case actUnixLineDiscard:
beof = len(t.input) == 0 beof = len(t.input) == 0
if t.cx > 0 { if t.cx > 0 {