Skip to content
Myr

Fix rendering of items with tabs when using a non-default ellipsis

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #4505

authored by Junegunn Choi · committed by Junegunn Choi · parent f2179f0 · Browse files · 1 file+9 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−9 removed

  • other:+9 added−9 removed

1 file+9 added−9 removed

modified:src/terminal.go+9 added-9 removed
2615 unmodified lines
2616 w = t.inputWindow2617 }2618 maxWidth := util.Max(1, w.Width()-t.promptLen-1)26192620 _, overflow := t.trimLeft(t.input[:t.cx], maxWidth)2620 _, overflow := t.trimLeft(t.input[:t.cx], maxWidth, 0)2621 minOffset := int(overflow)2622 maxOffset := minOffset + (maxWidth-util.Max(0, maxWidth-t.cx))/22623 t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset)2624 before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth)2624 before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth, 0)2625 beforeLen := t.displayWidth(before)2626 after, _ := t.trimRight(t.input[t.cx:], maxWidth-beforeLen)2627 afterLen := t.displayWidth(after)2628 t.queryLen = [2]int{beforeLen, afterLen}
692 unmodified lines
3321 width, _ := util.RunesWidth(runes, prefixWidth, t.tabstop, limit)3322 return width3323}33243325func (t *Terminal) trimLeft(runes []rune, width int) ([]rune, int32) {3325func (t *Terminal) trimLeft(runes []rune, width int, ellipsisWidth int) ([]rune, int32) {3326 width = util.Max(0, width)3327 var trimmed int323328 // Assume that each rune takes at least one column on screen3329 if len(runes) > width+2 {3330 diff := len(runes) - width - 23329 if len(runes) > width {3330 diff := len(runes) - width3331 trimmed = int32(diff)3332 runes = runes[diff:]3333 }33343335 currentWidth := t.displayWidth(runes)33363337 for currentWidth > width && len(runes) > 0 {3337 for currentWidth > width-ellipsisWidth && len(runes) > 0 {3338 runes = runes[1:]3339 trimmed++3340 currentWidth = t.displayWidthWithLimit(runes, 2, width)3340 currentWidth = t.displayWidthWithLimit(runes, ellipsisWidth, width)3341 }3342 return runes, trimmed3343}3344
216 unmodified lines
3561 }3562 }3563 if t.hscroll {3564 if t.keepRight && pos == nil {3565 trimmed, diff := t.trimLeft(line, maxWidth-ellipsisWidth)3565 trimmed, diff := t.trimLeft(line, maxWidth, ellipsisWidth)3566 transformOffsets(diff, false)3567 line = append(ellipsis, trimmed...)3568 } else if !t.overflow(line[:maxe], maxWidth-ellipsisWidth) {3569 // Stri..
7 unmodified lines
3577 rightTrim = true3578 }3579 // ..ri..3580 var diff int323581 line, diff = t.trimLeft(line, maxWidth-ellipsisWidth)3581 line, diff = t.trimLeft(line, maxWidth, ellipsisWidth)35823583 // Transform offsets3584 transformOffsets(diff, rightTrim)3585 line = append(ellipsis, line...)
3428 unmodified lines