Skip to content

Commit

Permalink
Merge pull request #122 from devchat-ai/fix_invliad_text_edit_error
Browse files Browse the repository at this point in the history
Refactor TextEditor to handle block flags in text
  • Loading branch information
kagami-l authored May 27, 2024
2 parents 379f356 + 79e6e80 commit eecad6f
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 eecad6f

Please sign in to comment.