Fix shifted/cutoff selection when melding with negative coordinates

Code intended to prevent errors was also creating an offset between
the source and target regions. The source region needs to be adjusted
to match the clipped target region.
This commit is contained in:
Isaiah Odhner 2023-04-26 13:49:33 -04:00
parent 0c52788843
commit 1f171259bb
2 changed files with 6 additions and 2 deletions

View File

@ -138,7 +138,6 @@ cat file.ans
- Large files can make the program very slow, as can magnifying the canvas.
- The program sometimes crashes or freezes randomly, and there's no auto-save feature.
- Saved ANSI files are unnecessarily large, because they include escape sequences for every cell, even if the colors match the previous cell.
- When finalizing a selection that is partially outside the document bounds to the top or to the left, it gets cut off.
The program has only been tested on Linux. Issues on other platforms are as-yet _unknown_ :)

View File

@ -467,8 +467,13 @@ class Selection:
if not self.contained_image:
# raise ValueError("Selection has no image data.")
return
# Prevent out of bounds errors (IndexError: list assignment index out of range)
# by clipping the target region to the document, and adjusting the source region accordingly.
target_region = self.region.intersection(Region(0, 0, document.width, document.height))
document.copy_region(source=self.contained_image, target_region=target_region, mask=self.mask)
source_region = Region(target_region.x - self.region.x, target_region.y - self.region.y, self.contained_image.width, self.contained_image.height)
document.copy_region(source=self.contained_image, source_region=source_region, target_region=target_region, mask=self.mask)
debug_region_updates = False