From ed5e399a58a50c070b51ae20eb934f39516ffa45 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Wed, 26 Apr 2023 11:19:16 -0400 Subject: [PATCH] Don't delete the whole textbox when pressing Delete --- README.md | 2 +- paint.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bca1420..812ea3f 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ cat file.ans ## Known Issues -- 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. +- Pressing Ctrl+A in textbox 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. - 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. diff --git a/paint.py b/paint.py index d8a213d..027e446 100755 --- a/paint.py +++ b/paint.py @@ -1169,8 +1169,7 @@ class PaintApp(App[None]): Binding("ctrl+w", "stretch_skew", _("Stretch/Skew")), Binding("ctrl+i", "invert_colors", _("Invert Colors")), Binding("ctrl+e", "attributes", _("Attributes")), - # TODO: don't delete textbox with delete key - Binding("delete", "clear_selection", _("Clear Selection")), + Binding("delete", "clear_selection(True)", _("Clear Selection")), Binding("ctrl+a", "select_all", _("Select All")), Binding("ctrl+pageup", "normal_size", _("Normal Size")), Binding("ctrl+pagedown", "large_size", _("Large Size")), @@ -2386,9 +2385,16 @@ class PaintApp(App[None]): """Draw the selection onto the image and dissolve the selection.""" self.meld_or_clear_selection(meld=True) - def action_clear_selection(self) -> None: - """Delete the selection and its contents.""" - self.meld_or_clear_selection(meld=False) + def action_clear_selection(self, from_key_binding: bool = False) -> None: + """Delete the selection and its contents, or if using the Text tool, delete text.""" + sel = self.image.selection + if sel is None: + return + if sel.textbox_mode: + if not from_key_binding: + self.on_key(events.Key("delete", None)) + else: + self.meld_or_clear_selection(meld=False) def on_canvas_tool_update(self, event: Canvas.ToolUpdate) -> None: """Called when the user is drawing on the canvas.