From eecdac930e2c5e3a73a1fea1e277e56e4e238510 Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 25 Jul 2023 21:21:30 +0200 Subject: [PATCH] View HTML: Show matched rules: ignore style & tweaks on long-press On long-press on the "Show matched stylesheets rules" buttons, ignore those from our epub.css/html5.css and from styletweaks, which may make investigating a book style simpler without their noise. --- frontend/document/credocument.lua | 4 ++-- frontend/ui/viewhtml.lua | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 567078368..48ab86bff 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -946,8 +946,8 @@ function CreDocument:getHTMLFromXPointers(xp0, xp1, flags, from_root_node) end end -function CreDocument:getStylesheetsMatchingRulesets(node_dataindex) - return self._document:getStylesheetsMatchingRulesets(node_dataindex) +function CreDocument:getStylesheetsMatchingRulesets(node_dataindex, with_main_stylesheet) + return self._document:getStylesheetsMatchingRulesets(node_dataindex, with_main_stylesheet) end function CreDocument:getNormalizedXPointer(xp) diff --git a/frontend/ui/viewhtml.lua b/frontend/ui/viewhtml.lua index b7902963f..f0c93283e 100644 --- a/frontend/ui/viewhtml.lua +++ b/frontend/ui/viewhtml.lua @@ -353,12 +353,20 @@ function ViewHtml:_handleLongPress(document, css_selectors_offsets, offset_shift callback = function() self:_showMatchingSelectors(document, ancestors, false) end, + hold_callback = function() + -- skip main stylesheet and style tweaks + self:_showMatchingSelectors(document, ancestors, false, false) + end, }}) table.insert(copy_buttons, {{ text = _("Show matched stylesheets rules (all ancestors)"), callback = function() self:_showMatchingSelectors(document, ancestors, true) end, + hold_callback = function() + -- skip main stylesheet and style tweaks + self:_showMatchingSelectors(document, ancestors, true, false) + end, }}) local ButtonDialogTitle = require("ui/widget/buttondialogtitle") @@ -372,11 +380,11 @@ function ViewHtml:_handleLongPress(document, css_selectors_offsets, offset_shift UIManager:show(widget) end -function ViewHtml:_showMatchingSelectors(document, ancestors, show_all_ancestors) +function ViewHtml:_showMatchingSelectors(document, ancestors, show_all_ancestors, with_main_stylesheet) local snippets if not show_all_ancestors then local node_dataindex = ancestors[1][2] - snippets = document:getStylesheetsMatchingRulesets(node_dataindex) + snippets = document:getStylesheetsMatchingRulesets(node_dataindex, with_main_stylesheet) else snippets = {} local elements = {} @@ -391,8 +399,11 @@ function ViewHtml:_showMatchingSelectors(document, ancestors, show_all_ancestors table.insert(snippets, "") end local desc = table.concat(elements, " > ", 1, #ancestors - i + 1) - table.insert(snippets, "/* ====== " .. desc .. " */") - util.arrayAppend(snippets, document:getStylesheetsMatchingRulesets(node_dataindex)) + -- We use Unicode solid black blocks to make these really visible + table.insert(snippets, "/* \u{259B}" .. ("\u{2580}"):rep(20) .. " */") + table.insert(snippets, "/* \u{258C}" .. desc .. " */") + table.insert(snippets, "/* \u{2599}" .. ("\u{2584}"):rep(20) .. " */") + util.arrayAppend(snippets, document:getStylesheetsMatchingRulesets(node_dataindex, with_main_stylesheet)) end end