From cbd1bf35c66a034e59389a1addbc0fce900af959 Mon Sep 17 00:00:00 2001 From: ginnyTheCat Date: Sat, 17 Sep 2022 13:25:26 +0200 Subject: [PATCH] Only escape when editing (#852) * Only escape when editing * Base edit change detection on rendered content --- src/app/molecules/message/Message.jsx | 8 ++++---- src/util/markdown.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/molecules/message/Message.jsx b/src/app/molecules/message/Message.jsx index 6becae1..26a5b29 100644 --- a/src/app/molecules/message/Message.jsx +++ b/src/app/molecules/message/Message.jsx @@ -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 ( -
{ e.preventDefault(); onSave(editInputRef.current.value); }}> + { e.preventDefault(); onSave(editInputRef.current.value, body); }}> { - if (newBody !== body) { + onSave={(newBody, oldBody) => { + if (newBody !== oldBody) { initMatrix.roomsInput.sendEditedMessage(roomId, mEvent, newBody); } cancelEdit(); diff --git a/src/util/markdown.js b/src/util/markdown.js index bc83cb3..d0f5d6b 100644 --- a/src/util/markdown.js +++ b/src/util/markdown.js @@ -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), }, };