diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-02-26 16:17:12 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-02-26 16:17:12 +0900 |
| commit | 639253840fc553cc6a082b3f1275e72903ecc0eb (patch) | |
| tree | ee2f85e02020ea3e2bcc7f7afcba4caf7b698eaf /src | |
| parent | 710ebdf9c14e0c88b0cfc843ce08edcdd4554571 (diff) | |
| download | fzf-639253840fc553cc6a082b3f1275e72903ecc0eb.tar.gz | |
Trim trailing whitespaces after processing ANSI sequences
Close #4282
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.go | 1 | ||||
| -rw-r--r-- | src/options.go | 2 | ||||
| -rw-r--r-- | src/util/chars.go | 5 |
3 files changed, 7 insertions, 1 deletions
diff --git a/src/core.go b/src/core.go index 404af12a..42add205 100644 --- a/src/core.go +++ b/src/core.go @@ -135,6 +135,7 @@ func Run(opts *Options) (int, error) { return false } item.text, item.colors = ansiProcessor(stringBytes(transformed)) + item.text.TrimTrailingWhitespaces() item.text.Index = itemIndex item.origText = &data itemIndex++ diff --git a/src/options.go b/src/options.go index a526d3b7..8a9e33ff 100644 --- a/src/options.go +++ b/src/options.go @@ -778,7 +778,7 @@ func nthTransformer(str string) (func(Delimiter) func([]Token, int32) string, er } return func(Delimiter) func([]Token, int32) string { return func(tokens []Token, index int32) string { - return strings.TrimRightFunc(JoinTokens(Transform(tokens, nth)), unicode.IsSpace) + return JoinTokens(Transform(tokens, nth)) } }, nil } diff --git a/src/util/chars.go b/src/util/chars.go index adde02a6..dd037caa 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -184,6 +184,11 @@ func (chars *Chars) TrailingWhitespaces() int { return whitespaces } +func (chars *Chars) TrimTrailingWhitespaces() { + whitespaces := chars.TrailingWhitespaces() + chars.slice = chars.slice[0 : len(chars.slice)-whitespaces] +} + func (chars *Chars) TrimSuffix(runes []rune) { lastIdx := len(chars.slice) firstIdx := lastIdx - len(runes) |
