Replace eof action with cancel (#289)

This commit is contained in:
Junegunn Choi 2015-07-23 21:05:33 +09:00
parent f9136cffe6
commit fdbf3d3fec
5 changed files with 19 additions and 14 deletions

View File

@ -9,8 +9,9 @@ CHANGELOG
- Added options for sticky header - Added options for sticky header
- `--header-file` - `--header-file`
- `--header-lines` - `--header-lines`
- Added `eof` action which closes the finder only when the input is empty - Added `cancel` action which clears the input or closes the finder when the
- e.g. `export FZF_DEFAULT_OPTS="--bind esc:eof"` input is already empty
- e.g. `export FZF_DEFAULT_OPTS="--bind esc:cancel"`
- Added `delete-char/eof` action to differentiate `CTRL-D` and `DEL` - Added `delete-char/eof` action to differentiate `CTRL-D` and `DEL`
### Minor improvements/fixes ### Minor improvements/fixes

View File

@ -188,13 +188,13 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
\fBbackward-kill-word\fR \fIalt-bs\fR \fBbackward-kill-word\fR \fIalt-bs\fR
\fBbackward-word\fR \fIalt-b shift-left\fR \fBbackward-word\fR \fIalt-b shift-left\fR
\fBbeginning-of-line\fR \fIctrl-a home\fR \fBbeginning-of-line\fR \fIctrl-a home\fR
\fBcancel\fR
\fBclear-screen\fR \fIctrl-l\fR \fBclear-screen\fR \fIctrl-l\fR
\fBdelete-char\fR \fIdel\fR \fBdelete-char\fR \fIdel\fR
\fBdelete-char/eof\fR \fIctrl-d\fR \fBdelete-char/eof\fR \fIctrl-d\fR
\fBdeselect-all\fR \fBdeselect-all\fR
\fBdown\fR \fIctrl-j ctrl-n down\fR \fBdown\fR \fIctrl-j ctrl-n down\fR
\fBend-of-line\fR \fIctrl-e end\fR \fBend-of-line\fR \fIctrl-e end\fR
\fBeof\fR
\fBexecute(...)\fR (see below for the details) \fBexecute(...)\fR (see below for the details)
\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

View File

@ -501,8 +501,8 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
keymap[key] = actDeleteCharEof keymap[key] = actDeleteCharEof
case "end-of-line": case "end-of-line":
keymap[key] = actEndOfLine keymap[key] = actEndOfLine
case "eof": case "cancel":
keymap[key] = actEof keymap[key] = actCancel
case "forward-char": case "forward-char":
keymap[key] = actForwardChar keymap[key] = actForwardChar
case "forward-word": case "forward-word":

View File

@ -100,11 +100,11 @@ const (
actBackwardChar actBackwardChar
actBackwardDeleteChar actBackwardDeleteChar
actBackwardWord actBackwardWord
actCancel
actClearScreen actClearScreen
actDeleteChar actDeleteChar
actDeleteCharEof actDeleteCharEof
actEndOfLine actEndOfLine
actEof
actForwardChar actForwardChar
actForwardWord actForwardWord
actKillLine actKillLine
@ -817,9 +817,13 @@ func (t *Terminal) Loop() {
} }
case actEndOfLine: case actEndOfLine:
t.cx = len(t.input) t.cx = len(t.input)
case actEof: case actCancel:
if len(t.input) == 0 { if len(t.input) == 0 {
req(reqQuit) req(reqQuit)
} else {
t.yanked = t.input
t.input = []rune{}
t.cx = 0
} }
case actForwardChar: case actForwardChar:
if t.cx < len(t.input) { if t.cx < len(t.input) {

View File

@ -718,14 +718,14 @@ class TestGoFZF < TestBase
end end
end end
def test_eof def test_canel
tmux.send_keys "seq 100 | #{fzf "--bind 2:eof"}", :Enter tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
tmux.until { |lines| lines[-2].include?('100/100') } tmux.until { |lines| lines[-2].include?('10/10') }
tmux.send_keys '123' tmux.send_keys '123'
tmux.until do |lines| tmux.until { |lines| lines[-1] == '> 3' && lines[-2].include?('1/10') }
lines[-1] == '> 13' && lines[-2].include?('1/100') tmux.send_keys 'C-y', 'C-y'
end tmux.until { |lines| lines[-1] == '> 311' }
tmux.send_keys :BSpace, :BSpace tmux.send_keys 2
tmux.until { |lines| lines[-1] == '>' } tmux.until { |lines| lines[-1] == '>' }
tmux.send_keys 2 tmux.send_keys 2
tmux.prepare tmux.prepare