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

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

Issue 2644753002: DevTools: untruncate links on copy (Closed)
Patch Set: a 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 this._itemCount = 0; 64 this._itemCount = 0;
65 65
66 // Listen for any changes to descendants and trigger a refresh. This ensures 66 // Listen for any changes to descendants and trigger a refresh. This ensures
67 // that items updated asynchronously will not break stick-to-bottom behavior 67 // that items updated asynchronously will not break stick-to-bottom behavior
68 // if they change the scroll height. 68 // if they change the scroll height.
69 this._observer = new MutationObserver(this.refresh.bind(this)); 69 this._observer = new MutationObserver(this.refresh.bind(this));
70 this._observerConfig = {childList: true, subtree: true}; 70 this._observerConfig = {childList: true, subtree: true};
71 } 71 }
72 72
73 /** 73 /**
74 * @param {!Node} node
75 * @return {string}
76 */
77 static contentTransform(node) {
78 var originalLinkText = Components.Linkifier.originalLinkText(node.parentElem ent);
79 return typeof originalLinkText === 'string' ? originalLinkText : node.textCo ntent;
allada 2017/03/28 01:13:08 nit: return originalLinkText === null ? node.textC
luoe 2017/03/31 21:35:21 Done. Empty strings is a good case to consider, b
allada 2017/03/31 23:17:33 Acknowledged.
80 }
81
82 /**
74 * @return {boolean} 83 * @return {boolean}
75 */ 84 */
76 stickToBottom() { 85 stickToBottom() {
77 return this._stickToBottom; 86 return this._stickToBottom;
78 } 87 }
79 88
80 /** 89 /**
81 * @param {boolean} value 90 * @param {boolean} value
82 */ 91 */
83 setStickToBottom(value) { 92 setStickToBottom(value) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 var endSelection = null; 425 var endSelection = null;
417 if (this._selectionIsBackward) { 426 if (this._selectionIsBackward) {
418 startSelection = this._headSelection; 427 startSelection = this._headSelection;
419 endSelection = this._anchorSelection; 428 endSelection = this._anchorSelection;
420 } else { 429 } else {
421 startSelection = this._anchorSelection; 430 startSelection = this._anchorSelection;
422 endSelection = this._headSelection; 431 endSelection = this._headSelection;
423 } 432 }
424 433
425 var textLines = []; 434 var textLines = [];
426 for (var i = startSelection.item; i <= endSelection.item; ++i) 435 for (var i = startSelection.item; i <= endSelection.item; ++i) {
427 textLines.push(this._providerElement(i).element().deepTextContent()); 436 var currElement = this._providerElement(i).element();
437 var lineContent = currElement.childTextNodes().map(Console.ConsoleViewport .contentTransform).join('');
438 textLines.push(lineContent);
439 }
428 440
429 var endSelectionElement = this._providerElement(endSelection.item).element() ; 441 var endSelectionElement = this._providerElement(endSelection.item).element() ;
430 if (endSelection.node && endSelection.node.isSelfOrDescendant(endSelectionEl ement)) { 442 if (endSelection.node && endSelection.node.isSelfOrDescendant(endSelectionEl ement)) {
431 var itemTextOffset = this._textOffsetInNode(endSelectionElement, endSelect ion.node, endSelection.offset); 443 var itemTextOffset = this._textOffsetInNode(endSelectionElement, endSelect ion.node, endSelection.offset);
432 textLines[textLines.length - 1] = textLines.peekLast().substring(0, itemTe xtOffset); 444 textLines[textLines.length - 1] = textLines.peekLast().substring(0, itemTe xtOffset);
433 } 445 }
434 446
435 var startSelectionElement = this._providerElement(startSelection.item).eleme nt(); 447 var startSelectionElement = this._providerElement(startSelection.item).eleme nt();
436 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec tionElement)) { 448 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec tionElement)) {
437 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe lection.node, startSelection.offset); 449 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe lection.node, startSelection.offset);
(...skipping 11 matching lines...) Expand all
449 */ 461 */
450 _textOffsetInNode(itemElement, container, offset) { 462 _textOffsetInNode(itemElement, container, offset) {
451 if (container.nodeType !== Node.TEXT_NODE) { 463 if (container.nodeType !== Node.TEXT_NODE) {
452 if (offset < container.childNodes.length) { 464 if (offset < container.childNodes.length) {
453 container = /** @type {!Node} */ (container.childNodes.item(offset)); 465 container = /** @type {!Node} */ (container.childNodes.item(offset));
454 offset = 0; 466 offset = 0;
455 } else { 467 } else {
456 offset = container.textContent.length; 468 offset = container.textContent.length;
457 } 469 }
458 } 470 }
471 // To calculate the correct offset, this assumes that links truncate from th e middle.
472 var originalLinkText = Components.Linkifier.originalLinkText(container.paren tElement);
473 if (typeof originalLinkText === 'string') {
474 var truncatedLength = originalLinkText.length - container.textContent.leng th;
475 if (offset > container.textContent.length >> 1)
476 offset += truncatedLength;
477 }
459 var chars = 0; 478 var chars = 0;
460 var node = itemElement; 479 var node = itemElement;
461 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container)) 480 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container))
462 chars += node.textContent.length; 481 chars += Console.ConsoleViewport.contentTransform(node).length;
463 return chars + offset; 482 return chars + offset;
464 } 483 }
465 484
466 /** 485 /**
467 * @param {!Event} event 486 * @param {!Event} event
468 */ 487 */
469 _onScroll(event) { 488 _onScroll(event) {
470 this.refresh(); 489 this.refresh();
471 } 490 }
472 491
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 Console.ConsoleViewportElement.prototype = { 617 Console.ConsoleViewportElement.prototype = {
599 willHide() {}, 618 willHide() {},
600 619
601 wasShown() {}, 620 wasShown() {},
602 621
603 /** 622 /**
604 * @return {!Element} 623 * @return {!Element}
605 */ 624 */
606 element() {}, 625 element() {},
607 }; 626 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698