summaryrefslogtreecommitdiffstats
path: root/src/tokenizer.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-10-02 18:40:20 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-10-02 18:40:20 +0900
commit92a75c9563600a174e9ee8334853f99ed560492a (patch)
treec65a17633ee57dbfbbafa4b351c41bbbfffa3f9f /src/tokenizer.go
parent7c7a30c472463e0115adcf8bc2a792b48c03bf08 (diff)
Use trimmed length when --nth is used with --tiebreak=length
This change improves sort ordering for aligned tabular input. Given the following input: apple juice 100 apple pie 200 fzf --nth=2 will now prefer the one with pie. Before this change fzf compared "juice " and "pie ", both of which have the same length.
Diffstat (limited to 'src/tokenizer.go')
-rw-r--r--src/tokenizer.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/tokenizer.go b/src/tokenizer.go
index a8d04003..4b89b38e 100644
--- a/src/tokenizer.go
+++ b/src/tokenizer.go
@@ -20,6 +20,7 @@ type Range struct {
type Token struct {
text []rune
prefixLength int
+ trimLength int
}
// Delimiter for tokenizing the input
@@ -81,7 +82,7 @@ func withPrefixLengths(tokens [][]rune, begin int) []Token {
for idx, token := range tokens {
// Need to define a new local variable instead of the reused token to take
// the pointer to it
- ret[idx] = Token{text: token, prefixLength: prefixLength}
+ ret[idx] = Token{token, prefixLength, util.TrimLen(token)}
prefixLength += len(token)
}
return ret
@@ -233,7 +234,7 @@ func Transform(tokens []Token, withNth []Range) []Token {
} else {
prefixLength = 0
}
- transTokens[idx] = Token{part, prefixLength}
+ transTokens[idx] = Token{part, prefixLength, util.TrimLen(part)}
}
return transTokens
}