Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js |
| index b98dc1c4252cbf47dbf61172efd63861d6072453..677f20d9138c0f247f609b6ec65267c992a7458d 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js |
| @@ -443,26 +443,32 @@ Console.ConsoleViewport = class { |
| /** |
| * @param {!Element} itemElement |
| - * @param {!Node} container |
| + * @param {!Node} selectionNode |
| * @param {number} offset |
| * @return {number} |
| */ |
| - _textOffsetInNode(itemElement, container, offset) { |
| - if (container.nodeType !== Node.TEXT_NODE) { |
| - if (offset < container.childNodes.length) { |
| - container = /** @type {!Node} */ (container.childNodes.item(offset)); |
| + _textOffsetInNode(itemElement, selectionNode, offset) { |
| + // If the selectionNode is not a TextNode, we may need to convert a child offset into a character offset. |
| + if (selectionNode.nodeType !== Node.TEXT_NODE) { |
| + if (offset < selectionNode.childNodes.length) { |
| + selectionNode = /** @type {!Node} */ (selectionNode.childNodes.item(offset)); |
| offset = 0; |
| } else { |
| - offset = container.textContent.length; |
| + offset = selectionNode.textContent.length; |
| } |
| } |
| + // This method traverses TextNodes until reaching the selectionNode. This fails if selectionNode is before the first |
| + // TextNode. We can move the selectionNode to the next TextNode to avoid this case, which may happen if a text |
| + // selection ends on an expand triangle icon. |
| + if (!selectionNode.textContent.length) |
| + selectionNode = selectionNode.traverseNextTextNode(itemElement) || selectionNode; |
| var chars = 0; |
| var node = itemElement; |
| - while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDescendant(container)) |
| + while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDescendant(selectionNode)) |
|
lushnikov
2017/05/05 23:31:57
let's use node.traverseNextNode(itemElement) to fi
luoe
2017/05/05 23:48:51
Done.
|
| chars += Components.Linkifier.untruncatedNodeText(node).length; |
| // If the selection offset is at the end of a link's ellipsis, use the untruncated length as offset. |
| - var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(container).length; |
| + var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(selectionNode).length; |
| if (offset === 1 && untruncatedContainerLength > offset) |
| offset = untruncatedContainerLength; |
| return chars + offset; |