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

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, 8 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..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;
« 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