From b1a2fa39b659de0ccaff961f1ecf10ec05e27794 Mon Sep 17 00:00:00 2001 From: kagami Date: Tue, 28 May 2024 14:32:26 +0800 Subject: [PATCH] Fix handling block flag for new_text in text editor --- lib/chatmark/widgets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/chatmark/widgets.py b/lib/chatmark/widgets.py index 459285e..4dedba3 100644 --- a/lib/chatmark/widgets.py +++ b/lib/chatmark/widgets.py @@ -207,16 +207,18 @@ def __init__( self._editor_key = self.gen_id(self._id_prefix, 0) self._new_text: Optional[str] = None - def _handle_block_flag(self, text): + def _handle_block_flag(self, text: str): """convert \\ to \\, and ` to \\`""" return text.replace("\\", "\\\\").replace("`", "\\`") - def _remove_block_flag(self, text): + def _remove_block_flag(self, text: str): """convert \\ to \\, and \\` to `""" return text.replace("\\`", "`").replace("\\\\", "\\") @property - def new_text(self): + def new_text(self) -> Optional[str]: + if self._new_text is None: + return None return self._remove_block_flag(self._new_text) def _in_chatmark(self) -> str: