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

Range normalization fix #238

Merged
merged 3 commits into from
Jul 16, 2013
Merged

Range normalization fix #238

merged 3 commits into from
Jul 16, 2013

Conversation

csillag
Copy link
Contributor

@csillag csillag commented Jul 13, 2013

This should fix selection bugs seen on pages with weird structure.
(Thus closing #235, and taking care of the failed test cases, too.)

csillag added 2 commits July 13, 2013 02:18
This is next attempt at fixing this long-standing issue.
Some background:

When we are normalizing a browser range, we must find a text node and offset
to point to, even if the browser range is pointing to some other (nearby)
node element. (p, div, br, img, whatever).
To do this, we must do some DOM crawling.

Earlier we were trying to take some shortcuts, but that failed on some crazy
page structures. Now I added full recursive crawling ability to locate the
wanted text nodes.

This fixes all the failing Range test cases, and also fixes #235.
@@ -33,6 +33,16 @@ Util.flatten = (array) ->

flatten(array)

# Public: decides whether node A is an ancestor of node B.
#
# This function purposefully ignores the native browser function for this, because it acts weird in PhantomJS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Weird" how?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Weird" as in bogus; on some occasions, it returns "false", even when the node does contain the other.
Should I create a test case, and file a bug upstream? Yeah, I guess I should.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the issue for PhantomJS: ariya/phantomjs#11479

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to the QT5 Phantom issue in the comments so that someone who finds this later can see that it can be removed if Phantom is updated.

@nickstenning
Copy link
Member

Thanks for this. Could you please add a test to the test suite that exhibits the behaviour you're trying to fix? I have no idea what "weird" page structure or what kind of selection bugs you're talking about, and thus there's every chance someone refactoring range.coffee again could reintroduce the bugs you're fixing here.

@csillag
Copy link
Contributor Author

csillag commented Jul 14, 2013

I have already added the test cases, see this commit: d08f698 .

6 of the 16 new test cases are failing.

The proposed fix fixes them.

(I have have shamelessly pushed those to the master branch, to highlight the problem.)

@@ -59,6 +69,44 @@ Util.getTextNodes = (jq) ->

jq.map -> Util.flatten(getTextNodes(this))

# Public: determine the last text node inside or before the given node
Util.getLastTextNodeUpTo = (n) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might change these to "getPreviousTextNode" and "getNextTextNode". Maybe clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the proposed new names would be clearer, since "previous" sounds like we can not accept the current node, while in reality, we we can. So it would be a little bit misleading. (The same goes with next, too.)

@tilgovi
Copy link
Member

tilgovi commented Jul 15, 2013

Looks good overall.

tilgovi added a commit that referenced this pull request Jul 16, 2013
@tilgovi tilgovi merged commit 201d181 into master Jul 16, 2013
@tilgovi tilgovi deleted the range-normalization-fix branch July 16, 2013 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants