From ce871d178848e3eea1e8795e5cfb74053dde4bb9 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 14 Feb 2018 18:36:10 +0530 Subject: [PATCH] godoc: allow line numbers to be searched by ctrl+f We used a css-pseudo class rule to move the line number inside the pseudo element. The idea was to prevent line numbers from getting selected while copying the code. But this was already implemented with the "user-select: none" rule. Since the spec was undefined on "user-select", we had to resort to the pseudo-class, but now both FF and Chrome implement the correct behavior. Hence, moving the content to be inside the span, and removing the pseudo-class rule. Manually tested with Chrome 63 and Firefox 58 on Ubuntu. Fixes golang/go#23724 Change-Id: I3e733db766b44875ba6bc3f6985cde2559d116e2 Reviewed-on: https://go-review.googlesource.com/93975 Run-TryBot: Andrew Bonventre TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- godoc/server.go | 2 +- godoc/static/static.go | 6 +----- godoc/static/style.css | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/godoc/server.go b/godoc/server.go index 3ebff5c5..95b47754 100644 --- a/godoc/server.go +++ b/godoc/server.go @@ -644,7 +644,7 @@ func formatGoSource(buf *bytes.Buffer, text []byte, links []analysis.Link, patte // The first tab for the code snippet needs to start in column 9, so // it indents a full 8 spaces, hence the two nbsp's. Otherwise the tab // character only indents about two spaces. - fmt.Fprintf(saved, `  `, n, n) + fmt.Fprintf(saved, `%6d  `, n, n) n++ saved.Write(line) saved.WriteByte('\n') diff --git a/godoc/static/static.go b/godoc/static/static.go index dec963a0..14739d80 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -2915,11 +2915,7 @@ pre .ln { -ms-user-select: none; user-select: none; } -.ln::before { - /* Inserting the line numbers as a ::before pseudo-element avoids making - * them selectable; it's the trick Github uses as well. */ - content: attr(data-content); -} + body { color: #222; } diff --git a/godoc/static/style.css b/godoc/static/style.css index e4d1e4c3..79989eea 100644 --- a/godoc/static/style.css +++ b/godoc/static/style.css @@ -37,11 +37,7 @@ pre .ln { -ms-user-select: none; user-select: none; } -.ln::before { - /* Inserting the line numbers as a ::before pseudo-element avoids making - * them selectable; it's the trick Github uses as well. */ - content: attr(data-content); -} + body { color: #222; }