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

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: 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
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..7730c06b484e60aa5a8b88035b0c499aa940eb6d 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleViewport.js
@@ -448,6 +448,7 @@ Console.ConsoleViewport = class {
* @return {number}
*/
_textOffsetInNode(itemElement, container, offset) {
einbinder 2017/05/03 01:07:48 These names are confusing because the itemElement
luoe 2017/05/03 02:58:39 Done.
+ // If the container is not a TextNode, we may need to convert a child offset into a character offset.
if (container.nodeType !== Node.TEXT_NODE) {
if (offset < container.childNodes.length) {
container = /** @type {!Node} */ (container.childNodes.item(offset));
@@ -456,6 +457,14 @@ Console.ConsoleViewport = class {
offset = container.textContent.length;
}
}
+ // This method traverses TextNodes until the container is reached. This fails if the container is before the first
+ // TextNode. We can move the container to the next TextNode to avoid this case, which may happen if a text selection
+ // ends on an expand triangle icon.
+ if (container.textContent.length === 0 && container.nodeType !== Node.TEXT_NODE) {
einbinder 2017/05/03 01:07:48 !container.textContent.length? I don't like the id
luoe 2017/05/03 02:58:39 Done.
+ var nextTextNode = container.traverseNextTextNode(itemElement);
+ if (nextTextNode)
+ container = nextTextNode;
einbinder 2017/05/03 01:07:48 This works, but it feels uncomfortable to not have
luoe 2017/05/03 02:58:39 I can see that it seems strange at first on first
einbinder 2017/05/03 05:15:23 I guess its fine the way it was.
+ }
var chars = 0;
var node = itemElement;

Powered by Google App Engine
This is Rietveld 408576698