From 6468ad1dd70863bbf5aade119259ec3f84b935a1 Mon Sep 17 00:00:00 2001 From: silverweed Date: Fri, 27 Sep 2024 11:21:19 +0200 Subject: [PATCH] some fixes to highlight logic --- src/hover.cpp | 37 +++++++++++++++++++++++++++++-------- src/str.cpp | 2 ++ src/str.h | 1 + 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/hover.cpp b/src/hover.cpp index 8d24726..cefb6cc 100644 --- a/src/hover.cpp +++ b/src/hover.cpp @@ -133,19 +133,19 @@ struct Sec_Hover_Fn { // if we're in display_grouped mode, we want to highlight the entire range of the section; u64 sec_len = cur_field_off - sec_start; info.rng = { start + sec_start, sec_len }; - // In case of nested sections, only highlight the innermost - // FIXME: sometimes no section ends up highlighted! - if (innermost_section_highlighted <= cur_section_nesting) { - info.highlighted_desc = info.desc; - } - innermost_section_highlighted = max(cur_section_nesting, innermost_section_highlighted); // ended = true; } - --cur_section_nesting; + if (!info.highlighted_desc) { + info.highlighted_desc = hovered ? info.desc : prev_desc; + innermost_section_highlighted = max(cur_section_nesting, innermost_section_highlighted); + } else if (display_grouped && innermost_section_highlighted <= cur_section_nesting && hovered) { + info.highlighted_desc = info.desc; + innermost_section_highlighted = max(cur_section_nesting, innermost_section_highlighted); + } + --cur_section_nesting; info.desc = prev_desc; - return; } // returns true if `val_read` was read @@ -824,6 +824,27 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co default:; } + // If we're displaying individual values, only show the ancestry of the highlighted desc and its siblings. + // @Speed: there is probably a more efficient way to do this by construction. + if (info.highlighted_desc && !display_grouped) { + String8_Node *cur = info.highlighted_desc; + // keep the siblings of highlighted desc, but drop their children. + cur = cur->parent; + if (cur) { + for (String8_Node *child = cur->first_child; child; child = child->next) { + if (child != info.highlighted_desc) + child->first_child = child->last_child = nullptr; + } + while (cur->parent) { + // discard all other children + String8_Node *parent = cur->parent; + parent->first_child = parent->last_child = cur; + cur->next = nullptr; + cur = parent; + } + } + } + return info; } diff --git a/src/str.cpp b/src/str.cpp index 08a700d..2982a1d 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -51,6 +51,7 @@ String8_Node *push_str8_node(Arena *arena, String8_Node *prev, const char *fmt, if (prev) { prev->next = snode; snode->head = prev->head; + snode->parent = prev->parent; } else { snode->head = snode; } @@ -79,6 +80,7 @@ String8_Node *push_str8_node_child(Arena *arena, String8_Node *parent, const cha parent->last_child = parent->first_child = snode; } snode->head = parent->head; + snode->parent = parent; return snode; } diff --git a/src/str.h b/src/str.h index e2cdaba..bdeeec3 100644 --- a/src/str.h +++ b/src/str.h @@ -14,5 +14,6 @@ struct String8 { struct String8_Node { String8_Node *next, *prev, *head; String8_Node *first_child, *last_child; + String8_Node *parent; String8 str; };