Release RuneStone 0.1.3 and expand plugin plans
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
|
||||
import { noteFormats } from "../src/lib/editor/noteFormats.ts";
|
||||
import { renderMarkdownHtml } from "../src/lib/workspace/noteHtml.ts";
|
||||
|
||||
const parser = markdown({ base: markdownLanguage, extensions: [noteFormats] }).language.parser;
|
||||
const render = (source: string) => renderMarkdownHtml(source, new Map());
|
||||
function mathNodes(source: string) {
|
||||
const nodes: string[] = [];
|
||||
parser.parse(source).iterate({ enter(node) {
|
||||
if (node.name === "NoteMath") nodes.push(source.slice(node.from, node.to));
|
||||
} });
|
||||
return nodes;
|
||||
}
|
||||
|
||||
test("dollar amounts stay literal in writing, reading, and table cells", () => {
|
||||
for (const source of [
|
||||
"$10", "$10 and $20", "$1,234.56 plus $78.90", "$10-$20", "$0.25-$.50",
|
||||
"US$10 / CA$20", "$ 10 and $ 20", "$-10 and $-20", "($10) and ($20)",
|
||||
"$10\n$20", "$10\r\n$20", "$10 **income**, $20 **cost**",
|
||||
]) {
|
||||
assert.deepEqual(mathNodes(source), [], source);
|
||||
const html = render(source);
|
||||
assert.doesNotMatch(html, /md-inline-math/, source);
|
||||
assert.equal((html.match(/\$/g) || []).length, (source.match(/\$/g) || []).length, source);
|
||||
assert.doesNotMatch(render(`| Amounts |\n| --- |\n| ${source.replace(/\r?\n/g, "<br>")} |`), /md-inline-math/, source);
|
||||
}
|
||||
});
|
||||
|
||||
test("inline math still works next to dollar amounts", () => {
|
||||
for (const expression of ["$x^2$", "$2 + 2$", "$x + y$", String.raw`$\frac{1}{2}$`, String.raw`$x + \$5$`]) {
|
||||
const source = `$10 and $20, then ${expression}, then $30 and $40.`;
|
||||
assert.deepEqual(mathNodes(source), [expression], source);
|
||||
assert.equal((render(source).match(/md-inline-math/g) || []).length, 1, source);
|
||||
assert.match(render(source), /\$10 and \$20/);
|
||||
assert.match(render(source), /\$30 and \$40/);
|
||||
}
|
||||
});
|
||||
|
||||
test("escaped, incomplete, spaced, multiline, and double delimiters do not create inline math", () => {
|
||||
for (const source of [String.raw`\$x\$`, "$x", "$ x$", "$x $", "$x\ny$", "$$x$$", "$$\nx\n$$", "`$x$`", "```\n$x$\n```", "$x$2"]) {
|
||||
assert.deepEqual(mathNodes(source), [], source);
|
||||
assert.doesNotMatch(render(source), /md-inline-math/, source);
|
||||
}
|
||||
});
|
||||
|
||||
test("highlight and comment formats keep their existing behavior", () => {
|
||||
const source = "==**highlight**== %%comment%%";
|
||||
const tree = parser.parse(source).toString();
|
||||
assert.match(tree, /NoteHighlight/);
|
||||
assert.match(tree, /StrongEmphasis/);
|
||||
assert.match(tree, /NoteComment/);
|
||||
assert.match(render(source), /<mark><strong>highlight<\/strong><\/mark>/);
|
||||
assert.match(render(source), /md-inline-comment/);
|
||||
});
|
||||
@@ -74,10 +74,7 @@ async function quickOpen(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
if (await page.getByRole("button", { name: "Switch to IDE layout (Ctrl E)", exact: true }).count()) {
|
||||
await page.getByRole("button", { name: "Switch to IDE layout (Ctrl E)", exact: true }).click();
|
||||
}
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
await page.locator('.live-writer .cm-content').waitFor();
|
||||
}
|
||||
|
||||
const source = '# Navigation\n\nBefore.\n\n| Name | Value | Formula |\n| --- | --- | --- |\n| Alpha | 12 | =B2*2 |\n| Beta | | tail |\n| Two<br>lines | short | end |\n\nAfter.\n';
|
||||
@@ -129,7 +126,6 @@ try {
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['navigation.md'] });
|
||||
}, source);
|
||||
await quickOpen('navigation.md');
|
||||
await page.getByRole('button', { name: 'Switch to writing layout (Ctrl E)', exact: true }).click();
|
||||
await table.waitFor();
|
||||
|
||||
// Reproduce the reported right-arrow escape, including formula destinations.
|
||||
@@ -290,6 +286,36 @@ try {
|
||||
assert.equal(await edit.count(), 0);
|
||||
assert.equal(await page.locator('.live-writer .cm-content').evaluate(el => el === document.activeElement), true);
|
||||
|
||||
// A line break in a tall table keeps the caret and viewport in the active cell.
|
||||
const tallSource = '# Tall table\n\nBefore.\n\n| Name | Value |\n| --- | --- |\n' +
|
||||
Array.from({ length: 45 }, (_, i) => `| Row ${i + 1} | |`).join('\n') + '\n\nAfter.\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('line-breaks.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['line-breaks.md'] });
|
||||
}, tallSource);
|
||||
await quickOpen('line-breaks.md');
|
||||
await table.waitFor();
|
||||
for (const [r, c, key] of [[1, 0, 'Shift+Enter'], [20, 0, 'Shift+Enter'], [21, 0, 'Enter'], [20, 0, 'Shift+Enter'], [20, 1, 'Shift+Enter'], [0, 0, 'Shift+Enter']]) {
|
||||
await at(r, c);
|
||||
const before = await page.locator('.live-writer .cm-scroller').evaluate(el => el.scrollTop);
|
||||
await page.keyboard.press(key);
|
||||
await expectCell(r, c);
|
||||
const after = await page.locator('.live-writer .cm-scroller').evaluate(el => el.scrollTop);
|
||||
assert.ok(Math.abs(after - before) < 50, `${key} in row ${r}: scroll moved from ${before} to ${after}`);
|
||||
await page.keyboard.type('Next line');
|
||||
await expectCell(r, c);
|
||||
assert.match(await edit.innerHTML(), /<br>Next line/);
|
||||
}
|
||||
await page.keyboard.press('Escape');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => {
|
||||
const source = window.__TEST__.files.get('line-breaks.md');
|
||||
return source.includes('| Name<br>Next line | Value |') &&
|
||||
source.includes('| Row 1<br>Next line | |') &&
|
||||
source.includes('| Row 21<br>Next line | |') &&
|
||||
/\| Row 20<br>Next line<br>Next line \| <br>Next line\s*\|/.test(source);
|
||||
});
|
||||
|
||||
// A table at the document boundary still offers somewhere to type outside it.
|
||||
const loneTable = '| Name |\n| --- |\n| Value |';
|
||||
for (const [key, after] of [['ArrowLeft', false], ['ArrowUp', false], ['ArrowRight', true], ['ArrowDown', true]]) {
|
||||
@@ -299,7 +325,6 @@ try {
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: [name] });
|
||||
}, { name, text: loneTable });
|
||||
await quickOpen(name);
|
||||
await page.getByRole('button', { name: 'Switch to writing layout (Ctrl E)', exact: true }).click();
|
||||
await table.waitFor();
|
||||
await at(after ? 1 : 0, 0, after ? 'End' : 'Home');
|
||||
await page.keyboard.press(key);
|
||||
@@ -317,7 +342,7 @@ try {
|
||||
await page.waitForFunction(({ name, expected }) => window.__TEST__.files.get(name) === expected, { name, expected });
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: arrows, caret positions, row wrapping, empty/formula/header cells, entry/exit in all directions, goal columns, document boundaries, text selection, word movement, multiline/wrapped text, save, undo/redo, Tab and Escape');
|
||||
console.log('PASS: arrows, caret positions, row wrapping, empty/formula/header cells, entry/exit in all directions, goal columns, document boundaries, text selection, word movement, multiline/wrapped text, line breaks and scrolling in tall tables, save, undo/redo, Tab and Escape');
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: '.audit/table-navigation-failure.png' });
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user