@blankdotpage/cake 0.1.17 → 0.1.19
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;AAqiC5B,+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,aA0HpC,CAAC"}
|
|
@@ -80,9 +80,13 @@ function applyListTransform(source, cursorLineIndex, transform, computeSelection
|
|
|
80
80
|
/**
|
|
81
81
|
* Get line indices for a selection range
|
|
82
82
|
*/
|
|
83
|
-
function getSelectionLineRange(source, selection) {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
83
|
+
function getSelectionLineRange(source, selection, map) {
|
|
84
|
+
const startCursor = Math.min(selection.start, selection.end);
|
|
85
|
+
const endCursor = Math.max(selection.start, selection.end);
|
|
86
|
+
const startSource = map.cursorToSource(startCursor, "backward");
|
|
87
|
+
const endSource = map.cursorToSource(Math.max(startCursor, endCursor - 1), "forward");
|
|
88
|
+
const startInfo = getLineInfo(source, startSource);
|
|
89
|
+
const endInfo = getLineInfo(source, endSource);
|
|
86
90
|
return { startLine: startInfo.lineIndex, endLine: endInfo.lineIndex };
|
|
87
91
|
}
|
|
88
92
|
function handleInsertLineBreak(state) {
|
|
@@ -406,8 +410,8 @@ function handleDeleteForward(state) {
|
|
|
406
410
|
return null;
|
|
407
411
|
}
|
|
408
412
|
function handleIndent(state) {
|
|
409
|
-
const { source, selection } = state;
|
|
410
|
-
const { startLine, endLine } = getSelectionLineRange(source, selection);
|
|
413
|
+
const { source, selection, map } = state;
|
|
414
|
+
const { startLine, endLine } = getSelectionLineRange(source, selection, map);
|
|
411
415
|
const lines = getSourceLines(source);
|
|
412
416
|
// Check if any line in selection is a list line
|
|
413
417
|
let hasListLine = false;
|
|
@@ -447,8 +451,8 @@ function handleIndent(state) {
|
|
|
447
451
|
};
|
|
448
452
|
}
|
|
449
453
|
function handleOutdent(state) {
|
|
450
|
-
const { source, selection } = state;
|
|
451
|
-
const { startLine, endLine } = getSelectionLineRange(source, selection);
|
|
454
|
+
const { source, selection, map } = state;
|
|
455
|
+
const { startLine, endLine } = getSelectionLineRange(source, selection, map);
|
|
452
456
|
const lines = getSourceLines(source);
|
|
453
457
|
// Check if any line in selection is a list line
|
|
454
458
|
let hasListLine = false;
|
|
@@ -532,8 +536,8 @@ function handleOutdent(state) {
|
|
|
532
536
|
};
|
|
533
537
|
}
|
|
534
538
|
function handleToggleList(state, isBullet) {
|
|
535
|
-
const { source, selection } = state;
|
|
536
|
-
const { startLine, endLine } = getSelectionLineRange(source, selection);
|
|
539
|
+
const { source, selection, map } = state;
|
|
540
|
+
const { startLine, endLine } = getSelectionLineRange(source, selection, map);
|
|
537
541
|
const lines = getSourceLines(source);
|
|
538
542
|
const bulletPattern = /^(\s*)([-*+])( )/;
|
|
539
543
|
const numberedPattern = /^(\s*)(\d+)\.( )/;
|
|
@@ -631,7 +635,7 @@ function handleToggleList(state, isBullet) {
|
|
|
631
635
|
};
|
|
632
636
|
}
|
|
633
637
|
function handleInsertListMarkerWithSelection(state, marker) {
|
|
634
|
-
const { source, selection } = state;
|
|
638
|
+
const { source, selection, map } = state;
|
|
635
639
|
// Only handle when there's a selection
|
|
636
640
|
if (selection.start === selection.end) {
|
|
637
641
|
return null;
|
|
@@ -640,7 +644,7 @@ function handleInsertListMarkerWithSelection(state, marker) {
|
|
|
640
644
|
if (marker !== "-" && marker !== "*" && marker !== "+") {
|
|
641
645
|
return null;
|
|
642
646
|
}
|
|
643
|
-
const { startLine, endLine } = getSelectionLineRange(source, selection);
|
|
647
|
+
const { startLine, endLine } = getSelectionLineRange(source, selection, map);
|
|
644
648
|
const lines = getSourceLines(source);
|
|
645
649
|
// Only convert to list if selection covers full lines
|
|
646
650
|
// Calculate line boundaries
|
|
@@ -654,9 +658,11 @@ function handleInsertListMarkerWithSelection(state, marker) {
|
|
|
654
658
|
}
|
|
655
659
|
const selStart = Math.min(selection.start, selection.end);
|
|
656
660
|
const selEnd = Math.max(selection.start, selection.end);
|
|
661
|
+
const selStartSource = map.cursorToSource(selStart, "backward");
|
|
662
|
+
const selEndSource = map.cursorToSource(selEnd, "forward");
|
|
657
663
|
// Check if selection starts at line start and ends at line end
|
|
658
|
-
const startsAtLineStart =
|
|
659
|
-
const endsAtLineEnd =
|
|
664
|
+
const startsAtLineStart = selStartSource === startLineOffset;
|
|
665
|
+
const endsAtLineEnd = selEndSource === endLineOffset;
|
|
660
666
|
// For partial selections, don't convert to list - let default behavior handle it
|
|
661
667
|
if (!startsAtLineStart || !endsAtLineEnd) {
|
|
662
668
|
return null;
|
|
@@ -696,12 +702,12 @@ function handleInsertListMarkerWithSelection(state, marker) {
|
|
|
696
702
|
};
|
|
697
703
|
}
|
|
698
704
|
function handleMarkerSwitch(state, insertedChar) {
|
|
699
|
-
const { source, selection } = state;
|
|
705
|
+
const { source, selection, map } = state;
|
|
700
706
|
// If there's a selection, try to convert lines to list
|
|
701
707
|
if (selection.start !== selection.end) {
|
|
702
708
|
// For multi-line selections, use toggle-bullet-list behavior (like Cmd+Shift+8)
|
|
703
709
|
// which doesn't require exact line boundary alignment
|
|
704
|
-
const { startLine, endLine } = getSelectionLineRange(source, selection);
|
|
710
|
+
const { startLine, endLine } = getSelectionLineRange(source, selection, map);
|
|
705
711
|
if (startLine !== endLine &&
|
|
706
712
|
(insertedChar === "-" || insertedChar === "*" || insertedChar === "+")) {
|
|
707
713
|
return { type: "toggle-bullet-list" };
|
|
@@ -712,7 +718,8 @@ function handleMarkerSwitch(state, insertedChar) {
|
|
|
712
718
|
return null;
|
|
713
719
|
}
|
|
714
720
|
const cursorPos = selection.start;
|
|
715
|
-
const
|
|
721
|
+
const cursorSourcePos = map.cursorToSource(cursorPos, selection.affinity ?? "forward");
|
|
722
|
+
const lineInfo = getLineInfo(source, cursorSourcePos);
|
|
716
723
|
const listMatch = matchListLine(lineInfo.line);
|
|
717
724
|
if (!listMatch || listMatch.number !== null) {
|
|
718
725
|
return null;
|
|
@@ -28,6 +28,21 @@ export interface CakeEditorRef {
|
|
|
28
28
|
blur: () => void;
|
|
29
29
|
hasFocus: () => boolean;
|
|
30
30
|
selectAll: () => void;
|
|
31
|
+
getText: () => string;
|
|
32
|
+
getTextSelection: () => {
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
};
|
|
36
|
+
setTextSelection: (selection: {
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
}) => void;
|
|
40
|
+
getTextBeforeCursor: (maxChars?: number) => string;
|
|
41
|
+
getTextAroundCursor: (before: number, after: number) => {
|
|
42
|
+
before: string;
|
|
43
|
+
after: string;
|
|
44
|
+
};
|
|
45
|
+
replaceTextBeforeCursor: (chars: number, replacement: string) => void;
|
|
31
46
|
/**
|
|
32
47
|
* Execute a semantic edit command.
|
|
33
48
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cake/react/index.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EAEb,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAczB,MAAM,MAAM,mBAAmB,GA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AAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAChD,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1D,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD;AAED,eAAO,MAAM,UAAU,kHAmOtB,CAAC"}
|
package/dist/cake/react/index.js
CHANGED
|
@@ -156,6 +156,19 @@ export const CakeEditor = forwardRef(function CakeEditor(props, outerRef) {
|
|
|
156
156
|
}
|
|
157
157
|
return { start: selection.start, end: selection.end };
|
|
158
158
|
},
|
|
159
|
+
getText: () => engineRef.current?.getText() ?? "",
|
|
160
|
+
getTextSelection: () => engineRef.current?.getTextSelection() ?? { start: 0, end: 0 },
|
|
161
|
+
setTextSelection: (selection) => {
|
|
162
|
+
engineRef.current?.setTextSelection(selection);
|
|
163
|
+
},
|
|
164
|
+
getTextBeforeCursor: (maxChars) => engineRef.current?.getTextBeforeCursor(maxChars) ?? "",
|
|
165
|
+
getTextAroundCursor: (before, after) => engineRef.current?.getTextAroundCursor(before, after) ?? {
|
|
166
|
+
before: "",
|
|
167
|
+
after: "",
|
|
168
|
+
},
|
|
169
|
+
replaceTextBeforeCursor: (chars, replacement) => {
|
|
170
|
+
engineRef.current?.replaceTextBeforeCursor(chars, replacement);
|
|
171
|
+
},
|
|
159
172
|
getCursorLength: () => engineRef.current?.getCursorLength() ?? 0,
|
|
160
173
|
insertText: (text) => {
|
|
161
174
|
engineRef.current?.insertText(text);
|