diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-11-22 14:30:35 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-11-22 14:30:35 -0600 |
commit | e488cf8f44a0d6b2b05e50a2cc2e5467ea6f7e37 (patch) | |
tree | 71e0c440e7363169fc1dee0d80ecc07482536942 /src/view/com/util/RichText.tsx | |
parent | 1df48d4dad0d6b13047185e37db94997ab36bb4b (diff) | |
download | voidsky-e488cf8f44a0d6b2b05e50a2cc2e5467ea6f7e37.tar.zst |
Add support for links with no scheme in composer
Diffstat (limited to 'src/view/com/util/RichText.tsx')
-rw-r--r-- | src/view/com/util/RichText.tsx | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/view/com/util/RichText.tsx b/src/view/com/util/RichText.tsx index 3c54094ba..a67f90a63 100644 --- a/src/view/com/util/RichText.tsx +++ b/src/view/com/util/RichText.tsx @@ -77,7 +77,9 @@ function* toSegments(text: string, entities: Entity[]) { let subtext = text.slice(currEnt.index.start, currEnt.index.end) if ( !subtext.trim() || - stripUsername(subtext) !== stripUsername(currEnt.value) + (currEnt.type === 'mention' && + stripUsername(subtext) !== stripUsername(currEnt.value)) || + (currEnt.type === 'link' && !isSameLink(subtext, currEnt.value)) ) { // dont yield links to empty strings or strings that don't match the entity value yield subtext @@ -99,3 +101,9 @@ function* toSegments(text: string, entities: Entity[]) { function stripUsername(v: string): string { return v.trim().replace('@', '') } + +function isSameLink(a: string, b: string) { + a = a.startsWith('http') ? a : `https://${a}` + b = b.startsWith('http') ? b : `https://${b}` + return a === b +} |