fix(viewport): optimize subline splitting by skipping lines without line endings

This commit is contained in:
Ayman Bagabas
2025-12-08 12:18:59 -05:00
parent 538d39c727
commit 93a004ab70
+4 -1
View File
@@ -240,8 +240,11 @@ func (m *Model) SetContentLines(lines []string) {
// iterate in reverse, so we can safely modify the slice.
var subLines []string
for i := len(m.lines) - 1; i >= 0; i-- {
m.lines[i] = strings.ReplaceAll(m.lines[i], "\r\n", "\n") // normalize line endings
if !strings.ContainsAny(m.lines[i], "\r\n") {
continue
}
m.lines[i] = strings.ReplaceAll(m.lines[i], "\r\n", "\n") // normalize line endings
subLines = strings.Split(m.lines[i], "\n")
if len(subLines) > 1 {
m.lines = slices.Insert(m.lines, i+1, subLines[1:]...)