mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 15:15:24 +00:00
fix(file-manager): restore text selection and copying in Markdown previews (#1518)
This commit is contained in:
1 parent
a1f72b9e53
commit
64b9b18fe6
2 files changed
+56
-1
No files matched your search
@@ -48,6 +48,15 @@ export function MarkdownRenderer({
|
|||||||
: "px-4 py-2 text-foreground";
|
: "px-4 py-2 text-foreground";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div
|
||||||
|
className="select-text"
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
// Keep native text copying out of the file grid's global shortcuts.
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "c")
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
remarkPlugins={[remarkGfm]}
|
remarkPlugins={[remarkGfm]}
|
||||||
components={{
|
components={{
|
||||||
@@ -97,7 +106,9 @@ export function MarkdownRenderer({
|
|||||||
<table className={tableClass}>{children}</table>
|
<table className={tableClass}>{children}</table>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
thead: ({ children }) => <thead className="bg-muted">{children}</thead>,
|
thead: ({ children }) => (
|
||||||
|
<thead className="bg-muted">{children}</thead>
|
||||||
|
),
|
||||||
tbody: ({ children }) => <tbody>{children}</tbody>,
|
tbody: ({ children }) => <tbody>{children}</tbody>,
|
||||||
tr: ({ children }) => (
|
tr: ({ children }) => (
|
||||||
<tr className="border-b border-border">{children}</tr>
|
<tr className="border-b border-border">{children}</tr>
|
||||||
@@ -118,5 +129,6 @@ export function MarkdownRenderer({
|
|||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
import { MarkdownRenderer } from "../../../src/frontend/components/MarkdownRenderer";
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
describe("Markdown preview text copying", () => {
|
||||||
|
it.each([false, true])(
|
||||||
|
"supports copying in compact=%s previews",
|
||||||
|
(compact) => {
|
||||||
|
const fileShortcut = vi.fn();
|
||||||
|
document.addEventListener("keydown", fileShortcut);
|
||||||
|
try {
|
||||||
|
const { container } = render(
|
||||||
|
<div className="select-none">
|
||||||
|
<MarkdownRenderer
|
||||||
|
compact={compact}
|
||||||
|
content={"# Preview\n\nCopy this text."}
|
||||||
|
/>
|
||||||
|
</div>,
|
||||||
|
);
|
||||||
|
const preview = container.querySelector<HTMLElement>(".select-text")!;
|
||||||
|
preview.focus();
|
||||||
|
expect(preview).toHaveFocus();
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", { name: "Preview" }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
for (const modifier of [{ ctrlKey: true }, { metaKey: true }]) {
|
||||||
|
expect(fireEvent.keyDown(preview, { key: "c", ...modifier })).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect(fileShortcut).not.toHaveBeenCalled();
|
||||||
|
fireEvent.keyDown(preview, { key: "Escape" });
|
||||||
|
expect(fileShortcut).toHaveBeenCalledTimes(1);
|
||||||
|
expect(fireEvent.contextMenu(preview)).toBe(true);
|
||||||
|
} finally {
|
||||||
|
document.removeEventListener("keydown", fileShortcut);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user