Add --filepath-word option

Close #802
This commit is contained in:
Junegunn Choi 2017-01-15 19:42:28 +09:00
parent 208d4f2173
commit e0036b5ad2
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
5 changed files with 49 additions and 4 deletions

View File

@ -9,6 +9,8 @@ CHANGELOG
- Latin script letters will be normalized before matching so that it's easier - Latin script letters will be normalized before matching so that it's easier
to match against accented letters. e.g. `sodanco` can match `Só Danço Samba`. to match against accented letters. e.g. `sodanco` can match `Só Danço Samba`.
- Normalization can be disabled via `--literal` - Normalization can be disabled via `--literal`
- Added `--filepath-word` to make word-wise movements/actions (`alt-b`,
`alt-f`, `alt-bs`, `alt-d`) respect path separators
0.15.9 0.15.9
------ ------

View File

@ -129,6 +129,18 @@ Number of screen columns to keep to the right of the highlighted substring
(default: 10). Setting it to a large value will cause the text to be positioned (default: 10). Setting it to a large value will cause the text to be positioned
on the center of the screen. on the center of the screen.
.TP .TP
.B "--filepath-word"
Make word-wise movements and actions respect path separators. The following
actions are affected:
\fBbackward-kill-word\fR
.br
\fBbackward-word\fR
.br
\fBforward-word\fR
.br
\fBkill-word\fR
.TP
.BI "--jump-labels=" "CHARS" .BI "--jump-labels=" "CHARS"
Label characters for \fBjump\fR and \fBjump-accept\fR Label characters for \fBjump\fR and \fBjump-accept\fR
.SS Layout .SS Layout

View File

@ -45,6 +45,7 @@ const usage = `usage: fzf [options]
--no-hscroll Disable horizontal scroll --no-hscroll Disable horizontal scroll
--hscroll-off=COL Number of screen columns to keep to the right of the --hscroll-off=COL Number of screen columns to keep to the right of the
highlighted substring (default: 10) highlighted substring (default: 10)
--filepath-word Make word-wise movements respect path separators
--jump-labels=CHARS Label characters for jump and jump-accept --jump-labels=CHARS Label characters for jump and jump-accept
Layout Layout
@ -160,6 +161,7 @@ type Options struct {
Cycle bool Cycle bool
Hscroll bool Hscroll bool
HscrollOff int HscrollOff int
FileWord bool
InlineInfo bool InlineInfo bool
JumpLabels string JumpLabels string
Prompt string Prompt string
@ -208,6 +210,7 @@ func defaultOptions() *Options {
Cycle: false, Cycle: false,
Hscroll: true, Hscroll: true,
HscrollOff: 10, HscrollOff: 10,
FileWord: false,
InlineInfo: false, InlineInfo: false,
JumpLabels: defaultJumpLabels, JumpLabels: defaultJumpLabels,
Prompt: "> ", Prompt: "> ",
@ -976,6 +979,10 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Hscroll = false opts.Hscroll = false
case "--hscroll-off": case "--hscroll-off":
opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required") opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")
case "--filepath-word":
opts.FileWord = true
case "--no-filepath-word":
opts.FileWord = false
case "--inline-info": case "--inline-info":
opts.InlineInfo = true opts.InlineInfo = true
case "--no-inline-info": case "--no-inline-info":

View File

@ -59,6 +59,8 @@ type Terminal struct {
reverse bool reverse bool
hscroll bool hscroll bool
hscrollOff int hscrollOff int
wordRubout string
wordNext string
cx int cx int
cy int cy int
offset int offset int
@ -291,6 +293,13 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
} else { } else {
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse) renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
} }
wordRubout := "[^[:alnum:]][[:alnum:]]"
wordNext := "[[:alnum:]][^[:alnum:]]|(.$)"
if opts.FileWord {
sep := regexp.QuoteMeta(string(os.PathSeparator))
wordRubout = fmt.Sprintf("%s[^%s]", sep, sep)
wordNext = fmt.Sprintf("[^%s]%s|(.$)", sep, sep)
}
return &Terminal{ return &Terminal{
initDelay: delay, initDelay: delay,
inlineInfo: opts.InlineInfo, inlineInfo: opts.InlineInfo,
@ -298,6 +307,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
reverse: opts.Reverse, reverse: opts.Reverse,
hscroll: opts.Hscroll, hscroll: opts.Hscroll,
hscrollOff: opts.HscrollOff, hscrollOff: opts.HscrollOff,
wordRubout: wordRubout,
wordNext: wordNext,
cx: len(input), cx: len(input),
cy: 0, cy: 0,
offset: 0, offset: 0,
@ -1448,7 +1459,7 @@ func (t *Terminal) Loop() {
} }
case actBackwardKillWord: case actBackwardKillWord:
if t.cx > 0 { if t.cx > 0 {
t.rubout("[^[:alnum:]][[:alnum:]]") t.rubout(t.wordRubout)
} }
case actYank: case actYank:
suffix := copySlice(t.input[t.cx:]) suffix := copySlice(t.input[t.cx:])
@ -1467,12 +1478,12 @@ func (t *Terminal) Loop() {
t.jumping = jumpAcceptEnabled t.jumping = jumpAcceptEnabled
req(reqJump) req(reqJump)
case actBackwardWord: case actBackwardWord:
t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1 t.cx = findLastMatch(t.wordRubout, string(t.input[:t.cx])) + 1
case actForwardWord: case actForwardWord:
t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1 t.cx += findFirstMatch(t.wordNext, string(t.input[t.cx:])) + 1
case actKillWord: case actKillWord:
ncx := t.cx + ncx := t.cx +
findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1 findFirstMatch(t.wordNext, string(t.input[t.cx:])) + 1
if ncx > t.cx { if ncx > t.cx {
t.yanked = copySlice(t.input[t.cx:ncx]) t.yanked = copySlice(t.input[t.cx:ncx])
t.input = append(t.input[:t.cx], t.input[ncx:]...) t.input = append(t.input[:t.cx], t.input[ncx:]...)

View File

@ -322,6 +322,19 @@ class TestGoFZF < TestBase
tmux.until { |lines| lines.last !~ /^>/ } tmux.until { |lines| lines.last !~ /^>/ }
end end
def test_file_word
tmux.send_keys "#{FZF} -q '--/foo bar/foo-bar/baz' --filepath-word", :Enter
tmux.until { |lines| lines.last =~ /^>/ }
tmux.send_keys :Escape, :b
tmux.send_keys :Escape, :b
tmux.send_keys :Escape, :b
tmux.send_keys :Escape, :d
tmux.send_keys :Escape, :f
tmux.send_keys :Escape, :BSpace
tmux.until { |lines| lines.last == '> --///baz' }
end
def test_multi_order def test_multi_order
tmux.send_keys "seq 1 10 | #{fzf :multi}", :Enter tmux.send_keys "seq 1 10 | #{fzf :multi}", :Enter
tmux.until { |lines| lines.last =~ /^>/ } tmux.until { |lines| lines.last =~ /^>/ }