Fix: accidentally pulled in a huge amount of codemirror code by not using the parseMarkdown syscall in outline ops, whoopsies

Reduces the editor plug bundle size by about 600K
This commit is contained in:
Zef Hemel
2026-04-21 16:52:50 +02:00
parent a34c2d3ac9
commit a446014e2c
3 changed files with 24 additions and 17 deletions
+9 -4
View File
@@ -13,12 +13,17 @@ import { parseMarkdown } from "../../client/markdown_parser/parser.ts";
const CURSOR = "|^|";
function applyOp(
op: (text: string, cursor: number) => OutlineResult,
op: (
text: string,
tree: ReturnType<typeof parseMarkdown>,
cursor: number,
) => OutlineResult,
input: string,
): string {
const pos = input.indexOf(CURSOR);
const clean = input.slice(0, pos) + input.slice(pos + CURSOR.length);
const result = op(clean, pos);
const tree = parseMarkdown(clean);
const result = op(clean, tree, pos);
if (result === null || result === "blocked") {
return input; // no-op returns unchanged
}
@@ -394,11 +399,11 @@ Body 1b
## Second
Body 2a
`;
const after = moveDown(original, 4);
const after = moveDown(original, parseMarkdown(original), 4);
if (after === null || after === "blocked") {
throw new Error(`moveDown returned ${after}`);
}
const back = moveUp(after.text, after.cursor);
const back = moveUp(after.text, parseMarkdown(after.text), after.cursor);
if (back === null || back === "blocked") {
throw new Error(`moveUp returned ${back}`);
}
+5 -2
View File
@@ -1,4 +1,5 @@
import { editor } from "@silverbulletmd/silverbullet/syscalls";
import { editor, markdown } from "@silverbulletmd/silverbullet/syscalls";
import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree";
import {
indent as indentOp,
moveDown as moveDownOp,
@@ -9,13 +10,15 @@ import {
async function applyOutlineOp(
op: (
text: string,
tree: ParseTree,
cursor: number,
) => { text: string; cursor: number } | "blocked" | null,
fallback?: () => void,
) {
const cursorPos = await editor.getCursor();
const text = await editor.getText();
const result = op(text, cursorPos);
const tree = await markdown.parseMarkdown(text);
const result = op(text, tree, cursorPos);
if (result === "blocked") {
await editor.flashNotification("Cannot move item further", "error");
return;
+10 -11
View File
@@ -1,4 +1,3 @@
import { parseMarkdown } from "../../client/markdown_parser/parser.ts";
import {
addParentPointers,
findParentMatching,
@@ -228,10 +227,10 @@ function renumberOrderedList(
*/
function move(
text: string,
tree: ParseTree,
cursor: number,
direction: "up" | "down",
): OutlineResult {
const tree = parseMarkdown(text);
const ctx = detectContext(tree, cursor);
if (!ctx) {
return null;
@@ -248,10 +247,10 @@ function move(
}
}
export const moveUp = (text: string, cursor: number) =>
move(text, cursor, "up");
export const moveDown = (text: string, cursor: number) =>
move(text, cursor, "down");
export const moveUp = (text: string, tree: ParseTree, cursor: number) =>
move(text, tree, cursor, "up");
export const moveDown = (text: string, tree: ParseTree, cursor: number) =>
move(text, tree, cursor, "down");
/**
* Indents or outdents the outline element at cursor, dispatching to the
@@ -259,10 +258,10 @@ export const moveDown = (text: string, cursor: number) =>
*/
function adjustLevel(
text: string,
tree: ParseTree,
cursor: number,
delta: 1 | -1,
): OutlineResult {
const tree = parseMarkdown(text);
const ctx = detectContext(tree, cursor);
if (!ctx) {
return null;
@@ -282,10 +281,10 @@ function adjustLevel(
}
}
export const indent = (text: string, cursor: number) =>
adjustLevel(text, cursor, 1);
export const outdent = (text: string, cursor: number) =>
adjustLevel(text, cursor, -1);
export const indent = (text: string, tree: ParseTree, cursor: number) =>
adjustLevel(text, tree, cursor, 1);
export const outdent = (text: string, tree: ParseTree, cursor: number) =>
adjustLevel(text, tree, cursor, -1);
/**
* Swaps a list item with its adjacent sibling, renumbering if in an ordered