Bug 1654406 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

[Bug 1620289](https://bugzilla.mozilla.org/show_bug.cgi?id=1620289) modified the behavior of printing selection ranges to remove its dependency on the original document's current selections.

To solve this, the selected ranges are cached on the static clone of the document when printing is invoked.

To print only the selections, the complement set of ranges (the non-selected data) is deleted from the cloned document and ellipses are added where appropriate (when content is cut off within the same node).
The old way of achieving this involved traversing both the original document and the static clone at the same time, deleting the relevant data in the clone while keeping track of the same position in the original. This led to code that would need to offset the position in the original document based on the addition of an ellipsis in the cloned document.

Now that the original document is no longer involved in the process, we no longer need to separately keep track of the difference in position with the added ellipses (it's all with regard to the same node that belongs to the clone). Failing to remove this code was causing an off-by-one issue with printing selections, reported in [Bug 1652746](https://bugzilla.mozilla.org/show_bug.cgi?id=1652746).

This patch aims to fix the regression by no longer double-counting the added offset from the ellipses.

The attached image shows (from left to right):
- The highlighted text in the [test case](https://bug1652746.bmoattachments.org/attachment.cgi?id=9163484)
- The incorrect output caused by the regression.
- The output before the regression.
- The output after applying this patch.
[Bug 1620289](https://bugzilla.mozilla.org/show_bug.cgi?id=1620289) modified the behavior of printing selection ranges to remove its dependency on the original document's current selections.

To solve this, the selected ranges are cached on the static clone of the document when printing is invoked.

To print only the selections, the complement set of ranges (the non-selected data) is deleted from the cloned document and ellipses are added where appropriate (when content is cut off within text in the same node).

The old way of achieving this involved traversing both the original document and the static clone at the same time, deleting the relevant data in the clone while keeping track of the same position in the original. This led to code that would need to offset the position in the original document based on the addition of an ellipsis in the cloned document.

Now that the original document is no longer involved in this process, we no longer need to separately keep track of the difference in position with the added ellipses. It is now implicitly taken care of in the modification to the node itself. 

Failing to remove the code that explicitly accounted for the added ellipses was causing an off-by-one issue with some printing selections, reported in [Bug 1652746](https://bugzilla.mozilla.org/show_bug.cgi?id=1652746). This issue occurs especially when there are multiple selections within the same text (see attached image).

The attached image shows (from left to right):
- The highlighted text in the [test case](https://bug1652746.bmoattachments.org/attachment.cgi?id=9163484)
- The incorrect output caused by the regression.
- The output before the regression.
- The output after applying this patch.

Back to Bug 1654406 Comment 0