Changesets · Branches · Tags · Compare
| Changeset | 62c4c3e6fad7c0bd0a569ab2a63c0c793174d6831bbcd50f2c5e1d9a448b159f |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-27 08:16 -07:00 |
| Committer | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-27 08:16 -07:00 |
| Parents | bdaaa3ef81c4 |
1 file changed
modified core/edit/searchAndReplace/findSearchMatch.ts +12 −12
| @@ -11,45 +11,45 @@ | ||
| 11 | 11 | /** |
| 12 | 12 | * Find the exact match position for search content in file content. |
| 13 | 13 | * Uses simple exact matching with trimmed newlines for MVP. |
| 14 | - * | |
| 14 | + * | |
| 15 | 15 | * Matching Strategy: |
| 16 | 16 | * 1. If search content is empty, matches at the beginning of file (position 0) |
| 17 | 17 | * 2. Try exact string match first |
| 18 | 18 | * 3. Fallback to trimmed content match if exact match fails |
| 19 | - * | |
| 19 | + * | |
| 20 | 20 | * @param fileContent - The complete content of the file to search in |
| 21 | 21 | * @param searchContent - The content to search for |
| 22 | 22 | * @returns Match result with character positions, or null if no match found |
| 23 | 23 | */ |
| 24 | 24 | export function findSearchMatch( |
| 25 | - fileContent: string, | |
| 26 | - searchContent: string | |
| 25 | + fileContent: string, | |
| 26 | + searchContent: string, | |
| 27 | 27 | ): SearchMatchResult | null { |
| 28 | 28 | // Strip leading/trailing newlines for basic matching strategy |
| 29 | 29 | const trimmedSearchContent = searchContent.trim(); |
| 30 | - | |
| 31 | - if (trimmedSearchContent === '') { | |
| 30 | + | |
| 31 | + if (trimmedSearchContent === "") { | |
| 32 | 32 | // Empty search content matches the beginning of the file |
| 33 | 33 | return { startIndex: 0, endIndex: 0 }; |
| 34 | 34 | } |
| 35 | - | |
| 35 | + | |
| 36 | 36 | // Try exact match first |
| 37 | 37 | const exactIndex = fileContent.indexOf(searchContent); |
| 38 | 38 | if (exactIndex !== -1) { |
| 39 | 39 | return { |
| 40 | 40 | startIndex: exactIndex, |
| 41 | - endIndex: exactIndex + searchContent.length | |
| 41 | + endIndex: exactIndex + searchContent.length, | |
| 42 | 42 | }; |
| 43 | 43 | } |
| 44 | - | |
| 44 | + | |
| 45 | 45 | // Fallback: try trimmed content match |
| 46 | 46 | const trimmedIndex = fileContent.indexOf(trimmedSearchContent); |
| 47 | 47 | if (trimmedIndex !== -1) { |
| 48 | 48 | return { |
| 49 | 49 | startIndex: trimmedIndex, |
| 50 | - endIndex: trimmedIndex + trimmedSearchContent.length | |
| 50 | + endIndex: trimmedIndex + trimmedSearchContent.length, | |
| 51 | 51 | }; |
| 52 | 52 | } |
| 53 | - | |
| 53 | + | |
| 54 | 54 | return null; |
| 55 | -} | |
| No newline at the end of the file | ||
| 55 | +} |