Code Highlighting Example - Select dropdown option text is included in text selection
See original GitHub issueIn the code highlighting example, selecting the text of the document also selects the text of the dropdown options.
This occurs because the Select
element gets wrapped up into the selection. This occurs even if you set the element’s CSS to user-select: none;
I’m running into issues related to this issue in my application. Is there some way to exclude items like this from the selection? If not, is there a better way to go about rendering elements like this in the editor?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Highlight Text Lines Based on Dropdown Selection
I want to highlight certain text lines on a pdf form if the user selects a particular option from a dropdown list on...
Read more >How to Create Actions for Selected Text With the Selection API
In this code, we first get a copy of the selection menu control inside <template> , then assign it to the control variable....
Read more >How to get the Highlighted/Selected text in JavaScript?
Time to try out the code. Run the code, select a text and press the button to show the selected text: Example: ...
Read more ><select>: The HTML Select element - HTML - MDN Web Docs
This Boolean attribute indicates that multiple options can be selected in the list. If it is not specified, then only one option can...
Read more >Options, Text Editor, General - Visual Studio - Microsoft Learn
When selected, zero-width characters are rendered in the code editor. See the following code snippet for an example of zero-width characters: C#
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey Ian, thanks for the response. I considered the
contentEditable
approach, but that would lump in images and potentially other things like checkboxes which we don’t want to filter out.I’ve determined conclusively there is no way around it with styling. Even
display: none
does nothing. At first I was absolutely baffled by this, but after spending the day poking aroundcloneFragment
, it makes perfect sense.cloneFragment
is filling thetext/html
object in the clipboard withdiv.innerHTML
, meaning as long as something appears in the HTML, it’s going to appear in the clipboard no matter what we do with styling. We can strip objects that should not be included out of the selection prior to this step either via a custom function, the serializer, or via building thetext/html
contents some other way.Interesting, I’m not sure. Portals probably? But I’d be curious if someone found a way without portals too since they are often a pain to manage.