Skip to content

Commit 6fbe38b

Browse files
committed
Fix tooltipping snippets
1 parent fec033a commit 6fbe38b

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

scaladoc-js/resources/code-snippets.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,18 @@ input:checked + .slider:before {
112112
transform: translateX(var(--translation-size));
113113
}
114114

115-
.tooltip {
116-
position: relative;
115+
.tooltip-container {
116+
display: none;
117117
}
118-
.tooltip:hover:after {
118+
.tooltip:hover .tooltip-container {
119+
display: block;
120+
}
121+
.tooltip:hover .tooltip-container::after {
119122
content: attr(label);
120123
padding: 4px 8px;
121124
color: white;
122125
background-color:black;
123126
position: absolute;
124-
left: 0;
125127
z-index:10;
126128
box-shadow:0 0 3px #444;
127129
opacity: 0.8;

scaladoc-js/src/Main.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object Main:
1111
DropdownHandler()
1212
Ux()
1313
ContentContributors()
14+
TooltipNormalizer()
1415
common()
1516

1617
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dotty.tools.scaladoc
2+
3+
4+
import org.scalajs.dom._
5+
import org.scalajs.dom.ext._
6+
import scala.scalajs.js
7+
import scalajs.js.DynamicImplicits.truthValue
8+
9+
10+
// Handful of links
11+
// https://css-tricks.com/popping-hidden-overflow/
12+
// https://github.com/highlightjs/highlight.js/issues/728
13+
// https://stackoverflow.com/a/54482317/14320995
14+
class TooltipNormalizer:
15+
document.addEventListener("mouseover", (e: Event) => {
16+
if e.target.asInstanceOf[js.Dynamic].closest(".snippet-error.tooltip") then
17+
val tooltipParent = e.target.asInstanceOf[html.Span]
18+
val tooltipContainer = tooltipParent.querySelector(".tooltip-container")
19+
js.typeOf(tooltipContainer) match
20+
case "undefined" =>
21+
case _ =>
22+
tooltipContainer match
23+
case casted: html.Span => casted.style = s"left: ${Math.round(tooltipParent.offsetLeft)}"
24+
case _ =>
25+
})

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ code {
7777
padding: 0 .3em;
7878
}
7979
pre {
80-
overflow: visible;
80+
overflow-x: auto;
8181
scrollbar-width: thin;
8282
margin: 0px;
8383
}

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.
1313
private def attributesToString: String = attributes.updated("id", lineNo).map((key, value) => s"""$key="$value"""").mkString(" ")
1414
def toHTML =
1515
val label = if messages.nonEmpty then s"""label="${messages.map(_.escapeReservedTokens).mkString("\n")}"""" else ""
16-
s"""<span $attributesToString class="${classes.mkString(" ")}" $label>$content</span>"""
16+
s"""<span $attributesToString class="${classes.mkString(" ")}"><span class="tooltip-container" $label></span>$content</span>"""
1717

1818
object SnippetRenderer:
1919
val hiddenStartSymbol = "//{"

0 commit comments

Comments
 (0)