From ee8d688de1819653cf1b69e917776bbb27858589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 1 May 2021 10:59:28 +0200 Subject: [PATCH 1/4] Fix saving room pill part to history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/editor/parts.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/editor/parts.ts b/src/editor/parts.ts index 02c5d64895..b69f255f89 100644 --- a/src/editor/parts.ts +++ b/src/editor/parts.ts @@ -287,6 +287,14 @@ abstract class PillPart extends BasePart implements IPillPart { } } + serialize(): ISerializedPillPart { + return { + type: this.type, + text: this.text, + resourceId: this.resourceId, + }; + } + get canEdit() { return false; } @@ -394,14 +402,6 @@ class UserPillPart extends PillPart { get className() { return "mx_UserPill mx_Pill"; } - - serialize(): ISerializedPillPart { - return { - type: this.type, - text: this.text, - resourceId: this.resourceId, - }; - } } class PillCandidatePart extends PlainBasePart implements IPillCandidatePart { @@ -495,7 +495,7 @@ export class PartCreator { case Type.PillCandidate: return this.pillCandidate(part.text); case Type.RoomPill: - return this.roomPill(part.text); + return this.roomPill(part.resourceId); case Type.UserPill: return this.userPill(part.text, part.resourceId); } From c1549dfac58d64f979f937c328f36ed4f8787a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 1 May 2021 11:32:35 +0200 Subject: [PATCH 2/4] Make optional params optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/editor/model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/model.ts b/src/editor/model.ts index 2e70b872e9..f1b6f90957 100644 --- a/src/editor/model.ts +++ b/src/editor/model.ts @@ -158,7 +158,7 @@ export default class EditorModel { } } - reset(serializedParts: SerializedPart[], caret: Caret, inputType: string) { + reset(serializedParts: SerializedPart[], caret?: Caret, inputType?: string) { this._parts = serializedParts.map(p => this._partCreator.deserializePart(p)); if (!caret) { caret = this.getPositionAtEnd(); From 0c869364e961365f6648be64cb9a967dea6084cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 1 May 2021 12:27:52 +0200 Subject: [PATCH 3/4] Don't serialize resourceId in AtRoomPill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/editor/parts.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/editor/parts.ts b/src/editor/parts.ts index b69f255f89..6e3f35371d 100644 --- a/src/editor/parts.ts +++ b/src/editor/parts.ts @@ -34,7 +34,7 @@ interface ISerializedPart { interface ISerializedPillPart { type: Type.AtRoomPill | Type.RoomPill | Type.UserPill; text: string; - resourceId: string; + resourceId?: string; } export type SerializedPart = ISerializedPart | ISerializedPillPart; @@ -374,6 +374,13 @@ class AtRoomPillPart extends RoomPillPart { get type(): IPillPart["type"] { return Type.AtRoomPill; } + + serialize(): ISerializedPillPart { + return { + type: this.type, + text: this.text, + }; + } } class UserPillPart extends PillPart { From 1fe20853095432f3b95a3ec31e6c3bd672b5d10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 1 May 2021 12:28:18 +0200 Subject: [PATCH 4/4] Fix deserialize test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- test/editor/deserialize-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/editor/deserialize-test.js b/test/editor/deserialize-test.js index 07b75aaae5..7c7a2f84fb 100644 --- a/test/editor/deserialize-test.js +++ b/test/editor/deserialize-test.js @@ -178,7 +178,7 @@ describe('editor/deserialize', function() { const parts = normalize(parseEvent(htmlMessage(html), createPartCreator())); expect(parts.length).toBe(3); expect(parts[0]).toStrictEqual({type: "plain", text: "Try "}); - expect(parts[1]).toStrictEqual({type: "room-pill", text: "#room:hs.tld"}); + expect(parts[1]).toStrictEqual({type: "room-pill", text: "#room:hs.tld", resourceId: "#room:hs.tld"}); expect(parts[2]).toStrictEqual({type: "plain", text: "?"}); }); it('@room pill', function() {