hmml_to_html.c: Deduplicate topics and add tooltip

Also fix bug in filter menu navigation, in which the lastFocusedElement
was not getting set after toggling a category via the keyboard
This commit is contained in:
Matt Mascarenhas 2017-06-11 23:49:04 +01:00
parent 6fd1ec3f37
commit 280102869b
2 changed files with 67 additions and 10 deletions

View File

@ -305,7 +305,7 @@ StringsDifferL(char *A, char *B, int LengthofA)
{ {
++i; ++i;
} }
if(!A[i] && LengthofA == i && B[i] == ' ') if(!A[i] && LengthofA == i && (B[i] == ' ' || B[i] == '\"'))
{ {
return FALSE; return FALSE;
} }
@ -696,11 +696,40 @@ BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, boo
*HasCategory = TRUE; *HasCategory = TRUE;
} }
CopyStringToBuffer(Category, "<div class=\"category %s\"></div>", // NOTE(matt): Iterate through the Category->Location looking for "Marker", and bail if we find it
SanitisePunctuation(Marker)); char *Ptr = Category->Location;
bool Found = FALSE;
while(*Ptr)
{
if(*Ptr == '\"')
{
++Ptr;
if(!StringsDifferL(SanitisePunctuation(Marker), Ptr, StringLength(SanitisePunctuation(Marker))))
{
Found = TRUE;
break;
}
else
{
while(*Ptr != '\"')
{
++Ptr;
}
}
}
++Ptr;
}
if(Found == FALSE)
{
CopyStringToBuffer(Category, "<div title=\"%s\" class=\"category %s\"></div>",
SanitisePunctuation(Marker),
SanitisePunctuation(Marker));
CopyStringToBuffer(AnnotationClass, " cat_%s",
SanitisePunctuation(Marker));
}
CopyStringToBuffer(AnnotationClass, " cat_%s",
SanitisePunctuation(Marker));
++*MarkerIndex; ++*MarkerIndex;
return; return;
} }
@ -1308,7 +1337,7 @@ main(int ArgC, char **Args)
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, "AnnotationClass", 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, "AnnotationClass", 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, "Text", Kilobytes(4)); ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, "Text", Kilobytes(4));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 512);
CopyStringToBuffer(&AnnotationHeader, CopyStringToBuffer(&AnnotationHeader,
" <div data-timestamp=\"%d\"", " <div data-timestamp=\"%d\"",

View File

@ -700,7 +700,18 @@ function handleKey(key) {
focusedElement.nextElementSibling.classList.contains("filter_content")) focusedElement.nextElementSibling.classList.contains("filter_content"))
{ {
focusedElement.classList.remove("focused"); focusedElement.classList.remove("focused");
focusedElement = focusedElement.nextElementSibling; if(focusedElement.parentNode.classList.contains("filter_topics"))
{
lastFocusedTopic = focusedElement.nextElementSibling;
lastFocusedCategory = lastFocusedTopic;
}
else
{
lastFocusedMedium = focusedElement.nextElementSibling;
lastFocusedCategory = lastFocusedMedium;
}
lastFocusedElement = lastFocusedCategory;
focusedElement = lastFocusedElement;
focusedElement.classList.add("focused"); focusedElement.classList.add("focused");
} }
} }
@ -714,7 +725,18 @@ function handleKey(key) {
focusedElement.previousElementSibling.classList.contains("filter_content")) focusedElement.previousElementSibling.classList.contains("filter_content"))
{ {
focusedElement.classList.remove("focused"); focusedElement.classList.remove("focused");
focusedElement = focusedElement.previousElementSibling; if(focusedElement.parentNode.classList.contains("filter_topics"))
{
lastFocusedTopic = focusedElement.previousElementSibling;
lastFocusedCategory = lastFocusedTopic;
}
else
{
lastFocusedMedium = focusedElement.previousElementSibling;
lastFocusedCategory = lastFocusedMedium;
}
lastFocusedElement = lastFocusedCategory;
focusedElement = lastFocusedElement;
focusedElement.classList.add("focused"); focusedElement.classList.add("focused");
} }
} }
@ -811,7 +833,10 @@ function filterItemToggle(filterItem) {
if(filterState[selectedCategory].off) if(filterState[selectedCategory].off)
{ {
filterItem.classList.add("off"); filterItem.classList.add("off");
filterItem.querySelector(".icon").style.backgroundColor = "transparent"; if(!filterItem.parentNode.classList.contains("filter_media"))
{
filterItem.querySelector(".icon").style.backgroundColor = "transparent";
}
var testMarkers = document.querySelectorAll(".marker." + selectedCategory + ", .marker.cat_" + selectedCategory); var testMarkers = document.querySelectorAll(".marker." + selectedCategory + ", .marker.cat_" + selectedCategory);
for(var j = 0; j < testMarkers.length; ++j) for(var j = 0; j < testMarkers.length; ++j)
{ {
@ -861,7 +886,10 @@ function filterItemToggle(filterItem) {
else else
{ {
filterItem.classList.remove("off"); filterItem.classList.remove("off");
filterItem.querySelector(".icon").style.backgroundColor = getComputedStyle(filterItem.querySelector(".icon")).getPropertyValue("border-color"); if(!filterItem.parentNode.classList.contains("filter_media"))
{
filterItem.querySelector(".icon").style.backgroundColor = getComputedStyle(filterItem.querySelector(".icon")).getPropertyValue("border-color");
}
setDotLightness(filterItem.querySelector(".icon")); setDotLightness(filterItem.querySelector(".icon"));
var testMarkers = document.querySelectorAll(".marker.off_" + selectedCategory); var testMarkers = document.querySelectorAll(".marker.off_" + selectedCategory);
for(var j = 0; j < testMarkers.length; ++j) for(var j = 0; j < testMarkers.length; ++j)