Refactor pill and add tests (#10304)

This commit is contained in:
Michael Weimann 2023-03-08 13:06:50 +01:00 committed by GitHub
parent c0e40217f3
commit ad26925bb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 653 additions and 275 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright 2019, 2020, 2021 The Matrix.org Foundation C.I.C.
Copyright 2019-2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -21,7 +21,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixClientPeg } from "../MatrixClientPeg";
import SettingsStore from "../settings/SettingsStore";
import Pill, { PillType } from "../components/views/elements/Pill";
import { Pill, PillType, pillRoomNotifLen, pillRoomNotifPos } from "../components/views/elements/Pill";
import { parsePermalink } from "./permalinks/Permalinks";
/**
@ -82,14 +82,14 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
// Take a textNode and break it up to make all the instances of @room their
// own textNode, adding those nodes to roomNotifTextNodes
while (currentTextNode !== null) {
const roomNotifPos = Pill.roomNotifPos(currentTextNode.textContent);
const roomNotifPos = pillRoomNotifPos(currentTextNode.textContent);
let nextTextNode = null;
if (roomNotifPos > -1) {
let roomTextNode = currentTextNode;
if (roomNotifPos > 0) roomTextNode = roomTextNode.splitText(roomNotifPos);
if (roomTextNode.textContent.length > Pill.roomNotifLen()) {
nextTextNode = roomTextNode.splitText(Pill.roomNotifLen());
if (roomTextNode.textContent.length > pillRoomNotifLen()) {
nextTextNode = roomTextNode.splitText(pillRoomNotifLen());
}
roomNotifTextNodes.push(roomTextNode);
}