diff --git a/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx index 7acc595e7..e66b3e8f6 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/editor/[documentId]/page.tsx @@ -1,7 +1,7 @@ "use client"; import { useAtom } from "jotai"; -import { AlertCircle, ArrowLeft, FileText, Save } from "lucide-react"; +import { AlertCircle, ArrowLeft, FileText } from "lucide-react"; import { motion } from "motion/react"; import dynamic from "next/dynamic"; import { useParams, useRouter } from "next/navigation"; @@ -297,6 +297,12 @@ export default function EditorPage() { } }; + const handleSaveAndLeave = async () => { + setShowUnsavedDialog(false); + setPendingNavigation(null); + await handleSave(); + }; + const handleCancelLeave = () => { setShowUnsavedDialog(false); setPendingNavigation(null); @@ -364,11 +370,21 @@ export default function EditorPage() { {/* Toolbar */} -
-
+
+
+

{displayTitle}

@@ -377,62 +393,32 @@ export default function EditorPage() { )}
- -
- - -
{/* Editor Container */} -
-
- {error && ( - -
- -

{error}

-
-
- )} -
- -
+
+ {error && ( + +
+ +

{error}

+
+
+ )} +
+
@@ -452,7 +438,12 @@ export default function EditorPage() { Cancel - OK + + Save + + + Leave without saving + diff --git a/surfsense_web/components/editor/plate-editor.tsx b/surfsense_web/components/editor/plate-editor.tsx index 6eb72b030..e559f85af 100644 --- a/surfsense_web/components/editor/plate-editor.tsx +++ b/surfsense_web/components/editor/plate-editor.tsx @@ -50,6 +50,8 @@ interface PlateEditorProps { hasUnsavedChanges?: boolean; /** Whether a save is in progress */ isSaving?: boolean; + /** Start the editor in editing mode instead of viewing mode. Ignored when readOnly is true. */ + defaultEditing?: boolean; } export function PlateEditor({ @@ -63,14 +65,15 @@ export function PlateEditor({ onSave, hasUnsavedChanges = false, isSaving = false, + defaultEditing = false, }: PlateEditorProps) { const lastMarkdownRef = useRef(markdown); - // Always initialize the editor in readOnly mode (viewing mode). - // For non-forced readOnly, the user can toggle to editing via ModeToolbarButton. - // For forced readOnly, the mode button is hidden and readOnly stays true. + // When readOnly is forced, always start in readOnly. + // Otherwise, respect defaultEditing to decide initial mode. + // The user can still toggle between editing/viewing via ModeToolbarButton. const editor = usePlateEditor({ - readOnly: true, + readOnly: readOnly || !defaultEditing, plugins: [ ...BasicNodesKit, ...TableKit,