How to Paste Multi-Line Text as A Single Line

Just realized I can reply to my own posts, and post links and whatnot where the Forum wouldn’t let me before. Here’s the rest of the information:

Plugins:

Code:

plugin.addCommand({
    name: 'Paste and Select',
    id: "paste-and-select",
    callback: async () => {
        const activeFile = app.workspace.getActiveFile();  
        const activeView = app.workspace.activeLeaf.view;

        if (!activeView) {
            console.warn("No active view!");
            return;
        }

        const editor = activeView.editor;
        const currPos = editor.getCursor();

        const clipboard = await navigator.clipboard.readText();
        if (!clipboard) {
            window.alert("No text in clipboard");
            return;
        }

        editor.replaceRange(clipboard, currPos);
        const endPos = editor.offsetToPos(editor.posToOffset(currPos) + clipboard.length);
        console.log(currPos, endPos);
        editor.setSelection(currPos, endPos);
    }
});

Setup:

  1. Paste the code into the User Plugins’ Snippets field, then press the > symbol on the left.
  2. QuickAdd: Create Macro “Single-Line Paste”
  3. Steps within the macro: 1.) User Plugins: Paste and Select, 2.) Wait for 10ms, 3.) Text Format: Merge broken paragraph(s) in selection
  4. Bind the Macro sequence to a hotkey.