@blankdotpage/cake 0.1.79-rc.4 → 0.1.79-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/cake/clipboard.ts"],"names":[],"mappings":"AAmgBA,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYzE"}
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/cake/clipboard.ts"],"names":[],"mappings":"AA0gBA,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYzE"}
@@ -383,8 +383,13 @@ function normalizeListPrefixes(content) {
383
383
  const match = line.match(/^(\s*)([-*+]|\d+\.)( +)(.*)$/);
384
384
  if (match) {
385
385
  const [, indent, marker, , listContent] = match;
386
- if (currentListType === null) {
387
- currentListType = /\d+\./.test(marker) ? "numbered" : "bullet";
386
+ const nextListType = /\d+\./.test(marker) ? "numbered" : "bullet";
387
+ if (currentListType !== nextListType) {
388
+ currentListType = nextListType;
389
+ currentNumber =
390
+ nextListType === "numbered"
391
+ ? Number.parseInt(marker, 10)
392
+ : 1;
388
393
  }
389
394
  const newMarker = currentListType === "bullet" ? "-" : `${currentNumber}.`;
390
395
  if (currentListType === "numbered") {
@@ -392,6 +397,8 @@ function normalizeListPrefixes(content) {
392
397
  }
393
398
  return `${indent}${newMarker} ${listContent}`;
394
399
  }
400
+ currentListType = null;
401
+ currentNumber = 1;
395
402
  return line;
396
403
  })
397
404
  .join("\n");
@@ -1 +1 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/heading/heading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAwa5B,eAAO,MAAM,gBAAgB,EAAE,aA8N9B,CAAC"}
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/heading/heading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAwa5B,eAAO,MAAM,gBAAgB,EAAE,aAkQ9B,CAAC"}
@@ -347,32 +347,56 @@ export const headingExtension = (editor) => {
347
347
  if (command.type !== "insert" || command.text !== " ") {
348
348
  return null;
349
349
  }
350
- const { source, selection, map } = state;
350
+ const { source, selection, map, runtime } = state;
351
351
  if (selection.start !== selection.end) {
352
352
  return null;
353
353
  }
354
354
  const cursorPos = Math.max(0, Math.min(map.cursorLength, selection.start));
355
355
  const sourcePos = map.cursorToSource(cursorPos, selection.affinity ?? "forward");
356
356
  const lineStart = findLineStartInSource(source, sourcePos);
357
- const prefix = source.slice(lineStart, sourcePos);
358
- if (!prefix || prefix.length > 3) {
359
- return null;
360
- }
361
- if (!/^[#]+$/.test(prefix)) {
362
- return null;
357
+ const rawPrefix = source.slice(lineStart, sourcePos);
358
+ // Fast path: hashes at the actual source line start (no inline markers).
359
+ if (rawPrefix.length > 0 &&
360
+ rawPrefix.length <= 3 &&
361
+ /^[#]+$/.test(rawPrefix) &&
362
+ sourcePos === lineStart + rawPrefix.length) {
363
+ const nextSource = source.slice(0, sourcePos) + " " + source.slice(sourcePos);
364
+ const lineStartCursor = cursorPos - rawPrefix.length;
365
+ return {
366
+ source: nextSource,
367
+ selection: {
368
+ start: lineStartCursor,
369
+ end: lineStartCursor,
370
+ affinity: "forward",
371
+ },
372
+ };
363
373
  }
364
- // Only convert when we're immediately after the leading hashes.
365
- if (sourcePos !== lineStart + prefix.length) {
374
+ // Slow path: hashes may be at the *visible* start of the line but inside
375
+ // inline formatting markers (e.g. source is `**##text**`). Use the cursor
376
+ // map to skip source-only spans and find the first visible character.
377
+ const lineStartCursorInfo = map.sourceToCursor(lineStart, "forward");
378
+ const visibleLineStart = map.cursorToSource(lineStartCursorInfo.cursorOffset, "forward");
379
+ const visiblePrefix = source.slice(visibleLineStart, sourcePos);
380
+ if (!visiblePrefix ||
381
+ visiblePrefix.length > 3 ||
382
+ !/^[#]+$/.test(visiblePrefix)) {
366
383
  return null;
367
384
  }
368
- const nextSource = source.slice(0, sourcePos) + " " + source.slice(sourcePos);
369
- const lineStartCursor = cursorPos - prefix.length;
385
+ // Restructure: move "## " before the inline markers so the block parser
386
+ // sees the heading prefix at the true line start.
387
+ const headingMarker = visiblePrefix + " ";
388
+ const inlinePrefix = source.slice(lineStart, visibleLineStart);
389
+ const afterHashes = source.slice(sourcePos);
390
+ const nextSource = source.slice(0, lineStart) + headingMarker + inlinePrefix + afterHashes;
391
+ const next = runtime.createState(nextSource);
392
+ const caretSource = lineStart + headingMarker.length + inlinePrefix.length;
393
+ const caretCursor = next.map.sourceToCursor(caretSource, "forward");
370
394
  return {
371
395
  source: nextSource,
372
396
  selection: {
373
- start: lineStartCursor,
374
- end: lineStartCursor,
375
- affinity: "forward",
397
+ start: caretCursor.cursorOffset,
398
+ end: caretCursor.cursorOffset,
399
+ affinity: caretCursor.affinity,
376
400
  },
377
401
  };
378
402
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blankdotpage/cake",
3
- "version": "0.1.79-rc.4",
3
+ "version": "0.1.79-rc.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",