Cancel active tool by pressing both mouse buttons

This commit is contained in:
Isaiah Odhner 2023-04-26 01:30:36 -04:00
parent bf8c7fa1a6
commit 6d6ef25da4
2 changed files with 9 additions and 1 deletions

View File

@ -128,7 +128,8 @@ cat file.ans
- Pressing Delete while using the Text tool deletes the whole text box. Similarly, Ctrl+A selects the canvas instead of the text in the text box.
- Selection box border is inside instead of outside (and lacks dashes). For the text box, I hid the border because it was too visually confusing, but it should also have an outer border.
- Pick Color can't be cancelled, since it samples the color continuously. No tools can be cancelled by pressing both mouse buttons, only with Escape.
- Pick Color can't be cancelled, since it samples the color continuously.
- Pressing both mouse buttons to cancel tools can sometimes result the the tool restarting, or it's just my mouse. It's probably my mouse, now that I think about it. But also, it should actually undo current action, not just end it.
- Help > Help Topics isn't very helpful.
- Due to limitations of the terminal, shortcuts using Shift or Alt might not work.
- Menus are not keyboard navigable.

View File

@ -944,14 +944,21 @@ class Canvas(Widget):
self.pointer_active: bool = False
self.magnifier_preview_region: Optional[Region] = None
self.select_preview_region: Optional[Region] = None
self.which_button: Optional[int] = None
def on_mouse_down(self, event: events.MouseDown) -> None:
self.fix_mouse_event(event) # not needed, pointer isn't captured yet.
event.x //= self.magnification
event.y //= self.magnification
if self.pointer_active and self.which_button != event.button:
assert isinstance(self.app, PaintApp)
self.app.stop_action_in_progress()
return
self.post_message(self.ToolStart(event))
self.pointer_active = True
self.which_button = event.button
self.capture_mouse(True)
def fix_mouse_event(self, event: events.MouseEvent) -> None: