Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js

Issue 2856933006: DevTools: fix text offset when selection ends on expand triangle (Closed)
Patch Set: ac Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-copy-truncated-text-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6341e4a282ddb72bbbaf8150037b429c1ee1f4e5 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))
+ while ((node = node.traverseNextNode(itemElement)) && node !== selectionNode) {
+ if (node.nodeType !== Node.TEXT_NODE || node.parentElement.nodeName === 'STYLE' ||
+ node.parentElement.nodeName === 'SCRIPT')
+ continue;
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;
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-copy-truncated-text-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698