mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 07:02:10 -05:00
Add shift+click
to channel links
This commit is contained in:
parent
a308e6ecb8
commit
f35ebeab67
2 changed files with 48 additions and 10 deletions
|
@ -140,16 +140,33 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
|
|||
(ev: MouseEvent) => {
|
||||
if (ev.currentTarget) {
|
||||
const element = ev.currentTarget as HTMLAnchorElement;
|
||||
if (element.dataset.type === 'mention' && ev.shiftKey) {
|
||||
internalEmit(
|
||||
"MessageBox",
|
||||
"append",
|
||||
`<@${element.dataset.mentionId}>`,
|
||||
"mention",
|
||||
);
|
||||
|
||||
ev.preventDefault()
|
||||
} else if (openLink(element.href)) {
|
||||
if (ev.shiftKey) {
|
||||
switch (element.dataset.type) {
|
||||
case "mention": {
|
||||
internalEmit(
|
||||
"MessageBox",
|
||||
"append",
|
||||
`<@${element.dataset.mentionId}>`,
|
||||
"mention",
|
||||
);
|
||||
ev.preventDefault()
|
||||
return
|
||||
}
|
||||
case "channel_mention": {
|
||||
internalEmit(
|
||||
"MessageBox",
|
||||
"append",
|
||||
`<#${element.dataset.mentionId}>`,
|
||||
"channel_mention",
|
||||
);
|
||||
ev.preventDefault()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (openLink(element.href)) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +194,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
|
|||
element.removeAttribute("target");
|
||||
|
||||
const link = determineLink(element.href);
|
||||
console.log(link)
|
||||
switch (link.type) {
|
||||
case "profile": {
|
||||
element.setAttribute(
|
||||
|
@ -189,6 +207,19 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
|
|||
)
|
||||
break;
|
||||
}
|
||||
case "navigate": {
|
||||
if (link.navigation_type === 'channel') {
|
||||
element.setAttribute(
|
||||
"data-type",
|
||||
"channel_mention",
|
||||
);
|
||||
element.setAttribute(
|
||||
"data-mention-id",
|
||||
link.channel_id
|
||||
)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "external": {
|
||||
element.setAttribute("target", "_blank");
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
type LinkType =
|
||||
| { type: "profile"; id: string }
|
||||
| { type: "navigate"; path: string }
|
||||
| { type: "navigate"; path: string; navigation_type?: null }
|
||||
| { type: "navigate"; path: string; navigation_type: 'channel'; channel_id: string }
|
||||
| { type: "external"; href: string; url: URL }
|
||||
| { type: "none" };
|
||||
|
||||
|
@ -11,6 +12,8 @@ const ALLOWED_ORIGINS = [
|
|||
"local.revolt.chat",
|
||||
];
|
||||
|
||||
const CHANNEL_PATH_RE = /^\/server\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}\/channel\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/
|
||||
|
||||
export function determineLink(href?: string): LinkType {
|
||||
let internal,
|
||||
url: URL | null = null;
|
||||
|
@ -27,6 +30,10 @@ export function determineLink(href?: string): LinkType {
|
|||
return { type: "profile", id };
|
||||
}
|
||||
} else {
|
||||
console.log(path)
|
||||
if(CHANNEL_PATH_RE.test(path)) {
|
||||
return { type: 'navigate', path, navigation_type: 'channel', channel_id: path.slice(43) }
|
||||
}
|
||||
return { type: "navigate", path };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue