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..b6c4801b2cec6c0fcc724c88a3f7ac64352e0ab6 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,31 @@ 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; |
| } |
| } |
| var chars = 0; |
| var node = itemElement; |
| - while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDescendant(container)) |
| - chars += Components.Linkifier.untruncatedNodeText(node).length; |
| + var nonTextTags = {'STYLE': 1, 'SCRIPT': 1}; |
| + while ((node = node.traverseNextNode(itemElement)) && node !== selectionNode) { |
| + var isValidTextNode = node.nodeType === Node.TEXT_NODE && !nonTextTags[node.parentElement.nodeName]; |
|
lushnikov
2017/05/09 00:39:40
nit: you can write this without having nonTextTags
luoe
2017/05/09 00:44:46
Done.
|
| + if (isValidTextNode) |
| + 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; |