From f10e2dd705063905e37098725eb2362ca40fcbcc Mon Sep 17 00:00:00 2001 From: Sabyrzhan Tasbolatov Date: Tue, 9 Nov 2021 15:48:27 +0600 Subject: pkg/cover: added close btn to hide syz description When we click on PC value in coverage page with the source code opened, there was no option to go back to file src code. Added a close button to hide (display:none) the syz description, and bring back the last file source code view. Fixes #2867 --- CONTRIBUTORS | 1 + pkg/cover/html.go | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d83ee9b4f..70e279967 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -99,3 +99,4 @@ Chuck Silvers Pavel Skripkin Linaro Lee Jones +Sabyrzhan Tasbolatov diff --git a/pkg/cover/html.go b/pkg/cover/html.go index 639adcf82..4e6e89cef 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -523,7 +523,7 @@ func fileContents(file *file, lines [][]byte, haveProgs bool) string { if haveProgs { prog, count := "", " " if line := file.lines[i+1]; len(line.progCount) != 0 { - prog = fmt.Sprintf("onclick='onProgClick(%v)'", line.progIndex) + prog = fmt.Sprintf("onclick='onProgClick(%v, this)'", line.progIndex) count = fmt.Sprintf("% 5v", len(line.progCount)) buf.WriteString(fmt.Sprintf("%v ", prog, count)) } @@ -848,6 +848,7 @@ var coverTemplate = template.Must(template.New("").Parse(`
+ {{range $i, $f := .Contents}}
{{$f}}
{{end}} @@ -880,26 +881,47 @@ var coverTemplate = template.Must(template.New("").Parse(` } })(); var visible; + var contentIdx; + var currentPC; function onPercentClick(index) { if (visible) visible.style.display = 'none'; visible = document.getElementById("function_" + index); visible.style.display = 'block'; document.getElementById("right_pane").scrollTo(0, 0); + toggleCloseBtn(); } function onFileClick(index) { if (visible) visible.style.display = 'none'; visible = document.getElementById("contents_" + index); visible.style.display = 'block'; + contentIdx = index; document.getElementById("right_pane").scrollTo(0, 0); + toggleCloseBtn(); } - function onProgClick(index) { + function toggleCloseBtn(showBtn) { + let display = 'none'; + if (showBtn) + display = 'block'; + document.getElementById("close-btn").style.display = display; + } + function onProgClick(index, span) { if (visible) visible.style.display = 'none'; visible = document.getElementById("prog_" + index); visible.style.display = 'block'; document.getElementById("right_pane").scrollTo(0, 0); + currentPC = span; + toggleCloseBtn(true); + } + function onCloseClick() { + if (visible) + visible.style.display = 'none'; + visible = document.getElementById("contents_" + contentIdx); + visible.style.display = 'block'; + toggleCloseBtn(); + currentPC.scrollIntoView(); } -- cgit mrf-deployment