From 49ee6f9734e71e0236a4cf000c0dc5233391bb7d Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Mon, 23 Oct 2023 07:28:51 +0530 Subject: [PATCH 1/3] fix missing empty line on edit --- src/app/components/editor/input.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/components/editor/input.ts b/src/app/components/editor/input.ts index 91386a877..5860df04f 100644 --- a/src/app/components/editor/input.ts +++ b/src/app/components/editor/input.ts @@ -138,6 +138,7 @@ const parseBlockquoteNode = (node: Element): BlockQuoteElement => { } if (isTag(child)) { if (child.name === 'br') { + lineHolder.push({ text: '' }); appendLine(); return; } @@ -202,6 +203,7 @@ const parseListNode = (node: Element): OrderedListElement | UnorderedListElement } if (isTag(child)) { if (child.name === 'br') { + lineHolder.push({ text: '' }); appendLine(); return; } @@ -260,6 +262,7 @@ export const domToEditorInput = (domNodes: ChildNode[]): Descendant[] => { } if (isTag(node)) { if (node.name === 'br') { + lineHolder.push({ text: '' }); appendLine(); return; } From d02349508df66146ee7e536c7fdde2897f256dbb Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Mon, 23 Oct 2023 07:53:52 +0530 Subject: [PATCH 2/3] fix edit save after adding formatting to plaintext --- .../organisms/room/message/MessageEditor.tsx | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/app/organisms/room/message/MessageEditor.tsx b/src/app/organisms/room/message/MessageEditor.tsx index 385042ec1..ef5100882 100644 --- a/src/app/organisms/room/message/MessageEditor.tsx +++ b/src/app/organisms/room/message/MessageEditor.tsx @@ -53,7 +53,10 @@ export const MessageEditor = as<'div', MessageEditorProps>( const [autocompleteQuery, setAutocompleteQuery] = useState>(); - const getPrevBodyAndFormattedBody = useCallback(() => { + const getPrevBodyAndFormattedBody = useCallback((): [ + string | undefined, + string | undefined + ] => { const evtId = mEvent.getId()!; const evtTimeline = room.getTimelineForEvent(evtId); const editedEvent = @@ -62,7 +65,10 @@ export const MessageEditor = as<'div', MessageEditorProps>( const { body, formatted_body: customHtml }: Record = editedEvent?.getContent()['m.new.content'] ?? mEvent.getContent(); - return [body, customHtml]; + return [ + typeof body === 'string' ? body : undefined, + typeof customHtml === 'string' ? customHtml : undefined, + ]; }, [room, mEvent]); const [saveState, save] = useAsyncCallback( @@ -78,14 +84,17 @@ export const MessageEditor = as<'div', MessageEditorProps>( const [prevBody, prevCustomHtml] = getPrevBodyAndFormattedBody(); if (plainText === '') return undefined; - if ( - typeof prevCustomHtml === 'string' && - trimReplyFromFormattedBody(prevCustomHtml) === customHtml - ) { - return undefined; - } - if (!prevCustomHtml && typeof prevBody === 'string' && prevBody === plainText) { - return undefined; + if (prevBody) { + if (prevCustomHtml && trimReplyFromFormattedBody(prevCustomHtml) === customHtml) { + return undefined; + } + if ( + !prevCustomHtml && + prevBody === plainText && + customHtmlEqualsPlainText(customHtml, plainText) + ) { + return undefined; + } } const newContent: IContent = { From 3cedf78900de405a78657b4da4a823381caea232 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Mon, 23 Oct 2023 08:42:46 +0530 Subject: [PATCH 3/3] fix reading edit content with wrong key --- src/app/organisms/room/RoomTimeline.tsx | 10 ++++++---- src/app/organisms/room/message/MessageEditor.tsx | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/organisms/room/RoomTimeline.tsx b/src/app/organisms/room/RoomTimeline.tsx index 0852ecf7a..2cfbd6584 100644 --- a/src/app/organisms/room/RoomTimeline.tsx +++ b/src/app/organisms/room/RoomTimeline.tsx @@ -615,6 +615,8 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli if (document.hasFocus()) { scrollToBottomRef.current.count += 1; scrollToBottomRef.current.smooth = true; + } else if (!unreadInfo) { + setUnreadInfo(getRoomUnreadInfo(room)); } setTimeline((ct) => ({ ...ct, @@ -919,7 +921,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli if (!replyEvt) return; const editedReply = getEditedEvent(replyId, replyEvt, room.getUnfilteredTimelineSet()); const { body, formatted_body: formattedBody }: Record = - editedReply?.getContent()['m.new.content'] ?? replyEvt.getContent(); + editedReply?.getContent()['m.new_content'] ?? replyEvt.getContent(); const senderId = replyEvt.getSender(); if (senderId && typeof body === 'string') { setReplyDraft({ @@ -982,7 +984,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli renderText: (mEventId, mEvent, timelineSet) => { const editedEvent = getEditedEvent(mEventId, mEvent, timelineSet); const { body, formatted_body: customBody }: Record = - editedEvent?.getContent()['m.new.content'] ?? mEvent.getContent(); + editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent(); if (typeof body !== 'string') return null; return ( @@ -1002,7 +1004,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli renderEmote: (mEventId, mEvent, timelineSet) => { const editedEvent = getEditedEvent(mEventId, mEvent, timelineSet); const { body, formatted_body: customBody } = - editedEvent?.getContent()['m.new.content'] ?? mEvent.getContent(); + editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent(); const senderId = mEvent.getSender() ?? ''; const senderDisplayName = @@ -1027,7 +1029,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli renderNotice: (mEventId, mEvent, timelineSet) => { const editedEvent = getEditedEvent(mEventId, mEvent, timelineSet); const { body, formatted_body: customBody }: Record = - editedEvent?.getContent()['m.new.content'] ?? mEvent.getContent(); + editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent(); if (typeof body !== 'string') return null; return ( diff --git a/src/app/organisms/room/message/MessageEditor.tsx b/src/app/organisms/room/message/MessageEditor.tsx index ef5100882..776e1d4d8 100644 --- a/src/app/organisms/room/message/MessageEditor.tsx +++ b/src/app/organisms/room/message/MessageEditor.tsx @@ -63,7 +63,7 @@ export const MessageEditor = as<'div', MessageEditorProps>( evtTimeline && getEditedEvent(evtId, mEvent, evtTimeline.getTimelineSet()); const { body, formatted_body: customHtml }: Record = - editedEvent?.getContent()['m.new.content'] ?? mEvent.getContent(); + editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent(); return [ typeof body === 'string' ? body : undefined,