| OLD | NEW |
| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec
tionElement)) { | 436 if (startSelection.node && startSelection.node.isSelfOrDescendant(startSelec
tionElement)) { |
| 437 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe
lection.node, startSelection.offset); | 437 var itemTextOffset = this._textOffsetInNode(startSelectionElement, startSe
lection.node, startSelection.offset); |
| 438 textLines[0] = textLines[0].substring(itemTextOffset); | 438 textLines[0] = textLines[0].substring(itemTextOffset); |
| 439 } | 439 } |
| 440 | 440 |
| 441 return textLines.join('\n'); | 441 return textLines.join('\n'); |
| 442 } | 442 } |
| 443 | 443 |
| 444 /** | 444 /** |
| 445 * @param {!Element} itemElement | 445 * @param {!Element} itemElement |
| 446 * @param {!Node} container | 446 * @param {!Node} selectionNode |
| 447 * @param {number} offset | 447 * @param {number} offset |
| 448 * @return {number} | 448 * @return {number} |
| 449 */ | 449 */ |
| 450 _textOffsetInNode(itemElement, container, offset) { | 450 _textOffsetInNode(itemElement, selectionNode, offset) { |
| 451 if (container.nodeType !== Node.TEXT_NODE) { | 451 // If the selectionNode is not a TextNode, we may need to convert a child of
fset into a character offset. |
| 452 if (offset < container.childNodes.length) { | 452 if (selectionNode.nodeType !== Node.TEXT_NODE) { |
| 453 container = /** @type {!Node} */ (container.childNodes.item(offset)); | 453 if (offset < selectionNode.childNodes.length) { |
| 454 selectionNode = /** @type {!Node} */ (selectionNode.childNodes.item(offs
et)); |
| 454 offset = 0; | 455 offset = 0; |
| 455 } else { | 456 } else { |
| 456 offset = container.textContent.length; | 457 offset = selectionNode.textContent.length; |
| 457 } | 458 } |
| 458 } | 459 } |
| 459 | 460 |
| 460 var chars = 0; | 461 var chars = 0; |
| 461 var node = itemElement; | 462 var node = itemElement; |
| 462 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc
endant(container)) | 463 while ((node = node.traverseNextNode(itemElement)) && node !== selectionNode
) { |
| 464 if (node.nodeType !== Node.TEXT_NODE || node.parentElement.nodeName === 'S
TYLE' || |
| 465 node.parentElement.nodeName === 'SCRIPT') |
| 466 continue; |
| 463 chars += Components.Linkifier.untruncatedNodeText(node).length; | 467 chars += Components.Linkifier.untruncatedNodeText(node).length; |
| 468 } |
| 464 // If the selection offset is at the end of a link's ellipsis, use the untru
ncated length as offset. | 469 // If the selection offset is at the end of a link's ellipsis, use the untru
ncated length as offset. |
| 465 var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(co
ntainer).length; | 470 var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(se
lectionNode).length; |
| 466 if (offset === 1 && untruncatedContainerLength > offset) | 471 if (offset === 1 && untruncatedContainerLength > offset) |
| 467 offset = untruncatedContainerLength; | 472 offset = untruncatedContainerLength; |
| 468 return chars + offset; | 473 return chars + offset; |
| 469 } | 474 } |
| 470 | 475 |
| 471 /** | 476 /** |
| 472 * @param {!Event} event | 477 * @param {!Event} event |
| 473 */ | 478 */ |
| 474 _onScroll(event) { | 479 _onScroll(event) { |
| 475 this.refresh(); | 480 this.refresh(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 Console.ConsoleViewportElement.prototype = { | 606 Console.ConsoleViewportElement.prototype = { |
| 602 willHide() {}, | 607 willHide() {}, |
| 603 | 608 |
| 604 wasShown() {}, | 609 wasShown() {}, |
| 605 | 610 |
| 606 /** | 611 /** |
| 607 * @return {!Element} | 612 * @return {!Element} |
| 608 */ | 613 */ |
| 609 element() {}, | 614 element() {}, |
| 610 }; | 615 }; |
| OLD | NEW |