Improve editor, plugin updates, and window transfers for 0.1.41
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
import { writerHistory, historyKeymap } from "./writerHistory";
|
||||
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
|
||||
import { noteFormats } from "./noteFormats";
|
||||
import { searchKeymap } from "@codemirror/search";
|
||||
import { closeSearchPanel, findNext, findPrevious, openSearchPanel, searchKeymap } from "@codemirror/search";
|
||||
import { htmlToMarkdown } from "$lib/workspace/htmlToMarkdown";
|
||||
import { writerSearch } from "./writerSearch";
|
||||
import type { OpenBuffer } from "$lib/workspace/types";
|
||||
import { workspaceReadDataUrl, workspaceReveal } from "$lib/workspace/api";
|
||||
@@ -52,6 +53,13 @@
|
||||
let host: HTMLDivElement | undefined = $state();
|
||||
let editor = $state.raw<EditorView>();
|
||||
export function focus() { editor?.focus(); }
|
||||
export function openFind(replace = false) {
|
||||
if (!editor) return;
|
||||
openSearchPanel(editor);
|
||||
editor.dom.querySelector<HTMLInputElement>(replace ? 'input[name="replace"]' : 'input[name="search"]')?.select();
|
||||
}
|
||||
export function closeFind() { if (editor) closeSearchPanel(editor); }
|
||||
export function nextMatch(backward = false) { if (editor) (backward ? findPrevious : findNext)(editor); }
|
||||
let error = $state("");
|
||||
let model: import("monaco-editor").editor.ITextModel | undefined;
|
||||
let ModelSelection: typeof import("monaco-editor").Selection;
|
||||
@@ -272,6 +280,17 @@
|
||||
return true;
|
||||
},
|
||||
paste(event, view) {
|
||||
const html = event.clipboardData?.getData("text/html") || "";
|
||||
if (/<table[\s>]/i.test(html)) {
|
||||
const markdown = htmlToMarkdown(html).replace(/\r\n?/g, "\n").trim();
|
||||
if (markdown) {
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
const { from, to } = view.state.selection.main;
|
||||
const insert = imageInsertion(view.state.doc.toString(), from, to, [markdown]);
|
||||
view.dispatch({ changes: { from, to, insert }, selection: { anchor: from + insert.length }, userEvent: "input.paste", annotations: isolateHistory.of("full") });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!onInsertImage || !imageFiles(event.clipboardData).length) return false;
|
||||
void insertImages(event, view); return true;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user