Only escape when editing (#852)
authorginnyTheCat <ginnythecat@lelux.net>
Sat, 17 Sep 2022 11:25:26 +0000 (13:25 +0200)
committerGitHub <noreply@github.com>
Sat, 17 Sep 2022 11:25:26 +0000 (16:55 +0530)
* Only escape when editing

* Base edit change detection on rendered content

src/app/molecules/message/Message.jsx
src/util/markdown.js

index 6becae1cbd8470c4c67c605b9882d8729d0f313f..26a5b29dae90cc9346fa1074dad2149709bca499 100644 (file)
@@ -300,12 +300,12 @@ function MessageEdit({ body, onSave, onCancel }) {
 
     if (e.key === 'Enter' && e.shiftKey === false) {
       e.preventDefault();
-      onSave(editInputRef.current.value);
+      onSave(editInputRef.current.value, body);
     }
   };
 
   return (
-    <form className="message__edit" onSubmit={(e) => { e.preventDefault(); onSave(editInputRef.current.value); }}>
+    <form className="message__edit" onSubmit={(e) => { e.preventDefault(); onSave(editInputRef.current.value, body); }}>
       <Input
         forwardRef={editInputRef}
         onKeyDown={handleKeyDown}
@@ -806,8 +806,8 @@ function Message({
             body={(customHTML
               ? html(customHTML, { kind: 'edit', onlyPlain: true }).plain
               : plain(body, { kind: 'edit', onlyPlain: true }).plain)}
-            onSave={(newBody) => {
-              if (newBody !== body) {
+            onSave={(newBody, oldBody) => {
+              if (newBody !== oldBody) {
                 initMatrix.roomsInput.sendEditedMessage(roomId, mEvent, newBody);
               }
               cancelEdit();
index bc83cb33a445800a97d4a6af310efb001b9e043a..d0f5d6b225baa02e35aeb131e7c864b3df6a6e2c 100644 (file)
@@ -96,7 +96,9 @@ const plainRules = {
   text: {
     ...defaultRules.text,
     match: anyScopeRegex(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]| *\n|\w+:\S|$)/),
-    plain: (node) => node.content.replace(/(\*|_|!\[|\[|\|\||\$\$?)/g, '\\$1'),
+    plain: (node, _, state) => (state.kind === 'edit'
+      ? node.content.replace(/(\*|_|!\[|\[|\|\||\$\$?)/g, '\\$1')
+      : node.content),
   },
 };