Chromium Code Reviews| 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 } |
| 460 // This method traverses TextNodes until reaching the selectionNode. This fa ils if selectionNode is before the first | |
| 461 // TextNode. We can move the selectionNode to the next TextNode to avoid thi s case, which may happen if a text | |
| 462 // selection ends on an expand triangle icon. | |
| 463 if (!selectionNode.textContent.length) | |
| 464 selectionNode = selectionNode.traverseNextTextNode(itemElement) || selecti onNode; | |
| 459 | 465 |
| 460 var chars = 0; | 466 var chars = 0; |
| 461 var node = itemElement; | 467 var node = itemElement; |
| 462 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container)) | 468 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(selectionNode)) |
|
lushnikov
2017/05/05 23:31:57
let's use node.traverseNextNode(itemElement) to fi
luoe
2017/05/05 23:48:51
Done.
| |
| 463 chars += Components.Linkifier.untruncatedNodeText(node).length; | 469 chars += Components.Linkifier.untruncatedNodeText(node).length; |
| 464 // If the selection offset is at the end of a link's ellipsis, use the untru ncated length as offset. | 470 // 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; | 471 var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(se lectionNode).length; |
| 466 if (offset === 1 && untruncatedContainerLength > offset) | 472 if (offset === 1 && untruncatedContainerLength > offset) |
| 467 offset = untruncatedContainerLength; | 473 offset = untruncatedContainerLength; |
| 468 return chars + offset; | 474 return chars + offset; |
| 469 } | 475 } |
| 470 | 476 |
| 471 /** | 477 /** |
| 472 * @param {!Event} event | 478 * @param {!Event} event |
| 473 */ | 479 */ |
| 474 _onScroll(event) { | 480 _onScroll(event) { |
| 475 this.refresh(); | 481 this.refresh(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 Console.ConsoleViewportElement.prototype = { | 607 Console.ConsoleViewportElement.prototype = { |
| 602 willHide() {}, | 608 willHide() {}, |
| 603 | 609 |
| 604 wasShown() {}, | 610 wasShown() {}, |
| 605 | 611 |
| 606 /** | 612 /** |
| 607 * @return {!Element} | 613 * @return {!Element} |
| 608 */ | 614 */ |
| 609 element() {}, | 615 element() {}, |
| 610 }; | 616 }; |
| OLD | NEW |