question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code Highlighting Example - Select dropdown option text is included in text selection

See original GitHub issue

In the code highlighting example, selecting the text of the document also selects the text of the dropdown options.

Issue demonstration

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;

image

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:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Slapboxcommented, Aug 7, 2018

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 around cloneFragment, it makes perfect sense.

cloneFragment is filling the text/html object in the clipboard with div.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 the text/html contents some other way.

1reaction
ianstormtaylorcommented, Aug 3, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found