Description
Describe the issue/behavior that seems buggy
By default, in the base-16 themes, highlighting text (in the click and drag sense) hides some of the code. The problem is caused by the .hljs ::selection
css rules in the files. It seems like they should be deleted.
Sample Code or Instructions to Reproduce
Try highlighting the code in this jsfiddle, which loads Material Darker.
Here's a screenshot for what it looks like for Material Darker.
Expected behavior
Here is what I expected (I achieved this by removing the style rule in Material Darker)
Here is how highlighting code via mouse works on Github, for example.
Here is how it looks on other base 16 themes. This one is Black Metal Burzum. The second picture is what happened when I removed the css rule from the browser files.
Additional context
This is a very good and widely used project, so perhaps this is on purpose and I hope I am not misunderstanding something. However, code tends to be highlighted/selected for the purpose of copying to the clipboard, so if you are user and are trying to select up to say a specific character of text, it becomes a poor user experience if some of if it randomly disappears/becomes hard to see.
Activity
joshgoebel commentedon Sep 23, 2021
At first glance it looks like we should change this:
The problem now is only the children get the rule applied not content from the code block itself that has no other highlighting applied. Can you confirm?
ltrujello commentedon Sep 23, 2021
Do you mean for example changing
to
If so, it seems that change would still have the problem, this time only it hides non syntax-highlighted text, which actually hides more content. Here is what it looks like on my end for example:
I think it makes sense to just delete the
::selection
rule, if possible.joshgoebel commentedon Sep 24, 2021
No, BOTH rules are necessary (the parent and the children) and in my testing it looked great.
joshgoebel commentedon Sep 24, 2021
@highlightjs/core Any philosophical thoughts on whether a theme should be able to change selection color - as a matter of policy? If we wanted to be picky we could decide this "hurts usability" or violates the users choice in some way and just disallow it... but I think technically this can be fixed as I already mention above.
ltrujello commentedon Sep 24, 2021
Nothing changes on my end when I add them both, and I think that's because adding both rules is actually just what was originally the problem: only the syntax highlighted content gets the rule, not the content which has no highlighting, and because the
::selected
color is very similar to the color of the background, it hides the syntax-highlighted content.If possible, this rule should just be taken out. The default blue colors that browsers provide are perfectly fine and are what users naturally expect. Additionally, when one is selecting code via click and drag, they are probably focused and in the middle of a more important task, hence they don't need to be distracted by a random color or inconvenienced by text disappearing for a task that should be really short and simple. That's probably why most websites with syntax-highlighted code, like Github or StackOverflow, don't have any interruption or fancy coloring in the selection highlighting.
joshgoebel commentedon Sep 24, 2021
https://jsfiddle.net/pz2wkuya/
Working properly with both Safari and Chrome here. You can disagree with the visual merits, but I'm more concerned with the technical problem you first raised, which seems solvable. Now, it's worth asking if the intention of
::selected
is to use thebackground-color
, rather thancolor
... and if so, then that's a mistake on my part I think - and something we should indeed fix (which might address some of your concerns). But these are themes - a great many of them are already a matter of personal taste, and "selection color" is an official part of the Base16 spec. If you don't like it, then don't use a base16 theme, or modify the CSS to remove::selection
.So:
background-color
(vs color), which seems obvious now in hindsight.We'll change those two things and think that will improve the situation greatly and get us back to what the theme authors originally intended.
ltrujello commentedon Sep 24, 2021
The linked fiddled works and looks great! It has different CSS syntax than what one would get by just applying your initial suggestion, hence why I did not see a difference (i.e.., Material Darker's
::selection
does not have abackground-color
value and thecolor
value is notinherent
). This works great for me though.joshgoebel commentedon Sep 29, 2021
@ltrujello You want to poke around in the
base16-highlightjs
repo and see if that looks good to you? If things are all good now we'll copy these newer versions over for the next release.ltrujello commentedon Oct 3, 2021
Yes these look great! Personally I stuck with
color: inherit
suggestion instead of a fixed color, so the text selection preserves the syntax highlighting, but that is just a matter of preference. Thanks for the help!joshgoebel commentedon Oct 3, 2021
934f2e7 Should land in 11.3
allejo commentedon Oct 7, 2021
I, personally, would allow themes to change selection color. Yes, it can lead to usability issues but there's also a chance that the browser color for highlighting can conflict with the theme. I don't think existing themes should be changed to add a selection color but if there's a problem with it, then it can be fixed.
If you're a theme author and you want to torture everyone by having red on green, we won't stop you; just nobody will use your theme 🤷♂️