mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 06:11:37 +03:00
Don't delete selection if copy fails during cut
This commit is contained in:
parent
0c3cc45ddd
commit
8c936552b7
10
paint.py
10
paint.py
@ -1868,14 +1868,14 @@ class PaintApp(App[None]):
|
|||||||
|
|
||||||
def action_cut(self) -> None:
|
def action_cut(self) -> None:
|
||||||
"""Cut the selection to the clipboard."""
|
"""Cut the selection to the clipboard."""
|
||||||
self.action_copy()
|
if self.action_copy():
|
||||||
self.action_clear_selection()
|
self.action_clear_selection()
|
||||||
|
|
||||||
def action_copy(self) -> None:
|
def action_copy(self) -> bool:
|
||||||
"""Copy the selection to the clipboard."""
|
"""Copy the selection to the clipboard."""
|
||||||
sel = self.image.selection
|
sel = self.image.selection
|
||||||
if sel is None:
|
if sel is None:
|
||||||
return
|
return False
|
||||||
had_contained_image = sel.contained_image is not None
|
had_contained_image = sel.contained_image is not None
|
||||||
try:
|
try:
|
||||||
if sel.contained_image is None:
|
if sel.contained_image is None:
|
||||||
@ -1886,14 +1886,16 @@ class PaintApp(App[None]):
|
|||||||
import pyperclip
|
import pyperclip
|
||||||
if not pyperclip.is_available():
|
if not pyperclip.is_available():
|
||||||
self.warning_message_box(_("Paint"), _("Clipboard is not available."), "ok")
|
self.warning_message_box(_("Paint"), _("Clipboard is not available."), "ok")
|
||||||
return
|
return False
|
||||||
pyperclip.copy(sel.contained_image.get_ansi())
|
pyperclip.copy(sel.contained_image.get_ansi())
|
||||||
# self.use_clipboard(sel.contained_image.get_ansi())
|
# self.use_clipboard(sel.contained_image.get_ansi())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.warning_message_box(_("Paint"), _("Failed to copy to the clipboard.") + "\n\n" + repr(e), "ok")
|
self.warning_message_box(_("Paint"), _("Failed to copy to the clipboard.") + "\n\n" + repr(e), "ok")
|
||||||
|
return False
|
||||||
finally:
|
finally:
|
||||||
if not had_contained_image:
|
if not had_contained_image:
|
||||||
sel.contained_image = None
|
sel.contained_image = None
|
||||||
|
return True
|
||||||
|
|
||||||
def action_paste(self) -> None:
|
def action_paste(self) -> None:
|
||||||
"""Paste the clipboard as a selection."""
|
"""Paste the clipboard as a selection."""
|
||||||
|
Loading…
Reference in New Issue
Block a user