mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-21 22:01:31 +03:00
Constrain selection so it doesn't go completely outside the document bounds
This commit is contained in:
parent
cb0db3b6e6
commit
dbce1434cd
5
paint.py
5
paint.py
@ -2063,6 +2063,11 @@ class PaintApp(App[None]):
|
||||
self.selection_drag_offset.x + event.mouse_move_event.x,
|
||||
self.selection_drag_offset.y + event.mouse_move_event.y,
|
||||
)
|
||||
# constrain to have at least one cell in the bounds of the document
|
||||
offset = (
|
||||
max(1-sel.region.width, min(self.image.width - 1, offset[0])),
|
||||
max(1-sel.region.height, min(self.image.height - 1, offset[1])),
|
||||
)
|
||||
old_region = sel.region
|
||||
sel.region = Region.from_offset(offset, sel.region.size)
|
||||
combined_region = old_region.union(sel.region)
|
||||
|
Loading…
Reference in New Issue
Block a user