Skip to content

Commit

Permalink
fix(fuzzyhelp): anchors to id should scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Mar 27, 2024
1 parent 93c55e4 commit 10e3a13
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion R/fuzzyhelp.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,23 @@ create_server <- function(method = c("fzf", "lv")) {
reactiveHelp <- shiny::reactive(
htmltools::tags$iframe(
srcdoc = get_content(reactiveToc(), reactiveSelection()),
style = "width: 100%; height: 100%;"
style = "width: 100%; height: 100%;",
id = "helpViewer",
onload = "(function(){
// replace anchors to avoid nesting shiny widgets
const pattern = document.baseURI + '#';
const iframe = document.querySelector('#helpViewer iframe');
Array.from(iframe.contentDocument.querySelectorAll('a'))
.filter(a => a.href.startsWith(pattern))
.map(a => {
const id = a.href.slice(pattern.length);
a.href = 'javascript:void(0)';
a.onclick = function() {
const top = iframe.contentDocument.getElementById(id).offsetTop;
iframe.contentWindow.scrollTo({ top: top, behavior: 'smooth' });
}
});
})();"
)
)

Expand Down

0 comments on commit 10e3a13

Please sign in to comment.