Skip to content

Commit

Permalink
Refactor TextEditor to handle block flags in text
Browse files Browse the repository at this point in the history
  • Loading branch information
yangbobo2021 committed May 27, 2024
1 parent 379f356 commit 79e6e80
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/chatmark/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,22 @@ def __init__(
super().__init__(submit_button_name, cancel_button_name)

self._title = title
self._text = text
self._text = self._handle_block_flag(text)

self._editor_key = self.gen_id(self._id_prefix, 0)
self._new_text: Optional[str] = None

def _handle_block_flag(self, text):
"""convert \\ to \\, and ` to \\`"""
return text.replace("\\", "\\\\").replace("`", "\\`")

def _remove_block_flag(self, text):
"""convert \\ to \\, and \\` to `"""
return text.replace("\\`", "`").replace("\\\\", "\\")

@property
def new_text(self):
return self._new_text
return self._remove_block_flag(self._new_text)

def _in_chatmark(self) -> str:
"""
Expand Down

0 comments on commit 79e6e80

Please sign in to comment.