Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(editor): create sub-issue from selected text in bubble menu (#1348)

Jiayuan Zhang2ab89d4690af
diff --git a/packages/views/editor/bubble-menu.tsx b/packages/views/editor/bubble-menu.tsx
index 2288937e44..392843f999 100644
--- a/packages/views/editor/bubble-menu.tsx
+++ b/packages/views/editor/bubble-menu.tsx
@@ -32,6 +32,8 @@ import { useEditorState } from "@tiptap/react";
import type { Editor } from "@tiptap/core";
import { posToDOMRect } from "@tiptap/core";
import { NodeSelection } from "@tiptap/pm/state";
+import { toast } from "sonner";
+import { useCreateIssue } from "@multica/core/issues/mutations";
import { Toggle } from "@multica/ui/components/ui/toggle";
import { Separator } from "@multica/ui/components/ui/separator";
import {
@@ -64,6 +66,8 @@ import {
Heading1,
Heading2,
Heading3,
+ FilePlus,
+ Loader2,
} from "lucide-react";
// ---------------------------------------------------------------------------
@@ -344,11 +348,106 @@ function ListDropdown({ editor, onOpenChange, isBullet, isOrdered }: { editor: E
);
}
+// ---------------------------------------------------------------------------
+// Create Sub-Issue Button
+// ---------------------------------------------------------------------------
+
+/**
+ * Turns the current selection into a sub-issue of `parentIssueId` and replaces
+ * the selection with a mention link to the new issue. Title is the selected
+ * text (trimmed, collapsed whitespace, capped). Only rendered when a parent
+ * issue is in scope; otherwise there's no meaningful "sub-issue of" target.
+ */
+function CreateSubIssueButton({
+ editor,
+ parentIssueId,
+}: {
+ editor: Editor;
+ parentIssueId: string;
+}) {
+ const createIssue = useCreateIssue();
+ const [pending, setPending] = useState(false);
+
+ const handleClick = useCallback(async () => {
+ if (pending) return;
+ const { from, to } = editor.state.selection;
+ if (from === to) return;
+
+ // Title from selection: collapse whitespace, cap length. The full selection
+ // still becomes the link text — only the issue title is capped.
+ const rawTitle = editor.state.doc.textBetween(from, to, " ", " ").trim();
+ const title = rawTitle.replace(/\s+/g, " ").slice(0, 200);
+ if (!title) return;
+
+ setPending(true);
+ try {
+ const newIssue = await createIssue.mutateAsync({
+ title,
+ parent_issue_id: parentIssueId,
+ });
+ editor
+ .chain()
+ .focus()
+ .insertContentAt(
+ { from, to },
+ [
+ {
+ type: "mention",
+ attrs: {
+ id: newIssue.id,
+ label: newIssue.identifier,
+ type: "issue",
+ },
+ },
+ { type: "text", text: " " },
+ ],
+ )
+ .run();
+ toast.success(`Created ${newIssue.identifier}`);
+ } catch {
+ toast.error("Failed to create sub-issue");
+ } finally {
+ setPending(false);
+ }
+ }, [editor, parentIssueId, createIssue, pending]);
+
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Toggle
+ size="sm"
+ pressed={false}
+ disabled={pending}
+ onPressedChange={handleClick}
+ onMouseDown={(e) => e.preventDefault()}
+ />
+ }
+ >
+ {pending ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : (
+ <FilePlus className="size-3.5" />
+ )}
+ </TooltipTrigger>
+ <TooltipContent side="top" sideOffset={8}>
+ Create sub-issue from selection
+ </TooltipContent>
+ </Tooltip>
+ );
+}
+
// ---------------------------------------------------------------------------
// Main Bubble Menu — @floating-ui/dom + portal to body
// ---------------------------------------------------------------------------
-function EditorBubbleMenu({ editor }: { editor: Editor }) {
+function EditorBubbleMenu({
+ editor,
+ currentIssueId,
+}: {
+ editor: Editor;
+ currentIssueId?: string;
+}) {
const [visible, setVisible] = useState(false);
const [mode, setMode] = useState<"toolbar" | "link-edit">("toolbar");
const floatingRef = useRef<HTMLDivElement>(null);
@@ -502,6 +601,12 @@ function EditorBubbleMenu({ editor }: { editor: Editor }) {
</TooltipTrigger>
<TooltipContent side="top" sideOffset={8}>Quote</TooltipContent>
</Tooltip>
+ {currentIssueId && (
+ <>
+ <Separator orientation="vertical" className="mx-0.5 h-5" />
+ <CreateSubIssueButton editor={editor} parentIssueId={currentIssueId} />
+ </>
+ )}
</div>
</TooltipProvider>
)}
diff --git a/packages/views/editor/content-editor.tsx b/packages/views/editor/content-editor.tsx
index 354b4405e0..7cc4cc86f3 100644
--- a/packages/views/editor/content-editor.tsx
+++ b/packages/views/editor/content-editor.tsx
@@ -75,6 +75,12 @@ interface ContentEditorProps {
showBubbleMenu?: boolean;
/** When true, bare Enter submits (chat-style). Mod-Enter always submits. */
submitOnEnter?: boolean;
+ /**
+ * ID of the issue this editor belongs to. When set, the bubble menu exposes
+ * a "Create sub-issue from selection" action that parents the new issue
+ * under this ID and replaces the selection with a mention link.
+ */
+ currentIssueId?: string;
}
interface ContentEditorRef {
@@ -104,6 +110,7 @@ const ContentEditor = forwardRef<ContentEditorRef, ContentEditorProps>(
onUploadFile,
showBubbleMenu = true,
submitOnEnter = false,
+ currentIssueId,
},
ref,
) {
@@ -258,7 +265,9 @@ const ContentEditor = forwardRef<ContentEditorRef, ContentEditorProps>(
onMouseDown={handleContainerMouseDown}
>
<EditorContent className="flex-1 min-h-full" editor={editor} />
- {editable && showBubbleMenu && <EditorBubbleMenu editor={editor} />}
+ {editable && showBubbleMenu && (
+ <EditorBubbleMenu editor={editor} currentIssueId={currentIssueId} />
+ )}
<LinkHoverCard {...hover} />
</div>
);
diff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsx
index 8f9328d75e..179a35bbef 100644
--- a/packages/views/issues/components/comment-card.tsx
+++ b/packages/views/issues/components/comment-card.tsx
@@ -291,6 +291,7 @@ function CommentRow({
onSubmit={saveEdit}
onUploadFile={(file) => uploadWithToast(file, { issueId })}
debounceMs={100}
+ currentIssueId={issueId}
/>
</div>
<div className="flex items-center justify-between mt-2">
@@ -511,6 +512,7 @@ function CommentCard({
onSubmit={saveEdit}
onUploadFile={(file) => uploadWithToast(file, { issueId })}
debounceMs={100}
+ currentIssueId={issueId}
/>
</div>
<div className="flex items-center justify-between mt-2">
diff --git a/packages/views/issues/components/comment-input.tsx b/packages/views/issues/components/comment-input.tsx
index be464763c0..4f4bf3b862 100644
--- a/packages/views/issues/components/comment-input.tsx
+++ b/packages/views/issues/components/comment-input.tsx
@@ -63,6 +63,7 @@ function CommentInput({ issueId, onSubmit }: CommentInputProps) {
onSubmit={handleSubmit}
onUploadFile={handleUpload}
debounceMs={100}
+ currentIssueId={issueId}
/>
</div>
<div className="absolute bottom-1 right-1.5 flex items-center gap-1">
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index f6b2c290b6..fa74af9a4c 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -1049,6 +1049,7 @@ export function IssueDetail({ issueId, onDelete, defaultSidebarOpen = true, layo
onUpdate={(md) => handleUpdateField({ description: md })}
onUploadFile={handleDescriptionUpload}
debounceMs={1500}
+ currentIssueId={id}
/>
<div className="flex items-center gap-1 mt-3">
diff --git a/packages/views/issues/components/reply-input.tsx b/packages/views/issues/components/reply-input.tsx
index 14ea5ac0e2..6006edfd99 100644
--- a/packages/views/issues/components/reply-input.tsx
+++ b/packages/views/issues/components/reply-input.tsx
@@ -110,6 +110,7 @@ function ReplyInput({
onSubmit={handleSubmit}
onUploadFile={handleUpload}
debounceMs={100}
+ currentIssueId={issueId}
/>
</div>
</div>