Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b3617ca

Browse files
committed
Fix edit a reply in rich text editor
1 parent 569a364 commit b3617ca

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ function parseEditorStateTransfer(
4242
// const restoredParts = this.restoreStoredEditorState(partCreator);
4343

4444
if (editorStateTransfer.getEvent().getContent().format === 'org.matrix.custom.html') {
45-
return editorStateTransfer.getEvent().getContent().formatted_body || "";
45+
return editorStateTransfer.getEvent().getContent().formatted_body.replace(/<mx-reply>.*<\/mx-reply>/, '')
46+
|| "";
4647
}
4748

4849
parts = parseEvent(editorStateTransfer.getEvent(), partCreator, {

test/components/views/rooms/wysiwyg_composer/EditWysiwygComposer-test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@ describe('EditWysiwygComposer', () => {
9696
await waitFor(() =>
9797
expect(screen.getByRole('textbox')).toContainHTML(mockEvent.getContent()['body']));
9898
});
99+
100+
it('Should strip <mx-reply> tag from initial content', async () => {
101+
// When
102+
const mockEvent = mkEvent({
103+
type: "m.room.message",
104+
room: 'myfakeroom',
105+
user: 'myfakeuser',
106+
content: {
107+
"msgtype": "m.text",
108+
"body": "Replying to this",
109+
"format": "org.matrix.custom.html",
110+
"formatted_body": '<mx-reply>Reply</mx-reply>My content',
111+
},
112+
event: true,
113+
});
114+
115+
const editorStateTransfer = new EditorStateTransfer(mockEvent);
116+
customRender(false, editorStateTransfer);
117+
await waitFor(() => expect(screen.getByRole('textbox')).toHaveAttribute('contentEditable', "true"));
118+
119+
// Then
120+
await waitFor(() => {
121+
expect(screen.getByRole('textbox')).not.toContainHTML("<mx-reply>Reply</mx-reply>");
122+
expect(screen.getByRole('textbox')).toContainHTML("My content");
123+
});
124+
});
99125
});
100126

101127
describe('Edit and save actions', () => {

0 commit comments

Comments
 (0)