Split action_paste and paste

This commit is contained in:
Isaiah Odhner 2023-05-03 20:48:12 -04:00
parent c2ee9ef2df
commit 3e29d2a75e

View File

@ -2170,7 +2170,7 @@ class PaintApp(App[None]):
return True return True
def action_paste(self) -> None: def action_paste(self) -> None:
"""Paste the clipboard as a selection.""" """Paste the clipboard (ANSI art allowed), either as a selection, or into a textbox."""
try: try:
import pyperclip import pyperclip
text: str = pyperclip.paste() text: str = pyperclip.paste()
@ -2179,6 +2179,10 @@ class PaintApp(App[None]):
return return
if not text: if not text:
return return
self.paste(text)
def paste(self, text: str) -> None:
"""Paste the given text (ANSI art allowed), either as a selection, or into a textbox."""
if self.image.selection and self.image.selection.textbox_mode: if self.image.selection and self.image.selection.textbox_mode:
# paste into textbox # paste into textbox
pasted_image = AnsiArtDocument.from_text(text, default_bg=self.selected_bg_color, default_fg=self.selected_fg_color) pasted_image = AnsiArtDocument.from_text(text, default_bg=self.selected_bg_color, default_fg=self.selected_fg_color)