Skip to content

Commit 93a004a

Browse files
committed
fix(viewport): optimize subline splitting by skipping lines without line endings
1 parent 538d39c commit 93a004a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

viewport/viewport.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ func (m *Model) SetContentLines(lines []string) {
240240
// iterate in reverse, so we can safely modify the slice.
241241
var subLines []string
242242
for i := len(m.lines) - 1; i >= 0; i-- {
243-
m.lines[i] = strings.ReplaceAll(m.lines[i], "\r\n", "\n") // normalize line endings
243+
if !strings.ContainsAny(m.lines[i], "\r\n") {
244+
continue
245+
}
244246

247+
m.lines[i] = strings.ReplaceAll(m.lines[i], "\r\n", "\n") // normalize line endings
245248
subLines = strings.Split(m.lines[i], "\n")
246249
if len(subLines) > 1 {
247250
m.lines = slices.Insert(m.lines, i+1, subLines[1:]...)

0 commit comments

Comments
 (0)