Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

website: cannot Ctrl-F for line numbers on golang.org/src pages #23724

Closed
alexbecker opened this issue Feb 6, 2018 · 12 comments
Closed

website: cannot Ctrl-F for line numbers on golang.org/src pages #23724

alexbecker opened this issue Feb 6, 2018 · 12 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alexbecker
Copy link

Ran into this trying to debug a panic where the stack trace included crypto/tls/common.go:717. Ctrl-F searching for 717 on the line-numbered source code at https://golang.org/src/crypto/tls/common.go gave no results, leading to brief confusion and forcing me to scroll manually until I found the right line, which is much slower than using Ctrl-F.

This is because the line number nodes have no actual content, and instead are implemented as a CSS pseudo-class rule:

.ln::before {
    content: attr(data-content);
}

and setting the data-content property on each line number node. This seems user-hostile and i18n-unfriendly, not to mention needlessly complex. Why not just have a line number in the DOM?

@pciet
Copy link
Contributor

pciet commented Feb 6, 2018

That CSS pattern is also the cause of #23500

@rasky
Copy link
Member

rasky commented Feb 6, 2018

I think the wanted side-effect is that you can copy&paste code without selecting the line numbers, but maybe there's another way that doesn't break CTRL+F.

@pciet
Copy link
Contributor

pciet commented Feb 6, 2018

There could be two inline-divs in a div, left with a div for each line number and right containing the pre. The pre could be rendered and the dimensions taken to calculate the height for the line number divs. There may be another idiomatic approach though, my experience hasn't been with text layout.

@andybons andybons changed the title Cannot Ctrl-F for line numbers on golang.org/src pages website: cannot Ctrl-F for line numbers on golang.org/src pages Feb 6, 2018
@andybons
Copy link
Member

andybons commented Feb 6, 2018

@rasky is correct. This is done to prevent line numbers from appearing when you cut and paste the code.

I agree that it’s a pain not to be able to ctrl-f to line numbers. We should find a solution.

That CSS pattern is also the cause of #23500

That bug is due to a bug in Firefox. Our usage of the ::before pseudo-element is a common pattern in CSS.

The pre could be rendered and the dimensions taken to calculate the height for the line number divs.

This would Introduce even more complexity as you’re then reliant on JS for your layout. Something we’d like to avoid.

@ALTree
Copy link
Member

ALTree commented Feb 6, 2018

I personally don't like when I search in a webpage and it finds line numbers and other "background" elements... also line numbers are sequential, so scrolling to the line you're looking for is really quick.

You can also append ?#L717 to the url to jump at the line, e.g.

https://golang.org/src/crypto/tls/common.go?#L717

@andybons andybons added this to the Unplanned milestone Feb 6, 2018
@alexbecker
Copy link
Author

@rasky @andybons But there is already a rule

.ln {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

so either one of these rules isn't necessary, or this is some weird browser compatibility hack.

@ALTree Using the anchors for lines is certainly useful, but how is a user supposed to guess that each line number has been assigned an ID of the form Lxxx? In contrast I think almost all users expect to be able to reach content they can see with Ctrl-F.

@andybons
Copy link
Member

andybons commented Feb 7, 2018

@alexbecker The spec for user-select is ambiguous on the required behavior:

This specification makes no normative requirement about the behavior of the clipboard. However, UAs are encouraged to keep the visual selection consistent with what would get copied to the clipboard when copying. Copying text that does not appear to be selected, or vice versa, is highly confusing to users.

as a result, user-select (and its variants) do not behave consistently with the clipboard across all browsers. At the time this code was written, the behavior was not reliable at all.

Firefox and Chrome 64 (released two weeks ago) implement the behavior we want. Safari is still an open bug (https://bugs.webkit.org/show_bug.cgi?id=80159). Given our desktop usage, we should change to use user-select: none as you propose.

@andybons andybons added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 7, 2018
@andybons andybons assigned andybons and unassigned andybons Feb 7, 2018
@agnivade
Copy link
Contributor

agnivade commented Feb 7, 2018

So, just to be clear, this issue is about removing the

.ln::before {
    content: attr(data-content);
}

and putting the line numbers inside the span. Because user-select: none behavior is now implemented properly in FF and Chrome.

Did I get that right ?

@andybons
Copy link
Member

andybons commented Feb 7, 2018

@agnivade yes that's correct.

@agnivade
Copy link
Contributor

agnivade commented Feb 7, 2018

Cool. Waiting for 1.11 to open 😄

@pciet
Copy link
Contributor

pciet commented Feb 7, 2018

My bad, I misunderstood how this works. Sorry for the churn from my comment.

I confirmed on Chrome 64 and Firefox 58 with the debug editors that putting the line number in an ln span (with the leading tab and two   intact to preserve spacing) allows searching for line numbers without affecting code highlighting. The Firefox bug is still present in this case with content: attr(data-content); disabled.

@gopherbot
Copy link

Change https://golang.org/cl/93975 mentions this issue: godoc: allow line numbers to be searched by ctrl+f

@golang golang locked and limited conversation to collaborators Feb 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants