some fixes to highlight logic

This commit is contained in:
silverweed 2024-09-27 11:21:19 +02:00
parent 331eec77e6
commit 6468ad1dd7
3 changed files with 32 additions and 8 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
};