diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 17:44:11 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 17:44:11 +0900 |
commit | 8df7d962e60bce44adda674ef8f99a2a76a4a6e7 (patch) | |
tree | b4899eda370cb82b2af12c61a16e6c1c1ce68eb5 /src | |
parent | 41e916a511f37848168a3cddf7cbd1ea1a9ba8da (diff) |
Improve rendering time of long lines
Diffstat (limited to 'src')
-rw-r--r-- | src/terminal.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/terminal.go b/src/terminal.go index ff1120a0..b6b61563 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -656,6 +656,17 @@ func trimLeft(runes []rune, width int) ([]rune, int32) { 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) { var maxe int 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) maxWidth := t.window.Width - 3 maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text)) - fullWidth := displayWidth(text) - if fullWidth > maxWidth { + if overflow(text, maxWidth) { if t.hscroll { // Stri.. - matchEndWidth := displayWidth(text[:maxe]) - if matchEndWidth <= maxWidth-2 { + if !overflow(text[:maxe], maxWidth-2) { text, _ = trimRight(text, maxWidth-2) text = append(text, []rune("..")...) } else { // Stri.. - if matchEndWidth < fullWidth-2 { + if overflow(text[maxe:], 2) { text = append(text[:maxe], []rune("..")...) } // ..ri.. |