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

Commit

Permalink
Fix edit a reply in rich text editor
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Nov 23, 2022
1 parent 569a364 commit b3617ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function parseEditorStateTransfer(
// const restoredParts = this.restoreStoredEditorState(partCreator);

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

parts = parseEvent(editorStateTransfer.getEvent(), partCreator, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ describe('EditWysiwygComposer', () => {
await waitFor(() =>
expect(screen.getByRole('textbox')).toContainHTML(mockEvent.getContent()['body']));
});

it('Should strip <mx-reply> tag from initial content', async () => {
// When
const mockEvent = mkEvent({
type: "m.room.message",
room: 'myfakeroom',
user: 'myfakeuser',
content: {
"msgtype": "m.text",
"body": "Replying to this",
"format": "org.matrix.custom.html",
"formatted_body": '<mx-reply>Reply</mx-reply>My content',
},
event: true,
});

const editorStateTransfer = new EditorStateTransfer(mockEvent);
customRender(false, editorStateTransfer);
await waitFor(() => expect(screen.getByRole('textbox')).toHaveAttribute('contentEditable', "true"));

// Then
await waitFor(() => {
expect(screen.getByRole('textbox')).not.toContainHTML("<mx-reply>Reply</mx-reply>");
expect(screen.getByRole('textbox')).toContainHTML("My content");
});
});
});

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

0 comments on commit b3617ca

Please sign in to comment.