pull/268/head
Anton Medvedev 9 months ago
parent 2f585b749a
commit 2b9c5e47ac
No known key found for this signature in database

@ -69,9 +69,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
m.termWidth = msg.Width
m.termHeight = msg.Height
if m.termWidth > 0 {
wrapAll(m.top, m.termWidth)
}
wrapAll(m.top, m.termWidth)
case tea.MouseMsg:
switch msg.Type {
@ -222,9 +220,7 @@ func (m *model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
at := m.cursorPointsTo()
m.wrap = !m.wrap
if m.wrap {
if m.termWidth > 0 {
wrapAll(m.top, m.termWidth)
}
wrapAll(m.top, m.termWidth)
} else {
dropWrapAll(m.top)
}

@ -16,6 +16,9 @@ func dropWrapAll(n *node) {
}
func wrapAll(n *node, termWidth int) {
if termWidth <= 0 {
return
}
for n != nil {
if n.value != nil && n.value[0] == '"' {
collapsed := n.isCollapsed()
@ -65,17 +68,12 @@ func doWrap(n *node, termWidth int) ([][]byte, int) {
r, size := utf8.DecodeRune(b)
w := runewidth.RuneWidth(r)
if width+w > termWidth {
if linesCount == 0 {
lines = append(lines, n.value[start:end])
} else {
lines = append(lines, n.value[start:end])
}
lines = append(lines, n.value[start:end])
start = end
width = int(n.depth) * 2
linesCount++
} else {
width += w
}
width += w
end += size
b = b[size:]
}

Loading…
Cancel
Save