-
Notifications
You must be signed in to change notification settings - Fork 538
Performance fix for long documents in 1.2.x branch #577
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,13 +252,22 @@ class Range.NormalizedRange | |
| # | ||
| # Returns updated self or null. | ||
| limit: (bounds) -> | ||
| nodes = $.grep this.textNodes(), (node) -> | ||
| node.parentNode == bounds or $.contains(bounds, node.parentNode) | ||
| if @commonAncestor == bounds or $.contains(bounds, @commonAncestor) | ||
| return this | ||
|
|
||
| return null unless nodes.length | ||
| if not $.contains(@commonAncestor, bounds) | ||
| return null | ||
| document = bounds.ownerDocument | ||
|
Comment on lines
+258
to
+260
|
||
|
|
||
| @start = nodes[0] | ||
| @end = nodes[nodes.length - 1] | ||
| if not $.contains(bounds, @start) | ||
| walker = document.createTreeWalker(bounds, NodeFilter.SHOW_TEXT) | ||
| @start = walker.firstChild() | ||
|
|
||
| if not $.contains(bounds, @end) | ||
| walker = document.createTreeWalker(bounds, NodeFilter.SHOW_TEXT) | ||
| @end = walker.lastChild() | ||
|
|
||
| return null unless @start and @end | ||
|
|
||
| startParents = $(@start).parents() | ||
| for parent in $(@end).parents() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
highlightRangenow assumes every text node has aparentNode(node.parentNode.replaceChild(...)). This will throw for detached text nodes and breaks existing unit tests that pass unattacheddocument.createTextNode(...)nodes intohighlightRange. Handle theparentNode-missing case (e.g., wrap withoutreplaceChild, or skip with a clear behavior) so the method is robust and tests continue to pass.