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

Commit ed8b05b

Browse files
authored
Merge pull request #5951 from SimonBrandner/fix/room-pill-history
Fix saving room pill part to history
2 parents 96592aa + 1fe2085 commit ed8b05b

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/editor/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default class EditorModel {
158158
}
159159
}
160160

161-
reset(serializedParts: SerializedPart[], caret: Caret, inputType: string) {
161+
reset(serializedParts: SerializedPart[], caret?: Caret, inputType?: string) {
162162
this._parts = serializedParts.map(p => this._partCreator.deserializePart(p));
163163
if (!caret) {
164164
caret = this.getPositionAtEnd();

src/editor/parts.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface ISerializedPart {
3434
interface ISerializedPillPart {
3535
type: Type.AtRoomPill | Type.RoomPill | Type.UserPill;
3636
text: string;
37-
resourceId: string;
37+
resourceId?: string;
3838
}
3939

4040
export type SerializedPart = ISerializedPart | ISerializedPillPart;
@@ -287,6 +287,14 @@ abstract class PillPart extends BasePart implements IPillPart {
287287
}
288288
}
289289

290+
serialize(): ISerializedPillPart {
291+
return {
292+
type: this.type,
293+
text: this.text,
294+
resourceId: this.resourceId,
295+
};
296+
}
297+
290298
get canEdit() {
291299
return false;
292300
}
@@ -366,6 +374,13 @@ class AtRoomPillPart extends RoomPillPart {
366374
get type(): IPillPart["type"] {
367375
return Type.AtRoomPill;
368376
}
377+
378+
serialize(): ISerializedPillPart {
379+
return {
380+
type: this.type,
381+
text: this.text,
382+
};
383+
}
369384
}
370385

371386
class UserPillPart extends PillPart {
@@ -394,14 +409,6 @@ class UserPillPart extends PillPart {
394409
get className() {
395410
return "mx_UserPill mx_Pill";
396411
}
397-
398-
serialize(): ISerializedPillPart {
399-
return {
400-
type: this.type,
401-
text: this.text,
402-
resourceId: this.resourceId,
403-
};
404-
}
405412
}
406413

407414
class PillCandidatePart extends PlainBasePart implements IPillCandidatePart {
@@ -495,7 +502,7 @@ export class PartCreator {
495502
case Type.PillCandidate:
496503
return this.pillCandidate(part.text);
497504
case Type.RoomPill:
498-
return this.roomPill(part.text);
505+
return this.roomPill(part.resourceId);
499506
case Type.UserPill:
500507
return this.userPill(part.text, part.resourceId);
501508
}

test/editor/deserialize-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('editor/deserialize', function() {
178178
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
179179
expect(parts.length).toBe(3);
180180
expect(parts[0]).toStrictEqual({type: "plain", text: "Try "});
181-
expect(parts[1]).toStrictEqual({type: "room-pill", text: "#room:hs.tld"});
181+
expect(parts[1]).toStrictEqual({type: "room-pill", text: "#room:hs.tld", resourceId: "#room:hs.tld"});
182182
expect(parts[2]).toStrictEqual({type: "plain", text: "?"});
183183
});
184184
it('@room pill', function() {

0 commit comments

Comments
 (0)