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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 element = this._providerElement(i).element(); |
428 var lineContent = element.childTextNodes().map(Components.Linkifier.untrun catedNodeText).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); |
438 textLines[0] = textLines[0].substring(itemTextOffset); | 441 textLines[0] = textLines[0].substring(itemTextOffset); |
439 } | 442 } |
440 | 443 |
441 return textLines.join('\n'); | 444 return textLines.join('\n'); |
442 } | 445 } |
443 | 446 |
444 /** | 447 /** |
445 * @param {!Element} itemElement | 448 * @param {!Element} itemElement |
446 * @param {!Node} container | 449 * @param {!Node} container |
447 * @param {number} offset | 450 * @param {number} offset |
448 * @return {number} | 451 * @return {number} |
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) { |
455 // If the container is not a TextNode, we may need to convert a child offs et into a character offset. | |
452 if (offset < container.childNodes.length) { | 456 if (offset < container.childNodes.length) { |
453 container = /** @type {!Node} */ (container.childNodes.item(offset)); | 457 container = /** @type {!Node} */ (container.childNodes.item(offset)); |
454 offset = 0; | 458 offset = 0; |
455 } else { | 459 } else { |
456 offset = container.textContent.length; | 460 offset = container.textContent.length; |
457 } | 461 } |
462 // Ensure that the container does not come before the first text node. | |
463 if (container.textContent.length === 0 && container.nodeType !== Node.TEXT _NODE) { | |
lushnikov
2017/05/01 22:52:26
this is unrelated to the patch - let's have this s
luoe
2017/05/01 23:03:49
Sounds good, I've made a separate bug with the rep
| |
464 var nextTextNode = container.traverseNextTextNode(itemElement); | |
465 if (nextTextNode) | |
466 container = nextTextNode; | |
467 } | |
458 } | 468 } |
469 | |
459 var chars = 0; | 470 var chars = 0; |
460 var node = itemElement; | 471 var node = itemElement; |
461 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container)) | 472 while ((node = node.traverseNextTextNode(itemElement)) && !node.isSelfOrDesc endant(container)) |
462 chars += node.textContent.length; | 473 chars += Components.Linkifier.untruncatedNodeText(node).length; |
474 // If the selection offset is at the end of a link's ellipsis, use the untru ncated length as offset. | |
475 var untruncatedContainerLength = Components.Linkifier.untruncatedNodeText(co ntainer).length; | |
476 if (offset === 1 && untruncatedContainerLength > offset) | |
477 offset = untruncatedContainerLength; | |
463 return chars + offset; | 478 return chars + offset; |
464 } | 479 } |
465 | 480 |
466 /** | 481 /** |
467 * @param {!Event} event | 482 * @param {!Event} event |
468 */ | 483 */ |
469 _onScroll(event) { | 484 _onScroll(event) { |
470 this.refresh(); | 485 this.refresh(); |
471 } | 486 } |
472 | 487 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 Console.ConsoleViewportElement.prototype = { | 613 Console.ConsoleViewportElement.prototype = { |
599 willHide() {}, | 614 willHide() {}, |
600 | 615 |
601 wasShown() {}, | 616 wasShown() {}, |
602 | 617 |
603 /** | 618 /** |
604 * @return {!Element} | 619 * @return {!Element} |
605 */ | 620 */ |
606 element() {}, | 621 element() {}, |
607 }; | 622 }; |
OLD | NEW |