Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add Command+Enter keyboard shortcut to save/update links

Cursor Agent20a804c0487a
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index cc2305c1..4d812fd7 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -1,7 +1,14 @@
import Link from "next/link";
import { useRouter } from "next/router";
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
@@ -177,6 +184,7 @@ export default function LinkSheet({
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isSaving, setIsSaving] = useState<boolean>(false);
const [currentPreset, setCurrentPreset] = useState<LinkPreset | null>(null);
+ const formRef = useRef<HTMLFormElement>(null);
const isPresetsAllowed =
isTrial ||
@@ -200,6 +208,28 @@ export default function LinkSheet({
setData(currentLink || DEFAULT_LINK_PROPS(linkType, groupId, !isDatarooms));
}, [currentLink]);
+ // Handle Command+Enter (Mac) or Ctrl+Enter (Windows/Linux) to submit the form
+ const handleKeyDown = useCallback(
+ (event: KeyboardEvent) => {
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
+ event.preventDefault();
+ if (!isSaving && formRef.current) {
+ formRef.current.requestSubmit();
+ }
+ }
+ },
+ [isSaving],
+ );
+
+ useEffect(() => {
+ if (isOpen) {
+ document.addEventListener("keydown", handleKeyDown);
+ return () => {
+ document.removeEventListener("keydown", handleKeyDown);
+ };
+ }
+ }, [isOpen, handleKeyDown]);
+
const handlePreviewLink = async (link: LinkWithViews) => {
if (link.domainId && isFree) {
toast.error("You need to upgrade to preview this link");
@@ -470,6 +500,7 @@ export default function LinkSheet({
</SheetHeader>
<form
+ ref={formRef}
className="flex grow flex-col"
onSubmit={(e) => handleSubmit(e, false)}
>
diff --git a/ee/features/permissions/components/dataroom-link-sheet.tsx b/ee/features/permissions/components/dataroom-link-sheet.tsx
index 7aebc9d2..0375db4a 100644
--- a/ee/features/permissions/components/dataroom-link-sheet.tsx
+++ b/ee/features/permissions/components/dataroom-link-sheet.tsx
@@ -1,7 +1,14 @@
import Link from "next/link";
import { useRouter } from "next/router";
-import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import { useTeam } from "@/context/team-context";
import {
@@ -113,6 +120,7 @@ export function DataroomLinkSheet({
const [currentPreset, setCurrentPreset] = useState<LinkPreset | null>(null);
const [showPermissionsSheet, setShowPermissionsSheet] =
useState<boolean>(false);
+ const formRef = useRef<HTMLFormElement>(null);
const [pendingLinkData, setPendingLinkData] =
useState<DEFAULT_LINK_TYPE | null>(null);
const [showSuccessSheet, setShowSuccessSheet] = useState<boolean>(false);
@@ -140,6 +148,28 @@ export function DataroomLinkSheet({
setData(currentLink || DEFAULT_LINK_PROPS(linkType, groupId, !isDatarooms));
}, [currentLink]);
+ // Handle Command+Enter (Mac) or Ctrl+Enter (Windows/Linux) to submit the form
+ const handleKeyDown = useCallback(
+ (event: KeyboardEvent) => {
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
+ event.preventDefault();
+ if (!isSaving && formRef.current) {
+ formRef.current.requestSubmit();
+ }
+ }
+ },
+ [isSaving],
+ );
+
+ useEffect(() => {
+ if (isOpen) {
+ document.addEventListener("keydown", handleKeyDown);
+ return () => {
+ document.removeEventListener("keydown", handleKeyDown);
+ };
+ }
+ }, [isOpen, handleKeyDown]);
+
const handlePreviewLink = async (link: LinkWithViews) => {
if (link.domainId && isFree) {
toast.error("You need to upgrade to preview this link");
@@ -695,6 +725,7 @@ export function DataroomLinkSheet({
</SheetHeader>
<form
+ ref={formRef}
className="flex grow flex-col"
onSubmit={(e) => handleSubmit(e, false)}
>