Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { OrderedList } from "@tiptap/extension-ordered-list";
import { Paragraph } from "@tiptap/extension-paragraph";
import Placeholder from "@tiptap/extension-placeholder";
import { Strike } from "@tiptap/extension-strike";
import { TableKit } from "@tiptap/extension-table";
import TaskItem from "@tiptap/extension-task-item";
import TaskList from "@tiptap/extension-task-list";
import { Text } from "@tiptap/extension-text";
Expand Down Expand Up @@ -150,6 +151,20 @@ function getMarkdown(editor: Editor | null): string {
return storage?.markdown?.getMarkdown?.() ?? "";
}

function isMarkdownTable(text: string): boolean {
const lines = text
.trim()
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean);

if (lines.length < 2 || !lines[0]?.includes("|")) {
return false;
}

return /^\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?$/.test(lines[1]);
}

export function MarkdownEditor({
content,
onSave,
Expand All @@ -166,6 +181,7 @@ export function MarkdownEditor({
// Thread through a ref so the extension reads the live callback each fire.
const searchFilesRef = useRef(searchFiles);
searchFilesRef.current = searchFiles;
const editorRef = useRef<Editor | null>(null);

const { getUrlAction } = useInlineLinkActions();

Expand Down Expand Up @@ -241,6 +257,26 @@ export function MarkdownEditor({
LinearImage.configure({
HTMLAttributes: { class: "max-w-full h-auto rounded-md my-3" },
}),
TableKit.configure({
table: {
resizable: false,
cellMinWidth: 192,
HTMLAttributes: {
class: "markdown-table my-4 min-w-full border-collapse",
},
},
tableHeader: {
HTMLAttributes: {
class:
"bg-muted px-4 py-2 text-left text-sm font-semibold align-top",
},
},
tableCell: {
HTMLAttributes: {
class: "border-t border-border px-4 py-2 text-sm align-top",
},
},
}),
Placeholder.configure({
placeholder: ({ node }) => {
if (node.type.name === "paragraph") {
Expand Down Expand Up @@ -278,6 +314,22 @@ export function MarkdownEditor({
}
return false;
},
handlePaste: (_, event) => {
const text = event.clipboardData?.getData("text/plain") ?? "";
const currentEditor = editorRef.current;
if (!currentEditor || !isMarkdownTable(text)) {
return false;
}

event.preventDefault();
return currentEditor.commands.insertContentAt(
{
from: currentEditor.state.selection.from,
to: currentEditor.state.selection.to,
},
text,
);
},
handleClickOn: (_view, _pos, _node, _nodePos, event) => {
const target = event.target as HTMLElement | null;
const anchor = target?.closest?.("a") as HTMLAnchorElement | null;
Expand All @@ -302,6 +354,7 @@ export function MarkdownEditor({
onSave?.(getMarkdown(editor));
},
});
editorRef.current = editor;

useEffect(() => {
if (!editor || editor.isFocused) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ ul[data-type="taskList"]
0 0 0 2px hsl(var(--background)),
0 0 0 4px hsl(var(--ring));
}

.markdown-table {
width: max-content;
min-width: 100%;
overflow: hidden;
border: 1px solid hsl(var(--border));
border-radius: 0.375rem;
}
Comment on lines +89 to +95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Wide tables can overflow the editor with no horizontal scroll.

width: max-content combined with th/td { min-width: 12rem } (192px) means a 3‑column table needs ≥576px and a 4‑column table needs ≥768px just for the cell minimums. Since neither .markdown-table nor the parent .ProseMirror enables overflow-x: auto, anything wider than the editor pane will visually overflow into surrounding chrome (and overflow: hidden on the table only clips its own descendants, not its outer box). Consider wrapping tables in a horizontally scrollable container, e.g. setting the wrapper produced by the Table extension to overflow-x: auto:

♻️ Suggested CSS
 .markdown-table {
-	width: max-content;
-	min-width: 100%;
-	overflow: hidden;
-	border: 1px solid hsl(var(--border));
-	border-radius: 0.375rem;
+	width: max-content;
+	min-width: 100%;
+	border: 1px solid hsl(var(--border));
+	border-radius: 0.375rem;
+}
+
+/* Tiptap wraps tables in a div.tableWrapper */
+.ProseMirror .tableWrapper {
+	overflow-x: auto;
+	margin: 1rem 0;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.markdown-table {
width: max-content;
min-width: 100%;
overflow: hidden;
border: 1px solid hsl(var(--border));
border-radius: 0.375rem;
}
.markdown-table {
width: max-content;
min-width: 100%;
border: 1px solid hsl(var(--border));
border-radius: 0.375rem;
}
/* Tiptap wraps tables in a div.tableWrapper */
.ProseMirror .tableWrapper {
overflow-x: auto;
margin: 1rem 0;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/renderer/components/MarkdownEditor/markdown-editor.css`
around lines 89 - 95, The .markdown-table rule uses width: max-content which,
together with th/td { min-width: 12rem }, lets wide tables overflow the editor
because neither the table nor its ProseMirror parent enables horizontal
scrolling; change the table wrapper produced by the Table extension (or the
.markdown-table container) to allow horizontal scrolling (e.g., remove or avoid
width: max-content, ensure the wrapper or .ProseMirror has overflow-x: auto and
max-width: 100%, and keep the table itself max-width: none or display: block so
inner min-widths can scroll) so wide tables scroll horizontally instead of
overflowing the editor chrome.


.markdown-table th,
.markdown-table td {
border: 1px solid hsl(var(--border));
min-width: 12rem;
}

.markdown-table th > *,
.markdown-table td > * {
margin-top: 0;
margin-bottom: 0;
}

.markdown-table .selectedCell {
background-color: hsl(var(--accent) / 0.6);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { ListItem } from "@tiptap/extension-list-item";
import { OrderedList } from "@tiptap/extension-ordered-list";
import { Paragraph } from "@tiptap/extension-paragraph";
import { Strike } from "@tiptap/extension-strike";
import { Table } from "@tiptap/extension-table";
import TableCell from "@tiptap/extension-table-cell";
import TableHeader from "@tiptap/extension-table-header";
import TableRow from "@tiptap/extension-table-row";
import { TableKit } from "@tiptap/extension-table";
import TaskItem from "@tiptap/extension-task-item";
import TaskList from "@tiptap/extension-task-list";
import { Text } from "@tiptap/extension-text";
Expand Down Expand Up @@ -158,21 +155,23 @@ export function createMarkdownExtensions({
},
}),
SafeImage,
Table.configure({
resizable: false,
HTMLAttributes: {
class: "markdown-table my-4 min-w-full border-collapse",
TableKit.configure({
table: {
resizable: false,
cellMinWidth: 192,
HTMLAttributes: {
class: "markdown-table my-4 min-w-full border-collapse",
},
},
}),
TableRow,
TableHeader.configure({
HTMLAttributes: {
class: "bg-muted px-4 py-2 text-left text-sm font-semibold align-top",
tableHeader: {
HTMLAttributes: {
class: "bg-muted px-4 py-2 text-left text-sm font-semibold align-top",
},
},
}),
TableCell.configure({
HTMLAttributes: {
class: "border-t border-border px-4 py-2 text-sm align-top",
tableCell: {
HTMLAttributes: {
class: "border-t border-border px-4 py-2 text-sm align-top",
},
},
}),
Markdown.configure({
Expand Down
Loading