Update the browser, editor, settings, and installer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { StateEffect, StateField, type EditorState, type Range } from "@codemirror/state";
|
||||
import { Decoration, EditorView, WidgetType, type DecorationSet } from "@codemirror/view";
|
||||
import { syntaxTree } from "@codemirror/language";
|
||||
import { syntaxTree, foldedRanges, foldEffect, unfoldEffect } from "@codemirror/language";
|
||||
import { renderMarkdownSections } from "../workspace/noteHtml";
|
||||
import { renderDiagrams } from "../workspace/diagrams";
|
||||
import { tableControls, tableEditors } from "./tableControls";
|
||||
@@ -139,10 +139,12 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
|
||||
const active = state.selection.ranges.map(range => ({ from: state.doc.lineAt(range.from).from, to: state.doc.lineAt(range.to).to }));
|
||||
const selected = (from: number, to: number) => active.some(range => range.from <= to && range.to >= from);
|
||||
const hiddenBlocks: { from: number; to: number }[] = [];
|
||||
foldedRanges(state).between(0, state.doc.length, (from, to) => { hiddenBlocks.push({ from, to }); });
|
||||
const source = state.doc.toString();
|
||||
const editing = state.field(imageSource);
|
||||
const imageNodes = imageSourceRanges(source);
|
||||
for (const section of renderMarkdownSections(source, urls)) {
|
||||
if (hiddenBlocks.some(block => block.from <= section.start && block.to >= section.end - 1)) continue;
|
||||
if (!/(?:<pre|<table|<img|md-properties|md-callout|missing-image)/.test(section.html)) continue;
|
||||
// Code remains a real editor surface. A preview swap loses the first drag
|
||||
// and changes block height when focus or the selection moves elsewhere.
|
||||
@@ -199,17 +201,19 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
|
||||
const fenced = node.name === "FencedCode";
|
||||
const closed = fenced && /^\s*(`{3,}|~{3,})\s*$/.test(last.text) && last.number > first.number;
|
||||
const code = fenced ? source.slice(Math.min(first.to + 1, node.to), closed ? last.from : node.to) : source.slice(node.from, node.to);
|
||||
ranges.push(Decoration.widget({ widget: new CodeCopy(code), side: 1 }).range(first.to));
|
||||
const editingCode = selected(node.from, node.to);
|
||||
if (!editingCode) ranges.push(Decoration.widget({ widget: new CodeCopy(code), side: 1 }).range(first.to));
|
||||
for (let number = first.number; number <= last.number; number++) {
|
||||
const line = state.doc.line(number);
|
||||
ranges.push(Decoration.line({ class: `writer-code-line${number === first.number ? " writer-code-first" : ""}${number === last.number ? " writer-code-last" : ""}${fenced && (number === first.number || (closed && number === last.number)) ? " writer-code-fence" : ""}`, attributes: { spellcheck: "false" } }).range(line.from));
|
||||
ranges.push(Decoration.line({ class: editingCode ? "writer-code-source" : `writer-code-line${number === first.number ? " writer-code-first" : ""}${number === last.number ? " writer-code-last" : ""}${fenced && (number === first.number || (closed && number === last.number)) ? " writer-code-fence" : ""}`, attributes: { spellcheck: "false" } }).range(line.from));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const line = state.doc.lineAt(node.from);
|
||||
if (/^ATXHeading[1-6]$/.test(node.name)) {
|
||||
if (/^(?:ATX|Setext)Heading[1-6]$/.test(node.name)) {
|
||||
ranges.push(Decoration.line({ class: `writer-heading writer-h${node.name.at(-1)}` }).range(line.from));
|
||||
}
|
||||
if (node.name === "InlineCode") codeRanges.push({ from: node.from, to: node.to });
|
||||
if (selected(node.from, node.to)) return;
|
||||
if (node.name === "HorizontalRule") {
|
||||
ranges.push(Decoration.line({ class: "writer-divider-line" }).range(line.from));
|
||||
@@ -244,6 +248,12 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
|
||||
if (match[3].toLowerCase() === "x") mark(line.from + match[0].length, line.to, "writer-completed");
|
||||
}
|
||||
} });
|
||||
for (const match of source.matchAll(/\[\^([^\]\s]+)\](:)?/g)) {
|
||||
const from = match.index, to = from + match[0].length;
|
||||
if (hidden(from, to) || codeRanges.some(code => from >= code.from && to <= code.to)) continue;
|
||||
if (source[from - 1] === "\\") continue;
|
||||
mark(from, to, match[2] && state.doc.lineAt(from).from === from ? "writer-footnote-definition" : "writer-footnote-ref");
|
||||
}
|
||||
for (const match of source.matchAll(/\[\[([^\]\n]+)\]\]/g)) {
|
||||
const from = match.index, to = from + match[0].length;
|
||||
if (selected(from, to) || hidden(from, to) || codeRanges.some(code => from >= code.from && to <= code.to)) continue;
|
||||
@@ -260,7 +270,7 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
|
||||
update(value, transaction) {
|
||||
return transaction.docChanged || transaction.selection
|
||||
|| syntaxTree(transaction.startState) !== syntaxTree(transaction.state)
|
||||
|| transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource))
|
||||
|| transaction.effects.some(effect => effect.is(refreshImages) || effect.is(editImageSource) || effect.is(foldEffect) || effect.is(unfoldEffect))
|
||||
? build(transaction.state, value.map(transaction.changes)) : value;
|
||||
},
|
||||
provide: field => [EditorView.decorations.from(field), EditorView.atomicRanges.of(view => view.state.field(field).update({
|
||||
|
||||
Reference in New Issue
Block a user