feat(workspace): numbered lists and reliable markdown paste
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m5s

- block type 'numbered' (/number): 1., a., i. by nesting, continues on
  Enter, an empty item ends the list; markdown export/import as 1.
- pasting: parser moved to lib/pasteOutline with tests; blank lines split
  paragraphs, numbered lists keep their type, indentation levels follow
  the widths in use (2, 3 or 4 spaces, tabs)
- text that stays in the focused block after pasting (a paragraph with
  line breaks) was dropped; the block now takes it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-30 19:36:15 +01:00
1 parent 9008d7c915
commit 2bfe74e66b
13 files changed
+286 -176

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import type { DocumentBlock } from './types';
// Numbered lists in the outliner: consecutive 'numbered' siblings count 1, 2, 3 …; a numbered list
// inside another one uses a, b, c, the next level i, ii, iii, then numbers again.
function alpha(n: number): string {
let s = '';
while (n > 0) {
n--;
s = String.fromCharCode(97 + (n % 26)) + s;
n = Math.floor(n / 26);
}
return s;
}
const ROMAN: [number, string][] = [
[1000, 'm'], [900, 'cm'], [500, 'd'], [400, 'cd'], [100, 'c'], [90, 'xc'],
[50, 'l'], [40, 'xl'], [10, 'x'], [9, 'ix'], [5, 'v'], [4, 'iv'], [1, 'i'],
];
function roman(n: number): string {
let s = '';
for (const [v, r] of ROMAN) {
while (n >= v) {
s += r;
n -= v;
}
}
return s;
}
export function listLabel(n: number, depth: number): string {
switch (depth % 3) {
case 1:
return `${alpha(n)}.`;
case 2:
return `${roman(n)}.`;
default:
return `${n}.`;
}
}
/** Label ("1.", "b.", "iii.") for every numbered block, in document order. */
export function numberedLabels(blocks: DocumentBlock[]): Map<string, string> {
const labels = new Map<string, string>();
const runs = new Map<number, number>(); // level -> count of the current run
const chain: DocumentBlock[] = []; // last block seen per level = ancestors of the next one
for (const b of blocks) {
const level = Math.max(0, b.level || 0);
for (const l of Array.from(runs.keys())) {
if (l > level) runs.delete(l);
}
chain.length = Math.min(chain.length, level);
if (b.type === 'numbered') {
const n = (runs.get(level) ?? 0) + 1;
runs.set(level, n);
const depth = chain.filter((a) => a && a.type === 'numbered').length;
labels.set(b.id, listLabel(n, depth));
} else {
runs.delete(level);
}
chain[level] = b;
}
return labels;
}