From 6e63127acbd9dc355eac4f5d73f7fb734a0346dc Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Fri, 22 May 2026 12:04:23 +0530 Subject: [PATCH] add proper functioning around / command --- apps/web/components/quick-note-card.tsx | 24 +++------------ .../web/components/text-editor/extensions.tsx | 30 ++++++++++++------- apps/web/components/text-editor/index.tsx | 12 +++++--- .../components/text-editor/slash-command.tsx | 2 +- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/apps/web/components/quick-note-card.tsx b/apps/web/components/quick-note-card.tsx index 31dbf61a..6e3b2549 100644 --- a/apps/web/components/quick-note-card.tsx +++ b/apps/web/components/quick-note-card.tsx @@ -188,15 +188,7 @@ export function QuickNoteCard({ className="w-full h-[120px] cursor-text text-left disabled:cursor-not-allowed disabled:opacity-50" aria-label="Expand quick note" > - - - New quick note - + - {previewText ?? "Type / for shortcuts"} + {previewText ?? "Start writing..."} @@ -318,16 +310,7 @@ export function QuickNoteCard({ "inset 1.421px 1.421px 4.263px 0 rgba(11, 15, 21, 0.4)", }} > -
-

- New quick note -

- +
diff --git a/apps/web/components/text-editor/extensions.tsx b/apps/web/components/text-editor/extensions.tsx index 9db26c2b..cefbac18 100644 --- a/apps/web/components/text-editor/extensions.tsx +++ b/apps/web/components/text-editor/extensions.tsx @@ -6,9 +6,13 @@ import TaskList from "@tiptap/extension-task-list" import TaskItem from "@tiptap/extension-task-item" import { cx } from "class-variance-authority" -const placeholder = Placeholder.configure({ - placeholder: 'Write, paste anything or type "/" for commands...', -}) +const DEFAULT_PLACEHOLDER = 'Write, paste anything or type "/" for commands...' + +function createPlaceholder(placeholderText = DEFAULT_PLACEHOLDER) { + return Placeholder.configure({ + placeholder: placeholderText, + }) +} const taskList = TaskList.configure({ HTMLAttributes: { @@ -82,11 +86,15 @@ const starterKit = StarterKit.configure({ gapcursor: false, }) -export const defaultExtensions = [ - starterKit, - placeholder, - link, - image, - taskList, - taskItem, -] +export function createDefaultExtensions(placeholderText?: string) { + return [ + starterKit, + createPlaceholder(placeholderText), + link, + image, + taskList, + taskItem, + ] +} + +export const defaultExtensions = createDefaultExtensions() diff --git a/apps/web/components/text-editor/index.tsx b/apps/web/components/text-editor/index.tsx index 7dafb7c7..58bd375a 100644 --- a/apps/web/components/text-editor/index.tsx +++ b/apps/web/components/text-editor/index.tsx @@ -4,32 +4,36 @@ import { useEditor, EditorContent } from "@tiptap/react" import { BubbleMenu } from "@tiptap/react/menus" import type { Editor } from "@tiptap/core" import { Markdown } from "@tiptap/markdown" -import { useRef, useEffect, useCallback } from "react" -import { defaultExtensions } from "./extensions" +import { useRef, useEffect, useCallback, useMemo } from "react" +import { createDefaultExtensions } from "./extensions" import { slashCommand } from "./suggestions" import { Bold, Italic, Code } from "lucide-react" import { useDebouncedCallback } from "use-debounce" import { cn } from "@lib/utils" -const extensions = [...defaultExtensions, slashCommand, Markdown] - export function TextEditor({ content: initialContent, onContentChange, onSubmit, debounceMs = 500, autoFocus = false, + placeholder, }: { content: string | undefined onContentChange: (content: string) => void onSubmit: () => void debounceMs?: number autoFocus?: boolean + placeholder?: string }) { const containerRef = useRef(null) const editorRef = useRef(null) const onSubmitRef = useRef(onSubmit) const hasUserEditedRef = useRef(false) + const extensions = useMemo( + () => [...createDefaultExtensions(placeholder), slashCommand, Markdown], + [placeholder], + ) useEffect(() => { onSubmitRef.current = onSubmit diff --git a/apps/web/components/text-editor/slash-command.tsx b/apps/web/components/text-editor/slash-command.tsx index 3b6f3a33..846b8792 100644 --- a/apps/web/components/text-editor/slash-command.tsx +++ b/apps/web/components/text-editor/slash-command.tsx @@ -111,7 +111,7 @@ function CommandMenu({ if (!mounted) return null return createPortal( -
+