Do not collapse strings

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

@ -746,22 +746,16 @@ func (m *model) doSearch(s string) {
for range indexes {
m.search.results = append(m.search.results, n)
}
if n.chunk != nil && n.hasChildren() {
if n.chunk != nil {
// String can be split into chunks, so we need to map the indexes to the chunks.
chunks := [][]byte{n.chunk}
chunkNodes := []*node{n}
var it *node
if n.isCollapsed() {
it = n.collapsed
} else {
it = n.next
}
it := n.next
for it != nil {
chunkNodes = append(chunkNodes, it)
chunks = append(chunks, it.chunk)
if it == n.end {
if it == n.chunkEnd {
break
}
it = it.next

@ -13,6 +13,7 @@ type node struct {
key []byte
value []byte
chunk []byte
chunkEnd *node
comma bool
index int
}
@ -30,13 +31,13 @@ func (n *node) append(child *node) {
}
}
func (n *node) insertChild(child *node) {
if n.end == nil {
n.insertAfter(child)
func (n *node) insertChunk(chunk *node) {
if n.chunkEnd == nil {
n.insertAfter(chunk)
} else {
n.end.insertAfter(child)
n.chunkEnd.insertAfter(chunk)
}
n.end = child
n.chunkEnd = chunk
}
func (n *node) insertAfter(child *node) {
@ -53,18 +54,18 @@ func (n *node) insertAfter(child *node) {
}
func (n *node) dropChunks() {
if n.end == nil {
if n.chunkEnd == nil {
return
}
n.chunk = nil
n.next = n.end.next
n.next = n.chunkEnd.next
if n.next != nil {
n.next.prev = n
}
n.end = nil
n.chunkEnd = nil
}
func (n *node) hasChildren() bool {

@ -186,7 +186,10 @@ var themes = map[string]theme{
Number: noColor,
},
"🔵": {
Cursor: toColor(lipgloss.NewStyle().Foreground(lipgloss.Color("15")).Background(lipgloss.Color("33")).Render),
Cursor: toColor(lipgloss.NewStyle().
Foreground(lipgloss.Color("15")).
Background(lipgloss.Color("33")).
Render),
Syntax: boldFg("33"),
Preview: defaultPreview,
StatusBar: defaultStatusBar,

@ -11,7 +11,11 @@ func dropWrapAll(n *node) {
if n.value != nil && n.value[0] == '"' {
n.dropChunks()
}
n = n.next
if n.isCollapsed() {
n = n.collapsed
} else {
n = n.next
}
}
}
@ -21,10 +25,6 @@ func wrapAll(n *node, termWidth int) {
}
for n != nil {
if n.value != nil && n.value[0] == '"' {
collapsed := n.isCollapsed()
if collapsed {
n.collapsed = nil
}
n.dropChunks()
lines, count := doWrap(n, termWidth)
if count > 1 {
@ -38,12 +38,9 @@ func wrapAll(n *node, termWidth int) {
if n.comma && i == count-1 {
child.comma = true
}
n.insertChild(child)
n.insertChunk(child)
}
}
if collapsed {
n.collapse()
}
}
n = n.next
}

Loading…
Cancel
Save