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

@ -43,6 +43,7 @@ func main() {
m := &model{
head: head,
top: head,
wrap: true,
}
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())
@ -56,6 +57,7 @@ type model struct {
termWidth, termHeight int
head, top *node
cursor int // cursor position [0, termHeight)
wrap bool
}
func (m *model) Init() tea.Cmd {
@ -216,7 +218,22 @@ func (m *model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.top.expandRecursively()
m.selectNode(at)
case key.Matches(msg, keyMap.ToggleWrap):
at := m.cursorPointsTo()
m.wrap = !m.wrap
if m.wrap {
if m.termWidth > 0 {
wrapAll(m.top, m.termWidth)
}
} else {
dropWrapAll(m.top)
}
if at.chunk != nil && at.value == nil {
at = at.parent()
}
m.selectNode(at)
}
return m, nil
}

@ -6,6 +6,15 @@ import (
"github.com/mattn/go-runewidth"
)
func dropWrapAll(n *node) {
for n != nil {
if n.value != nil && n.value[0] == '"' {
n.dropChunks()
}
n = n.next
}
}
func wrapAll(n *node, termWidth int) {
for n != nil {
if n.value != nil && n.value[0] == '"' {

Loading…
Cancel
Save