Fix extractRegion() matching region names that are substrings of others
The `extractRegion()` function in `sync-snippets.ts` used `indexOf()` to find region markers like `//#region persistData`. This caused incorrect matching when one region name was a prefix of another—searching for `persistData` would match `//#region persistDataServer` first if it appeared earlier in the file. The fix detects the file's line ending style and appends it to region markers, ensuring exact matches: - `//#region persistData\n` no longer matches `//#region persistDataServer\n` This corrects `docs/patterns.md` where the `persistData` code fence was incorrectly showing server-side code instead of client-side localStorage helpers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f90e0bd090
commit
1215bf33c3
1 changed files with 42 additions and 9 deletions
|
|
@ -254,8 +254,9 @@ function extractRegion(
|
|||
);
|
||||
}
|
||||
|
||||
const regionStart = `//#region ${regionName}`;
|
||||
const regionEnd = `//#endregion ${regionName}`;
|
||||
const lineEnding = exampleContent.includes("\r\n") ? "\r\n" : "\n";
|
||||
const regionStart = `//#region ${regionName}${lineEnding}`;
|
||||
const regionEnd = `//#endregion ${regionName}${lineEnding}`;
|
||||
|
||||
const startIndex = exampleContent.indexOf(regionStart);
|
||||
if (startIndex === -1) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue