@blankdotpage/cake 0.1.72 → 0.1.74
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":"list.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/list/list.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/list/list.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AA0qC5B,+CAA+C;AAC/C,MAAM,MAAM,uBAAuB,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAErE,iDAAiD;AACjD,MAAM,MAAM,yBAAyB,GAAG;IAAE,IAAI,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAEzE,kCAAkC;AAClC,MAAM,MAAM,WAAW,GAAG,uBAAuB,GAAG,yBAAyB,CAAC;AAE9E,eAAO,MAAM,sBAAsB,EAAE,aA8HpC,CAAC"}
|
|
@@ -585,19 +585,23 @@ function handleToggleList(state, isBullet) {
|
|
|
585
585
|
if (selection.start === selection.end && startLine === endLine && lines[startLine] === "") {
|
|
586
586
|
const marker = isBullet ? "- " : "1. ";
|
|
587
587
|
newLines[startLine] = marker;
|
|
588
|
-
// Calculate new
|
|
589
|
-
let
|
|
588
|
+
// Calculate new source position after the inserted marker.
|
|
589
|
+
let newCursorSourcePos = 0;
|
|
590
590
|
for (let i = 0; i < startLine; i++) {
|
|
591
|
-
|
|
591
|
+
newCursorSourcePos += lines[i].length + 1; // +1 for newline
|
|
592
592
|
}
|
|
593
|
-
|
|
593
|
+
newCursorSourcePos += marker.length;
|
|
594
594
|
const newSource = newLines.join("\n");
|
|
595
|
+
const next = runtime.createState(newSource);
|
|
596
|
+
// Bias backward so the caret stays on the newly created empty list line
|
|
597
|
+
// instead of normalizing to the following line at the shared boundary.
|
|
598
|
+
const nextCursor = next.map.sourceToCursor(newCursorSourcePos, "backward");
|
|
595
599
|
return {
|
|
596
600
|
source: newSource,
|
|
597
601
|
selection: {
|
|
598
|
-
start:
|
|
599
|
-
end:
|
|
600
|
-
affinity:
|
|
602
|
+
start: nextCursor.cursorOffset,
|
|
603
|
+
end: nextCursor.cursorOffset,
|
|
604
|
+
affinity: nextCursor.affinity,
|
|
601
605
|
},
|
|
602
606
|
};
|
|
603
607
|
}
|
|
@@ -663,6 +667,34 @@ function handleToggleList(state, isBullet) {
|
|
|
663
667
|
newSource.slice(block.endOffset);
|
|
664
668
|
}
|
|
665
669
|
}
|
|
670
|
+
if (selection.start === selection.end && startLine === endLine) {
|
|
671
|
+
const originalCursorSource = map.cursorToSource(selection.start, selection.affinity ?? "forward");
|
|
672
|
+
const originalLineInfo = getLineInfo(source, originalCursorSource);
|
|
673
|
+
const originalLine = lines[startLine] ?? "";
|
|
674
|
+
const nextLines = getSourceLines(newSource);
|
|
675
|
+
const nextLine = nextLines[startLine] ?? "";
|
|
676
|
+
const originalPrefixLength = getListPrefixLength(originalLine) ?? 0;
|
|
677
|
+
const nextPrefixLength = getListPrefixLength(nextLine) ?? 0;
|
|
678
|
+
const originalContentLength = Math.max(0, originalLine.length - originalPrefixLength);
|
|
679
|
+
const nextContentLength = Math.max(0, nextLine.length - nextPrefixLength);
|
|
680
|
+
const cursorOffsetInContent = Math.max(0, Math.min(originalContentLength, originalLineInfo.offsetInLine - originalPrefixLength));
|
|
681
|
+
const nextOffsetInContent = Math.min(nextContentLength, cursorOffsetInContent);
|
|
682
|
+
let nextCursorSourceOffset = 0;
|
|
683
|
+
for (let i = 0; i < startLine; i += 1) {
|
|
684
|
+
nextCursorSourceOffset += (nextLines[i] ?? "").length + 1;
|
|
685
|
+
}
|
|
686
|
+
nextCursorSourceOffset += nextPrefixLength + nextOffsetInContent;
|
|
687
|
+
const next = runtime.createState(newSource);
|
|
688
|
+
const nextCursor = next.map.sourceToCursor(nextCursorSourceOffset, "forward");
|
|
689
|
+
return {
|
|
690
|
+
source: newSource,
|
|
691
|
+
selection: {
|
|
692
|
+
start: nextCursor.cursorOffset,
|
|
693
|
+
end: nextCursor.cursorOffset,
|
|
694
|
+
affinity: nextCursor.affinity,
|
|
695
|
+
},
|
|
696
|
+
};
|
|
697
|
+
}
|
|
666
698
|
// Calculate new selection to preserve the selected range
|
|
667
699
|
const newSourceLines = getSourceLines(newSource);
|
|
668
700
|
let newStartSourceOffset = 0;
|