diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e09bc..f05e680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG ```sh fzf --preview 'cat {}' --bind 'ctrl-/:change-preview-window(right,70%|down,40%,border-horizontal|hidden|right)' ``` +- Fixed rendering of the prompt line when overflow occurs with `--info=inline` 0.28.0 ------ diff --git a/src/terminal.go b/src/terminal.go index a00bf6d..e4823ad 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io/ioutil" + "math" "os" "os/signal" "regexp" @@ -709,7 +710,7 @@ func (t *Terminal) sortSelected() []selectedItem { } func (t *Terminal) displayWidth(runes []rune) int { - width, _ := util.RunesWidth(runes, 0, t.tabstop, 0) + width, _ := util.RunesWidth(runes, 0, t.tabstop, math.MaxInt32) return width } @@ -1197,7 +1198,7 @@ func (t *Terminal) printItem(result Result, line int, i int, current bool) { func (t *Terminal) trimRight(runes []rune, width int) ([]rune, bool) { // We start from the beginning to handle tab characters - width, overflowIdx := util.RunesWidth(runes, 0, t.tabstop, width) + _, overflowIdx := util.RunesWidth(runes, 0, t.tabstop, width) if overflowIdx >= 0 { return runes[:overflowIdx], true } diff --git a/src/util/util.go b/src/util/util.go index c16f1af..c3995bf 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -26,7 +26,7 @@ func RunesWidth(runes []rune, prefixWidth int, tabstop int, limit int) (int, int w = runewidth.StringWidth(s) + strings.Count(s, "\n") } width += w - if limit > 0 && width > limit { + if width > limit { return width, idx } idx += len(rs) diff --git a/src/util/util_test.go b/src/util/util_test.go index 4baa56f..45a5a2d 100644 --- a/src/util/util_test.go +++ b/src/util/util_test.go @@ -38,3 +38,19 @@ func TestOnce(t *testing.T) { t.Error("Expected: false") } } + +func TestRunesWidth(t *testing.T) { + for _, args := range [][]int{ + {100, 5, -1}, + {3, 4, 3}, + {0, 1, 0}, + } { + width, overflowIdx := RunesWidth([]rune("hello"), 0, 0, args[0]) + if width != args[1] { + t.Errorf("Expected width: %d, actual: %d", args[1], width) + } + if overflowIdx != args[2] { + t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx) + } + } +}