Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(views): focus description editor when clicking empty area
Lyon Liang9170b01739f7
diff --git a/packages/views/editor/content-editor.css b/packages/views/editor/content-editor.cssindex 42c4a29123..4b6363d636 100644--- a/packages/views/editor/content-editor.css+++ b/packages/views/editor/content-editor.css@@ -28,6 +28,7 @@.rich-text-editor.ProseMirror {color: var(--foreground);caret-color: var(--foreground);+ min-height: 100%;}.rich-text-editor.ProseMirror:focus {@@ -486,4 +487,4 @@0 4px 12px color-mix(in srgb, black 12%, transparent),0 0 0 1px color-mix(in srgb, black 4%, transparent);min-width: 300px;-}\ No newline at end of file+}diff --git a/packages/views/editor/content-editor.test.tsx b/packages/views/editor/content-editor.test.tsxnew file mode 100644index 0000000000..9fe8e9e314--- /dev/null+++ b/packages/views/editor/content-editor.test.tsx@@ -0,0 +1,73 @@+import { describe, it, expect, vi, beforeEach } from "vitest";+import { fireEvent, render, screen } from "@testing-library/react";++const mockFocus = vi.hoisted(() => vi.fn());++vi.mock("@tanstack/react-query", () => ({+ useQueryClient: () => ({}),+}));++vi.mock("./extensions", () => ({+ createEditorExtensions: () => [],+}));++vi.mock("./extensions/file-upload", () => ({+ uploadAndInsertFile: vi.fn(),+}));++vi.mock("./utils/preprocess", () => ({+ preprocessMarkdown: (value: string) => value,+}));++vi.mock("./bubble-menu", () => ({+ EditorBubbleMenu: () => null,+}));++vi.mock("@tiptap/react", () => ({+ useEditor: () => ({+ commands: {+ focus: mockFocus,+ clearContent: vi.fn(),+ },+ getMarkdown: () => "",+ state: {+ doc: {+ content: {+ size: 0,+ },+ },+ },+ }),+ EditorContent: ({ className }: { className?: string }) => (+ <div className={className} data-testid="editor-content">+ <div className="ProseMirror rich-text-editor" data-testid="prosemirror" />+ </div>+ ),+}));++import { ContentEditor } from "./content-editor";++describe("ContentEditor", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it("focuses the editor when clicking the empty container area", () => {+ render(<ContentEditor placeholder="Add description..." />);++ const shell = screen.getByTestId("editor-content").parentElement;+ expect(shell).not.toBeNull();++ fireEvent.mouseDown(shell!);++ expect(mockFocus).toHaveBeenCalledWith("end");+ });++ it("does not hijack clicks that land inside the ProseMirror node", () => {+ render(<ContentEditor placeholder="Add description..." />);++ fireEvent.mouseDown(screen.getByTestId("prosemirror"));++ expect(mockFocus).not.toHaveBeenCalled();+ });+});diff --git a/packages/views/editor/content-editor.tsx b/packages/views/editor/content-editor.tsxindex f2dcc9d4c5..5bd839702b 100644--- a/packages/views/editor/content-editor.tsx+++ b/packages/views/editor/content-editor.tsx@@ -30,6 +30,7 @@ import {useEffect,useImperativeHandle,useRef,+ type MouseEvent as ReactMouseEvent,} from "react";import { useEditor, EditorContent } from "@tiptap/react";import { cn } from "@multica/ui/lib/utils";@@ -206,11 +207,25 @@ const ContentEditor = forwardRef<ContentEditorRef, ContentEditorProps>(},}));+ const handleContainerMouseDown = (event: ReactMouseEvent<HTMLDivElement>) => {+ if (!editable || !editor) return;++ const target = event.target as HTMLElement;+ if (target.closest(".ProseMirror")) return;+ if (target.closest("a, button, input, textarea, [role='button'], [data-node-view-wrapper]")) return;++ event.preventDefault();+ editor.commands.focus("end");+ };+if (!editor) return null;return (- <div className="relative min-h-full">- <EditorContent editor={editor} />+ <div+ className="relative flex min-h-full flex-col"+ onMouseDown={handleContainerMouseDown}+ >+ <EditorContent className="flex-1 min-h-full" editor={editor} />{editable && <EditorBubbleMenu editor={editor} />}</div>);