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

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

Issue 2644753002: DevTools: untruncate links on copy (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 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 var endSelection = null; 416 var endSelection = null;
417 if (this._selectionIsBackward) { 417 if (this._selectionIsBackward) {
418 startSelection = this._headSelection; 418 startSelection = this._headSelection;
419 endSelection = this._anchorSelection; 419 endSelection = this._anchorSelection;
420 } else { 420 } else {
421 startSelection = this._anchorSelection; 421 startSelection = this._anchorSelection;
422 endSelection = this._headSelection; 422 endSelection = this._headSelection;
423 } 423 }
424 424
425 var textLines = []; 425 var textLines = [];
426 for (var i = startSelection.item; i <= endSelection.item; ++i) 426 for (var i = startSelection.item; i <= endSelection.item; ++i) {
427 textLines.push(this._providerElement(i).element().deepTextContent()); 427 var currElement = this._providerElement(i).element();
428 var lineContent = currElement.childTextNodes().map(Components.DOMPresentat ionUtils.originalNodeText).join('');
429 textLines.push(lineContent);
430 }
428 431
429 var endSelectionElement = this._providerElement(endSelection.item).element() ; 432 var endSelectionElement = this._providerElement(endSelection.item).element() ;
430 if (endSelection.node && endSelection.node.isSelfOrDescendant(endSelectionEl ement)) { 433 if (endSelection.node && endSelection.node.isSelfOrDescendant(endSelectionEl ement)) {
431 var itemTextOffset = this._textOffsetInNode(endSelectionElement, endSelect ion.node, endSelection.offset); 434 var itemTextOffset = this._textOffsetInNode(endSelectionElement, endSelect ion.node, endSelection.offset);
432 textLines[textLines.length - 1] = textLines.peekLast().substring(0, itemTe xtOffset); 435 textLines[textLines.length - 1] = textLines.peekLast().substring(0, itemTe xtOffset);
433 } 436 }
434 437
435 var startSelectionElement = this._providerElement(startSelection.item).eleme nt(); 438 var startSelectionElement = this._providerElement(startSelection.item).eleme nt();
436 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec tionElement)) { 439 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec tionElement)) {
437 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe lection.node, startSelection.offset); 440 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe lection.node, startSelection.offset);
(...skipping 11 matching lines...) Expand all
449 */ 452 */
450 _textOffsetInNode(itemElement, container, offset) { 453 _textOffsetInNode(itemElement, container, offset) {
451 if (container.nodeType !== Node.TEXT_NODE) { 454 if (container.nodeType !== Node.TEXT_NODE) {
452 if (offset < container.childNodes.length) { 455 if (offset < container.childNodes.length) {
453 container = /** @type {!Node} */ (container.childNodes.item(offset)); 456 container = /** @type {!Node} */ (container.childNodes.item(offset));
454 offset = 0; 457 offset = 0;
455 } else { 458 } else {
456 offset = container.textContent.length; 459 offset = container.textContent.length;
457 } 460 }
458 } 461 }
462 // To calculate the correct offset, this assumes that links truncate from th e middle.
463 var originalLinkText = Components.DOMPresentationUtils.originalNodeText(cont ainer);
464 if (originalLinkText !== null) {
465 var truncatedLength = originalLinkText.length - container.textContent.leng th;
466 if (offset > container.textContent.length >> 1)
467 offset += truncatedLength;
468 }
459 var chars = 0; 469 var chars = 0;
460 var node = itemElement; 470 var node = itemElement;
461 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container)) 471 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container))
462 chars += node.textContent.length; 472 chars += Components.DOMPresentationUtils.originalNodeText(node).length;
463 return chars + offset; 473 return chars + offset;
464 } 474 }
465 475
466 /** 476 /**
467 * @param {!Event} event 477 * @param {!Event} event
468 */ 478 */
469 _onScroll(event) { 479 _onScroll(event) {
470 this.refresh(); 480 this.refresh();
471 } 481 }
472 482
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 Console.ConsoleViewportElement.prototype = { 608 Console.ConsoleViewportElement.prototype = {
599 willHide() {}, 609 willHide() {},
600 610
601 wasShown() {}, 611 wasShown() {},
602 612
603 /** 613 /**
604 * @return {!Element} 614 * @return {!Element}
605 */ 615 */
606 element() {}, 616 element() {},
607 }; 617 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698