MCPcopy
hub / github.com/element-hq/element-web / MockAutoComplete

Class MockAutoComplete

apps/web/test/unit-tests/editor/mock.ts:17–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15import DocumentPosition from "../../../src/editor/position";
16
17export class MockAutoComplete {
18 public _updateCallback;
19 public _partCreator;
20 public _completions;
21 public _part: Part | null;
22
23 constructor(updateCallback: UpdateCallback, partCreator: PartCreator, completions: PillPart[]) {
24 this._updateCallback = updateCallback;
25 this._partCreator = partCreator;
26 this._completions = completions;
27 this._part = null;
28 }
29
30 close() {
31 this._updateCallback({ close: true });
32 }
33
34 tryComplete(close = true) {
35 const matches = this._completions.filter((o) => {
36 return this._part && o.resourceId.startsWith(this._part.text);
37 });
38 if (matches.length === 1 && this._part && this._part.text.length > 1) {
39 const match = matches[0];
40 let pill: PillPart;
41 if (match.resourceId[0] === "@") {
42 pill = this._partCreator.userPill(match.text, match.resourceId);
43 } else {
44 pill = this._partCreator.roomPill(match.resourceId);
45 }
46 this._updateCallback({ replaceParts: [pill], close });
47 }
48 }
49
50 // called by EditorModel when typing into pill-candidate part
51 onPartUpdate(part: Part, pos: DocumentPosition) {
52 this._part = part;
53 }
54}
55
56// MockClient & MockRoom are only used for avatars in room and user pills,
57// which is not tested

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected