chrome-extension-web_inspector icon indicating copy to clipboard operation
chrome-extension-web_inspector copied to clipboard

Text Nodes Cannot Be Selected When Siblings Are Element Nodes

Open sshaw opened this issue 8 years ago • 5 comments

Given this: screen shot 2017-02-19 at 9 37 15 pm

"866 Results" cannot be selected. If I wrap it in a span, it can be.

.search-options__actions is floated right.

sshaw avatar Feb 20 '17 02:02 sshaw

@sshaw did you wrap it with a span using the browser inspect element or did you do it in your HTML code?

Is it possible to see this page?

bensampaio avatar Feb 20 '17 08:02 bensampaio

Page is not public but this demonstrates the issue:

<!DOCTYPE html>
<html lang='en'>
    <head>
        <title>Foo</title>
    </head>
    <body>
        <h1>Foo</h1>
        <div style="width:300px; margin: auto">
            <div style="float:right">
                <button>Filter</button>
            </div>
            866 results
        </div>
    </body>
</html>

Adding a span to the source fixes it.

I haven't looked at your code but from the markup it looks like it requires an element with a .chrome-extention-wi-element class. Which a text node cannot have.

sshaw avatar Feb 22 '17 04:02 sshaw

@sshaw I understand the problem now and indeed my code will never detect this case. In my opinion, having loose text nodes is never a good practice so I would say that adding a <span> to it is the correct solution. This way this element can easily be styled (if needed) and you won't get white space around the text as shown in the picture you uploaded.

bensampaio avatar Feb 27 '17 08:02 bensampaio

my code will never detect this case...

What's the issue?

In my opinion, having loose text nodes is never a good practice so I would say that adding a to it is the correct solution.

Heh. There's nothing wrong with loose text, it's definitely not a bad practice :neckbeard:.

sshaw avatar Feb 27 '17 23:02 sshaw

What's the issue?

This extension looks for terminal elements (or elements without children) and allows you to select those elements and see their properties. Otherwise you would be able to select a lot of undesirable elements that most people don't even know are there. For your specific case the div that contains "866 results" is not terminal. It contains another div as children so it will never be selectable, but the child div will.

Text nodes cannot have a class so the only possibility here would be to also allow elements that contain text nodes to be selected. However, I think this would be confusing because the parent element size won't necessarily be the size of the clicked text.

Heh. There's nothing wrong with loose text, it's definitely not a bad practice :neckbeard:.

I didn't mean to say there is something wrong with it but from my experience they never make anyones life easier.

bensampaio avatar Feb 28 '17 12:02 bensampaio