Elffuss BraidHub

kikocis/continue public

add a discriminate union
Changeset9da59f739c22a0d74ac4ee6ef2101c7a5031a42be7be4ddc0b4e67b48821b9fe
AuthorJacob Kim <jacob@continue.dev> · 2025-07-02 15:37 -07:00
CommitterJacob Kim <jacob@continue.dev> · 2025-07-02 15:37 -07:00
Parentsbf84192738a3

Browse the files at this changeset

1 file changed

modified core/nextEdit/diff/diff.ts +18 −11
@@ -125,10 +125,15 @@
125125 oldEditRange: string,
126126 newEditRange: string,
127127 cursorPosition: { line: number; character: number },
128-): {
129- isFim: boolean;
130- fimText: string;
131-} {
128+):
129+ | {
130+ isFim: true;
131+ fimText: string;
132+ }
133+ | {
134+ isFim: false;
135+ fimText: null;
136+ } {
132137 // Find the common prefix.
133138 let prefixLength = 0;
134139 while (
@@ -177,11 +182,13 @@
177182 // Check if the old text is completely preserved (no deletion).
178183 const noTextDeleted = suffixStartInOld - prefixLength <= 0;
179184
180- // Extract the content between prefix and suffix in the new string.
181- const fimText = newEditRange.substring(prefixLength, suffixStartInNew);
182-
183- return {
184- isFim: cursorBetweenPrefixAndSuffix && noTextDeleted,
185- fimText,
186- };
185+ const isFim = cursorBetweenPrefixAndSuffix && noTextDeleted;
186+
187+ if (isFim) {
188+ // Extract the content between prefix and suffix in the new string.
189+ const fimText = newEditRange.substring(prefixLength, suffixStartInNew);
190+ return { isFim, fimText };
191+ } else {
192+ return { isFim, fimText: null };
193+ }
187194 }