summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-03-23 19:05:06 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-03-23 19:05:06 +0900
commit07b965bba18fcea575458aeb3e6cc4fc832b11f2 (patch)
tree91b8860c3cd3d653a6f0a030d052988c012ef93d
parentc39113ee41f032c72a08e015b23d00f60d61a57c (diff)
Fix ANSI color offsets when --keep-right is used
-rw-r--r--src/terminal.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 0cb45c90..cb8f13c9 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1003,10 +1003,21 @@ func (t *Terminal) printHighlighted(result Result, attr tui.Attr, col1 tui.Color
maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))
displayWidth := t.displayWidthWithLimit(text, 0, maxWidth)
if displayWidth > maxWidth {
+ transformOffsets := func(diff int32) {
+ for idx, offset := range offsets {
+ b, e := offset.offset[0], offset.offset[1]
+ b += 2 - diff
+ e += 2 - diff
+ b = util.Max32(b, 2)
+ offsets[idx].offset[0] = b
+ offsets[idx].offset[1] = util.Max32(b, e)
+ }
+ }
if t.hscroll {
if t.keepRight && pos == nil {
- text, _ = t.trimLeft(text, maxWidth-2)
- text = append([]rune(ellipsis), text...)
+ trimmed, diff := t.trimLeft(text, maxWidth-2)
+ transformOffsets(diff)
+ text = append([]rune(ellipsis), trimmed...)
} else if !t.overflow(text[:maxe], maxWidth-2) {
// Stri..
text, _ = t.trimRight(text, maxWidth-2)
@@ -1021,14 +1032,7 @@ func (t *Terminal) printHighlighted(result Result, attr tui.Attr, col1 tui.Color
text, diff = t.trimLeft(text, maxWidth-2)
// Transform offsets
- for idx, offset := range offsets {
- b, e := offset.offset[0], offset.offset[1]
- b += 2 - diff
- e += 2 - diff
- b = util.Max32(b, 2)
- offsets[idx].offset[0] = b
- offsets[idx].offset[1] = util.Max32(b, e)
- }
+ transformOffsets(diff)
text = append([]rune(ellipsis), text...)
}
} else {