@@ -402,8 +402,8 @@ func (l lineType) String() string {
402
402
return str
403
403
}
404
404
405
- // newView returns a new View object.
406
- func newView (name string , x0 , y0 , x1 , y1 int , mode OutputMode ) * View {
405
+ // NewView returns a new View object.
406
+ func NewView (name string , x0 , y0 , x1 , y1 int , mode OutputMode ) * View {
407
407
v := & View {
408
408
name : name ,
409
409
x0 : x0 ,
@@ -494,31 +494,15 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) {
494
494
bgColor = v .BgColor
495
495
ch = v .Mask
496
496
} else if v .Highlight {
497
- var ry , rcy int
498
-
499
- _ , ry , ok := v .realPosition (x , y )
500
- if ! ok {
501
- return
502
- }
503
- _ , rrcy , ok := v .realPosition (v .cx , v .cy )
504
- // out of bounds is fine
505
- if ok {
506
- rcy = rrcy
507
- }
508
-
509
- rangeSelectStart := rcy
510
- rangeSelectEnd := rcy
497
+ rangeSelectStart := v .cy
498
+ rangeSelectEnd := v .cy
511
499
if v .rangeSelectStartY != - 1 {
512
- _ , realRangeSelectStart , ok := v .realPosition (0 , v .rangeSelectStartY - v .oy )
513
- if ! ok {
514
- return
515
- }
516
-
517
- rangeSelectStart = min (realRangeSelectStart , rcy )
518
- rangeSelectEnd = max (realRangeSelectStart , rcy )
500
+ relativeRangeSelectStart := v .rangeSelectStartY - v .oy
501
+ rangeSelectStart = min (relativeRangeSelectStart , v .cy )
502
+ rangeSelectEnd = max (relativeRangeSelectStart , v .cy )
519
503
}
520
504
521
- if ry >= rangeSelectStart && ry <= rangeSelectEnd {
505
+ if y >= rangeSelectStart && y <= rangeSelectEnd {
522
506
// this ensures we use the bright variant of a colour upon highlight
523
507
fgColorComponent := fgColor & ^ AttrAll
524
508
if fgColorComponent >= AttrIsValidColor && fgColorComponent < AttrIsValidColor + 8 {
@@ -1103,6 +1087,8 @@ func (v *View) updateSearchPositions() {
1103
1087
1104
1088
if v .searcher .modelSearchResults != nil {
1105
1089
for _ , result := range v .searcher .modelSearchResults {
1090
+ // This code only works when v.Wrap is false.
1091
+
1106
1092
if result .Y >= len (v .lines ) {
1107
1093
break
1108
1094
}
@@ -1131,8 +1117,9 @@ func (v *View) updateSearchPositions() {
1131
1117
}
1132
1118
}
1133
1119
} else {
1134
- for y , line := range v .lines {
1135
- v .searcher .searchPositions = append (v .searcher .searchPositions , searchPositionsForLine (line , y )... )
1120
+ v .refreshViewLinesIfNeeded ()
1121
+ for y , line := range v .viewLines {
1122
+ v .searcher .searchPositions = append (v .searcher .searchPositions , searchPositionsForLine (line .line , y )... )
1136
1123
}
1137
1124
}
1138
1125
}
@@ -1373,6 +1360,8 @@ func (v *View) ViewBufferLines() []string {
1373
1360
v .writeMutex .Lock ()
1374
1361
defer v .writeMutex .Unlock ()
1375
1362
1363
+ v .refreshViewLinesIfNeeded ()
1364
+
1376
1365
lines := make ([]string , len (v .viewLines ))
1377
1366
for i , l := range v .viewLines {
1378
1367
str := lineType (l .line ).String ()
@@ -1512,18 +1501,20 @@ func lineWrap(line []cell, columns int) [][]cell {
1512
1501
lines = append (lines , line [offset :i ])
1513
1502
offset = i
1514
1503
n = rw
1515
- } else if lastWhitespaceIndex != - 1 && lastWhitespaceIndex + 1 != i {
1504
+ } else if lastWhitespaceIndex != - 1 {
1516
1505
// if there is a space in the line and the line is not breaking at a space/hyphen
1517
1506
if line [lastWhitespaceIndex ].chr == '-' {
1518
1507
// if break occurs at hyphen, we'll retain the hyphen
1519
1508
lines = append (lines , line [offset :lastWhitespaceIndex + 1 ])
1520
- offset = lastWhitespaceIndex + 1
1521
- n = i - offset
1522
1509
} else {
1523
1510
// if break occurs at space, we'll omit the space
1524
1511
lines = append (lines , line [offset :lastWhitespaceIndex ])
1525
- offset = lastWhitespaceIndex + 1
1526
- n = i - offset + 1
1512
+ }
1513
+ // Either way, continue *after* the break
1514
+ offset = lastWhitespaceIndex + 1
1515
+ n = 0
1516
+ for _ , c := range line [offset : i + 1 ] {
1517
+ n += runewidth .RuneWidth (c .chr )
1527
1518
}
1528
1519
} else {
1529
1520
// in this case we're breaking mid-word
0 commit comments