Add a way to copy message links.

Remove focus from auto complete after click, fixes #12.
This commit is contained in:
Paul 2021-08-07 10:52:22 +01:00
parent bb6ac68c8e
commit 2f06112921
3 changed files with 20 additions and 1 deletions

2
external/lang vendored

@ -1 +1 @@
Subproject commit 3048948e65b8214b065a6103347db78e2719e8ba Subproject commit d27cbcf7a8d7663d924ecb67de283b2fea901788

View file

@ -264,6 +264,7 @@ export function useAutoComplete(
function onClick(ev: JSX.TargetedMouseEvent<HTMLButtonElement>) { function onClick(ev: JSX.TargetedMouseEvent<HTMLButtonElement>) {
ev.preventDefault(); ev.preventDefault();
selectCurrent(document.querySelector("#message")!); selectCurrent(document.querySelector("#message")!);
setFocused(false);
} }
function onKeyDown(e: KeyboardEvent) { function onKeyDown(e: KeyboardEvent) {

View file

@ -71,6 +71,7 @@ interface ContextMenuData {
type Action = type Action =
| { action: "copy_id"; id: string } | { action: "copy_id"; id: string }
| { action: "copy_message_link"; message: Message }
| { action: "copy_selection" } | { action: "copy_selection" }
| { action: "copy_text"; content: string } | { action: "copy_text"; content: string }
| { action: "mark_as_read"; channel: Channel } | { action: "mark_as_read"; channel: Channel }
@ -145,6 +146,16 @@ function ContextMenus(props: Props) {
case "copy_id": case "copy_id":
writeClipboard(data.id); writeClipboard(data.id);
break; break;
case "copy_message_link":
{
let pathname = `/channel/${data.message.channel_id}/${data.message._id}`;
const channel = data.message.channel;
if (channel?.channel_type === "TextChannel")
pathname = `/server/${channel.server_id}${pathname}`;
writeClipboard(window.origin + pathname);
}
break;
case "copy_selection": case "copy_selection":
writeClipboard(document.getSelection()?.toString() ?? ""); writeClipboard(document.getSelection()?.toString() ?? "");
break; break;
@ -846,6 +857,13 @@ function ContextMenus(props: Props) {
} }
} }
if (message) {
generateAction({
action: "copy_message_link",
message,
});
}
generateAction( generateAction(
{ action: "copy_id", id }, { action: "copy_id", id },
sid sid