Skip to content

Commit

Permalink
Merge pull request #123 from devchat-ai/fix-text-editor
Browse files Browse the repository at this point in the history
Fix handling block flag for new_text in text editor
  • Loading branch information
yangbobo2021 authored May 28, 2024
2 parents eecad6f + b1a2fa3 commit 95bd6d0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/chatmark/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 95bd6d0

Please sign in to comment.