mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-21 22:50:59 -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) => {
|
(ev: MouseEvent) => {
|
||||||
if (ev.currentTarget) {
|
if (ev.currentTarget) {
|
||||||
const element = ev.currentTarget as HTMLAnchorElement;
|
const element = ev.currentTarget as HTMLAnchorElement;
|
||||||
if (element.dataset.type === 'mention' && ev.shiftKey) {
|
|
||||||
internalEmit(
|
|
||||||
"MessageBox",
|
|
||||||
"append",
|
|
||||||
`<@${element.dataset.mentionId}>`,
|
|
||||||
"mention",
|
|
||||||
);
|
|
||||||
|
|
||||||
ev.preventDefault()
|
if (ev.shiftKey) {
|
||||||
} else if (openLink(element.href)) {
|
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();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +194,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
|
||||||
element.removeAttribute("target");
|
element.removeAttribute("target");
|
||||||
|
|
||||||
const link = determineLink(element.href);
|
const link = determineLink(element.href);
|
||||||
|
console.log(link)
|
||||||
switch (link.type) {
|
switch (link.type) {
|
||||||
case "profile": {
|
case "profile": {
|
||||||
element.setAttribute(
|
element.setAttribute(
|
||||||
|
@ -189,6 +207,19 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
|
||||||
)
|
)
|
||||||
break;
|
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": {
|
case "external": {
|
||||||
element.setAttribute("target", "_blank");
|
element.setAttribute("target", "_blank");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
type LinkType =
|
type LinkType =
|
||||||
| { type: "profile"; id: string }
|
| { 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: "external"; href: string; url: URL }
|
||||||
| { type: "none" };
|
| { type: "none" };
|
||||||
|
|
||||||
|
@ -11,6 +12,8 @@ const ALLOWED_ORIGINS = [
|
||||||
"local.revolt.chat",
|
"local.revolt.chat",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CHANNEL_PATH_RE = /^\/server\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}\/channel\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/
|
||||||
|
|
||||||
export function determineLink(href?: string): LinkType {
|
export function determineLink(href?: string): LinkType {
|
||||||
let internal,
|
let internal,
|
||||||
url: URL | null = null;
|
url: URL | null = null;
|
||||||
|
@ -27,6 +30,10 @@ export function determineLink(href?: string): LinkType {
|
||||||
return { type: "profile", id };
|
return { type: "profile", id };
|
||||||
}
|
}
|
||||||
} else {
|
} 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 };
|
return { type: "navigate", path };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue