diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index ce33d1447..5727032e6 100644 --- a/apps/client/src/components/app_context.ts +++ b/apps/client/src/components/app_context.ts @@ -218,12 +218,12 @@ export type CommandMappings = { /** Works only in the electron context menu. */ replaceMisspelling: CommandData; - importMarkdownInline: CommandData; showPasswordNotSet: CommandData; showProtectedSessionPasswordDialog: CommandData; showUploadAttachmentsDialog: CommandData & { noteId: string }; showIncludeNoteDialog: CommandData & { textTypeWidget: EditableTextTypeWidget }; showAddLinkDialog: CommandData & { textTypeWidget: EditableTextTypeWidget, text: string }; + showPasteMarkdownDialog: CommandData & { textTypeWidget: EditableTextTypeWidget }; closeProtectedSessionPasswordDialog: CommandData; copyImageReferenceToClipboard: CommandData; copyImageToClipboard: CommandData; diff --git a/apps/client/src/services/glob.ts b/apps/client/src/services/glob.ts index 48d0d29a7..44ce64309 100644 --- a/apps/client/src/services/glob.ts +++ b/apps/client/src/services/glob.ts @@ -20,9 +20,6 @@ function setupGlobs() { window.glob.froca = froca; window.glob.treeCache = froca; // compatibility for CKEditor builds for a while - // for CKEditor integration (button on block toolbar) - window.glob.importMarkdownInline = async () => appContext.triggerCommand("importMarkdownInline"); - window.onerror = function (msg, url, lineNo, columnNo, error) { const string = String(msg).toLowerCase(); diff --git a/apps/client/src/types.d.ts b/apps/client/src/types.d.ts index c5a93bd0a..d283983b4 100644 --- a/apps/client/src/types.d.ts +++ b/apps/client/src/types.d.ts @@ -26,7 +26,6 @@ interface CustomGlobals { appContext: AppContext; froca: Froca; treeCache: Froca; - importMarkdownInline: () => Promise; SEARCH_HELP_TEXT: string; activeDialog: JQuery | null; componentId: string; diff --git a/apps/client/src/widgets/dialogs/markdown_import.tsx b/apps/client/src/widgets/dialogs/markdown_import.tsx index d14d6fb11..43b20d378 100644 --- a/apps/client/src/widgets/dialogs/markdown_import.tsx +++ b/apps/client/src/widgets/dialogs/markdown_import.tsx @@ -7,6 +7,7 @@ import utils from "../../services/utils"; import Modal from "../react/Modal"; import Button from "../react/Button"; import { useTriliumEvent } from "../react/hooks"; +import EditableTextTypeWidget from "../type_widgets/editable_text"; interface RenderMarkdownResponse { htmlContent: string; @@ -14,39 +15,34 @@ interface RenderMarkdownResponse { export default function MarkdownImportDialog() { const markdownImportTextArea = useRef(null); + const [textTypeWidget, setTextTypeWidget] = useState(); const [ text, setText ] = useState(""); const [ shown, setShown ] = useState(false); - const triggerImport = useCallback(() => { - if (appContext.tabManager.getActiveContextNoteType() !== "text") { - return; - } - + useTriliumEvent("showPasteMarkdownDialog", ({ textTypeWidget }) => { + setTextTypeWidget(textTypeWidget); if (utils.isElectron()) { const { clipboard } = utils.dynamicRequire("electron"); const text = clipboard.readText(); - convertMarkdownToHtml(text); + convertMarkdownToHtml(text, textTypeWidget); } else { setShown(true); } - }, []); - - useTriliumEvent("importMarkdownInline", triggerImport); - useTriliumEvent("pasteMarkdownIntoText", triggerImport); - - async function sendForm() { - await convertMarkdownToHtml(text); - setText(""); - setShown(false); - } + }); return ( } + footer={