mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 07:43:39 -05:00
Keep the previous delimiter before frozen columns
This commit is contained in:
@@ -3546,8 +3546,9 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
if t.freezeLeft > 0 || t.freezeRight > 0 {
|
||||
tokens = Tokenize(item.text.ToString(), t.delimiter)
|
||||
}
|
||||
// 0 1 2| 3 |4 5
|
||||
// -----> <---
|
||||
|
||||
// 0 | 1 | 2 | 3 | 4 | 5
|
||||
// ------> <------
|
||||
if t.freezeLeft > 0 {
|
||||
if len(tokens) > 0 {
|
||||
token := tokens[util.Min(t.freezeLeft, len(tokens))-1]
|
||||
@@ -3560,7 +3561,8 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
splitOffset2 = 0
|
||||
} else if index >= t.freezeLeft {
|
||||
token := tokens[index]
|
||||
splitOffset2 = int(token.prefixLength) + token.text.Length()
|
||||
delimiter := strings.TrimLeftFunc(GetLastDelimiter(token.text.ToString(), t.delimiter), unicode.IsSpace)
|
||||
splitOffset2 = int(token.prefixLength) + token.text.Length() - len([]rune(delimiter))
|
||||
}
|
||||
splitOffset2 = util.Max(splitOffset2, splitOffset1)
|
||||
}
|
||||
|
||||
@@ -234,6 +234,23 @@ func StripLastDelimiter(str string, delimiter Delimiter) string {
|
||||
return strings.TrimRightFunc(str, unicode.IsSpace)
|
||||
}
|
||||
|
||||
func GetLastDelimiter(str string, delimiter Delimiter) string {
|
||||
if delimiter.str != nil {
|
||||
if strings.HasSuffix(str, *delimiter.str) {
|
||||
return *delimiter.str
|
||||
}
|
||||
} else if delimiter.regex != nil {
|
||||
locs := delimiter.regex.FindAllStringIndex(str, -1)
|
||||
if len(locs) > 0 {
|
||||
lastLoc := locs[len(locs)-1]
|
||||
if lastLoc[1] == len(str) {
|
||||
return str[lastLoc[0]:]
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// JoinTokens concatenates the tokens into a single string
|
||||
func JoinTokens(tokens []Token) string {
|
||||
var output bytes.Buffer
|
||||
|
||||
@@ -1208,6 +1208,13 @@ class TestCore < TestInteractive
|
||||
tmux.until { |lines| assert_match(/^> 1 2 3XX.*XX9998 9999 10000$/,lines[-3]) }
|
||||
end
|
||||
|
||||
def test_freeze_left_and_right_delimiter
|
||||
tmux.send_keys %[seq 10000 | tr "\n" ' ' | sed 's/ / , /g' | #{FZF} --freeze-left 3 --freeze-right 3 --ellipsis XX --delimiter ' , '], :Enter
|
||||
tmux.until { |lines| assert_match(/XX, 9999 , 10000 ,$/, lines[-3]) }
|
||||
tmux.send_keys "'1000"
|
||||
tmux.until { |lines| assert_match(/^> 1 , 2 , 3 ,XX.*XX, 9999 , 10000 ,$/,lines[-3]) }
|
||||
end
|
||||
|
||||
def test_freeze_right_exceed_range
|
||||
tmux.send_keys %[seq 10000 | tr "\n" ' ' | #{FZF} --freeze-right 100000 --ellipsis XX], :Enter
|
||||
['', "'1000"].each do |query|
|
||||
|
||||
Reference in New Issue
Block a user