Improve rendering time of long lines

This commit is contained in:
Junegunn Choi 2016-08-14 17:44:11 +09:00
parent 41e916a511
commit 8df7d962e6
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -656,6 +656,17 @@ func trimLeft(runes []rune, width int) ([]rune, int32) {
return runes, trimmed return runes, trimmed
} }
func overflow(runes []rune, max int) bool {
l := 0
for _, r := range runes {
l += runeWidth(r, l)
if l > max {
return true
}
}
return false
}
func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) { func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
var maxe int var maxe int
for _, offset := range item.offsets { for _, offset := range item.offsets {
@ -668,17 +679,15 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
offsets := item.colorOffsets(col2, bold, current) offsets := item.colorOffsets(col2, bold, current)
maxWidth := t.window.Width - 3 maxWidth := t.window.Width - 3
maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text)) maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))
fullWidth := displayWidth(text) if overflow(text, maxWidth) {
if fullWidth > maxWidth {
if t.hscroll { if t.hscroll {
// Stri.. // Stri..
matchEndWidth := displayWidth(text[:maxe]) if !overflow(text[:maxe], maxWidth-2) {
if matchEndWidth <= maxWidth-2 {
text, _ = trimRight(text, maxWidth-2) text, _ = trimRight(text, maxWidth-2)
text = append(text, []rune("..")...) text = append(text, []rune("..")...)
} else { } else {
// Stri.. // Stri..
if matchEndWidth < fullWidth-2 { if overflow(text[maxe:], 2) {
text = append(text[:maxe], []rune("..")...) text = append(text[:maxe], []rune("..")...)
} }
// ..ri.. // ..ri..