summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-01-15 19:42:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-01-15 19:42:28 +0900
commite0036b5ad208f71d02447c233a621e67185b0fff (patch)
tree3f1e7a7b5e5d3d2b98a3adadc593e530484edd87 /src
parent208d4f2173c1630408b836312271b3c675ddc5eb (diff)
downloadfzf-e0036b5ad208f71d02447c233a621e67185b0fff.tar.gz
Add --filepath-word option
Close #802
Diffstat (limited to 'src')
-rw-r--r--src/options.go7
-rw-r--r--src/terminal.go19
2 files changed, 22 insertions, 4 deletions
diff --git a/src/options.go b/src/options.go
index a0653d4e..7885325e 100644
--- a/src/options.go
+++ b/src/options.go
@@ -45,6 +45,7 @@ const usage = `usage: fzf [options]
--no-hscroll Disable horizontal scroll
--hscroll-off=COL Number of screen columns to keep to the right of the
highlighted substring (default: 10)
+ --filepath-word Make word-wise movements respect path separators
--jump-labels=CHARS Label characters for jump and jump-accept
Layout
@@ -160,6 +161,7 @@ type Options struct {
Cycle bool
Hscroll bool
HscrollOff int
+ FileWord bool
InlineInfo bool
JumpLabels string
Prompt string
@@ -208,6 +210,7 @@ func defaultOptions() *Options {
Cycle: false,
Hscroll: true,
HscrollOff: 10,
+ FileWord: false,
InlineInfo: false,
JumpLabels: defaultJumpLabels,
Prompt: "> ",
@@ -976,6 +979,10 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Hscroll = false
case "--hscroll-off":
opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")
+ case "--filepath-word":
+ opts.FileWord = true
+ case "--no-filepath-word":
+ opts.FileWord = false
case "--inline-info":
opts.InlineInfo = true
case "--no-inline-info":
diff --git a/src/terminal.go b/src/terminal.go
index 3a89bb40..69735d9c 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -59,6 +59,8 @@ type Terminal struct {
reverse bool
hscroll bool
hscrollOff int
+ wordRubout string
+ wordNext string
cx int
cy int
offset int
@@ -291,6 +293,13 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
} else {
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{
initDelay: delay,
inlineInfo: opts.InlineInfo,
@@ -298,6 +307,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
reverse: opts.Reverse,
hscroll: opts.Hscroll,
hscrollOff: opts.HscrollOff,
+ wordRubout: wordRubout,
+ wordNext: wordNext,
cx: len(input),
cy: 0,
offset: 0,
@@ -1448,7 +1459,7 @@ func (t *Terminal) Loop() {
}
case actBackwardKillWord:
if t.cx > 0 {
- t.rubout("[^[:alnum:]][[:alnum:]]")
+ t.rubout(t.wordRubout)
}
case actYank:
suffix := copySlice(t.input[t.cx:])
@@ -1467,12 +1478,12 @@ func (t *Terminal) Loop() {
t.jumping = jumpAcceptEnabled
req(reqJump)
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:
- t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1
+ t.cx += findFirstMatch(t.wordNext, string(t.input[t.cx:])) + 1
case actKillWord:
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 {
t.yanked = copySlice(t.input[t.cx:ncx])
t.input = append(t.input[:t.cx], t.input[ncx:]...)