Changesets · Branches · Tags · Compare
| Changeset | 7402671ebc64ee280a8892fefa414a7a2508b8b537461774c83cc66f4808554b |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-07-15 14:46 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-15 14:46 -07:00 |
| Parents | 0f17595b5c72, f242d509007a |
4 files changed
modified core/tools/definitions/searchAndReplaceInFile.ts +15 −10
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | |
| 4 | 4 | export interface SearchAndReplaceInFileArgs { |
| 5 | 5 | filepath: string; |
| 6 | - diff: string; | |
| 6 | + diffs: string[]; | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | // Currently unsupported and filtered out in `gui/src/redux/slices/sessionSlice.ts` |
| @@ -25,19 +25,22 @@ | ||
| 25 | 25 | isInstant: false, |
| 26 | 26 | function: { |
| 27 | 27 | name: BuiltInToolNames.SearchAndReplaceInFile, |
| 28 | - description: `Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file. ${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`, | |
| 28 | + description: `Request to replace sections of content in an existing file using multiple SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file. ${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`, | |
| 29 | 29 | parameters: { |
| 30 | 30 | type: "object", |
| 31 | - required: ["filepath", "diff"], | |
| 31 | + required: ["filepath", "diffs"], | |
| 32 | 32 | properties: { |
| 33 | 33 | filepath: { |
| 34 | 34 | type: "string", |
| 35 | 35 | description: |
| 36 | 36 | "The path of the file to modify, relative to the root of the workspace.", |
| 37 | 37 | }, |
| 38 | - diff: { | |
| 39 | - type: "string", | |
| 40 | - description: `One or more SEARCH/REPLACE blocks following this exact format: | |
| 38 | + diffs: { | |
| 39 | + type: "array", | |
| 40 | + items: { | |
| 41 | + type: "string", | |
| 42 | + }, | |
| 43 | + description: `An array of strings, each containing one or more SEARCH/REPLACE blocks following this exact format: | |
| 41 | 44 | \`\`\` |
| 42 | 45 | ------- SEARCH |
| 43 | 46 | [exact content to find] |
| @@ -54,16 +57,17 @@ | ||
| 54 | 57 | * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes. |
| 55 | 58 | * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change. |
| 56 | 59 | * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file. |
| 57 | -3. Keep SEARCH/REPLACE blocks concise: | |
| 60 | +3. **Order matters**: DIFFs in the array should be ordered from top to bottom of the file to ensure correct application. | |
| 61 | +4. Keep SEARCH/REPLACE blocks concise: | |
| 58 | 62 | * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file. |
| 59 | 63 | * Include just the changing lines, and a few surrounding lines if needed for uniqueness. |
| 60 | 64 | * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks. |
| 61 | 65 | * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures. |
| 62 | -4. Splitting up tool calls: | |
| 66 | +5. Splitting up tool calls: | |
| 63 | 67 | * When making multiple closely related edits to the same file, you should try to use multiple SEARCH/REPLACE blocks in a single tool call, rather than making multiple separate tool calls |
| 64 | 68 | * If you need to make follow up edits or group your work into logical segments, it is okay to perform additional tool calls |
| 65 | 69 | * DO NOT make back-to-back tool calls. Instead interleave with brief explanation of what each will do. For example, instead of [explanation, tool call, tool call] you should do [explanation, tool call, explanation, tool call] |
| 66 | -5. Special operations: | |
| 70 | +6. Special operations: | |
| 67 | 71 | * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location) |
| 68 | 72 | * To delete code: Use empty REPLACE section |
| 69 | 73 | |
| @@ -81,7 +85,8 @@ | ||
| 81 | 85 | [new content to replace with] |
| 82 | 86 | +++++++ REPLACE |
| 83 | 87 | \`\`\` |
| 84 | -`, | |
| 88 | + | |
| 89 | +Each string in the diffs array can contain multiple SEARCH/REPLACE blocks, and all will be applied sequentially in the order they appear.`, | |
| 85 | 90 | }, |
| 86 | 91 | }, |
| 87 | 92 | }, |
modified gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx +1 −1
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | return ( |
| 37 | 37 | <EditFile |
| 38 | 38 | relativeFilePath={args.filepath ?? ""} |
| 39 | - changes={args.diff ?? ""} | |
| 39 | + changes={args.diffs ? args.diffs.join("\n\n---\n\n") : ""} | |
| 40 | 40 | toolCallId={toolCall.id} |
| 41 | 41 | historyIndex={historyIndex} |
| 42 | 42 | /> |
modified gui/src/util/clientTools/searchReplaceImpl.test.ts +205 −15
| @@ -53,24 +53,61 @@ | ||
| 53 | 53 | |
| 54 | 54 | await expect( |
| 55 | 55 | searchReplaceToolImpl( |
| 56 | - { filepath: "nonexistent.txt", diff: "some diff" }, | |
| 56 | + { filepath: "nonexistent.txt", diffs: ["some diff"] }, | |
| 57 | 57 | "tool-call-id", |
| 58 | 58 | mockExtras, |
| 59 | 59 | ), |
| 60 | 60 | ).rejects.toThrow("File nonexistent.txt does not exist"); |
| 61 | 61 | }); |
| 62 | 62 | |
| 63 | - it("should throw error when no search/replace blocks found", async () => { | |
| 63 | + it("should throw error when no search/replace blocks found in first diff", async () => { | |
| 64 | 64 | mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.txt"); |
| 65 | 65 | mockParseAllSearchReplaceBlocks.mockReturnValue([]); |
| 66 | 66 | |
| 67 | 67 | await expect( |
| 68 | 68 | searchReplaceToolImpl( |
| 69 | - { filepath: "test.txt", diff: "invalid diff content" }, | |
| 69 | + { filepath: "test.txt", diffs: ["invalid diff content"] }, | |
| 70 | 70 | "tool-call-id", |
| 71 | 71 | mockExtras, |
| 72 | 72 | ), |
| 73 | - ).rejects.toThrow("No complete search/replace blocks found"); | |
| 73 | + ).rejects.toThrow("No complete search/replace blocks found in diff 1"); | |
| 74 | + }); | |
| 75 | + | |
| 76 | + it("should throw error when no search/replace blocks found in second diff", async () => { | |
| 77 | + mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.txt"); | |
| 78 | + mockParseAllSearchReplaceBlocks | |
| 79 | + .mockReturnValueOnce([ | |
| 80 | + { | |
| 81 | + isComplete: true, | |
| 82 | + searchContent: "valid content", | |
| 83 | + replaceContent: "replacement", | |
| 84 | + }, | |
| 85 | + ]) | |
| 86 | + .mockReturnValueOnce([]); | |
| 87 | + | |
| 88 | + await expect( | |
| 89 | + searchReplaceToolImpl( | |
| 90 | + { | |
| 91 | + filepath: "test.txt", | |
| 92 | + diffs: ["valid diff", "invalid diff content"], | |
| 93 | + }, | |
| 94 | + "tool-call-id", | |
| 95 | + mockExtras, | |
| 96 | + ), | |
| 97 | + ).rejects.toThrow("No complete search/replace blocks found in diff 2"); | |
| 98 | + }); | |
| 99 | + | |
| 100 | + it("should throw error when all diffs are empty", async () => { | |
| 101 | + mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.txt"); | |
| 102 | + mockParseAllSearchReplaceBlocks.mockReturnValue([]); | |
| 103 | + | |
| 104 | + await expect( | |
| 105 | + searchReplaceToolImpl( | |
| 106 | + { filepath: "test.txt", diffs: [] }, | |
| 107 | + "tool-call-id", | |
| 108 | + mockExtras, | |
| 109 | + ), | |
| 110 | + ).rejects.toThrow("No complete search/replace blocks found in any diffs"); | |
| 74 | 111 | }); |
| 75 | 112 | }); |
| 76 | 113 | |
| @@ -110,7 +147,65 @@ | ||
| 110 | 147 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 111 | 148 | |
| 112 | 149 | const result = await searchReplaceToolImpl( |
| 113 | - { filepath: "test.js", diff: "mock diff content" }, | |
| 150 | + { filepath: "test.js", diffs: ["mock diff content"] }, | |
| 151 | + "tool-call-id", | |
| 152 | + mockExtras, | |
| 153 | + ); | |
| 154 | + | |
| 155 | + // Verify the result | |
| 156 | + expect(result).toEqual({ | |
| 157 | + respondImmediately: false, | |
| 158 | + output: undefined, | |
| 159 | + }); | |
| 160 | + | |
| 161 | + // Verify applyToFile was called with correct parameters | |
| 162 | + expect(mockIdeMessenger.request).toHaveBeenCalledWith("applyToFile", { | |
| 163 | + text: expectedFinalContent, | |
| 164 | + streamId: "test-stream-id", | |
| 165 | + filepath: "/resolved/path/test.js", | |
| 166 | + toolCallId: "tool-call-id", | |
| 167 | + isSearchAndReplace: true, | |
| 168 | + }); | |
| 169 | + }); | |
| 170 | + }); | |
| 171 | + | |
| 172 | + describe("single diff scenarios", () => { | |
| 173 | + it("should successfully apply single diff with single search/replace block", async () => { | |
| 174 | + const originalContent = `function hello() { | |
| 175 | + console.log("Hello"); | |
| 176 | + return "world"; | |
| 177 | +}`; | |
| 178 | + | |
| 179 | + const expectedFinalContent = `function hello() { | |
| 180 | + console.log("Hi there!"); | |
| 181 | + return "world"; | |
| 182 | +}`; | |
| 183 | + | |
| 184 | + // Setup mocks | |
| 185 | + mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.js"); | |
| 186 | + mockParseAllSearchReplaceBlocks.mockReturnValue([ | |
| 187 | + { | |
| 188 | + isComplete: true, | |
| 189 | + searchContent: 'console.log("Hello");', | |
| 190 | + replaceContent: 'console.log("Hi there!");', | |
| 191 | + }, | |
| 192 | + ]); | |
| 193 | + mockIdeMessenger.ide.readFile.mockResolvedValue(originalContent); | |
| 194 | + | |
| 195 | + // Calculate correct positions for 'console.log("Hello");' in the original content | |
| 196 | + const searchText = 'console.log("Hello");'; | |
| 197 | + const startIndex = originalContent.indexOf(searchText); | |
| 198 | + const endIndex = startIndex + searchText.length; | |
| 199 | + | |
| 200 | + mockFindSearchMatch.mockReturnValue({ | |
| 201 | + startIndex, | |
| 202 | + endIndex, | |
| 203 | + strategyName: "exactMatch", | |
| 204 | + }); | |
| 205 | + mockIdeMessenger.request.mockResolvedValue({ status: "success" }); | |
| 206 | + | |
| 207 | + const result = await searchReplaceToolImpl( | |
| 208 | + { filepath: "test.js", diffs: ["mock diff content"] }, | |
| 114 | 209 | "tool-call-id", |
| 115 | 210 | mockExtras, |
| 116 | 211 | ); |
| @@ -191,7 +286,7 @@ | ||
| 191 | 286 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 192 | 287 | |
| 193 | 288 | const result = await searchReplaceToolImpl( |
| 194 | - { filepath: "test.js", diff: "mock diff content" }, | |
| 289 | + { filepath: "test.js", diffs: ["mock diff content"] }, | |
| 195 | 290 | "tool-call-id", |
| 196 | 291 | mockExtras, |
| 197 | 292 | ); |
| @@ -225,6 +320,101 @@ | ||
| 225 | 320 | }); |
| 226 | 321 | }); |
| 227 | 322 | |
| 323 | + describe("multiple diff scenarios", () => { | |
| 324 | + it("should successfully apply multiple diffs each with single search/replace block", async () => { | |
| 325 | + const originalContent = `const a = 1; | |
| 326 | +const b = 2; | |
| 327 | +const c = 3;`; | |
| 328 | + | |
| 329 | + const expectedFinalContent = `const a = 100; | |
| 330 | +const b = 200; | |
| 331 | +const c = 3;`; | |
| 332 | + | |
| 333 | + // Setup mocks - each diff returns one block | |
| 334 | + mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.js"); | |
| 335 | + mockParseAllSearchReplaceBlocks | |
| 336 | + .mockReturnValueOnce([ | |
| 337 | + { | |
| 338 | + isComplete: true, | |
| 339 | + searchContent: "const a = 1;", | |
| 340 | + replaceContent: "const a = 100;", | |
| 341 | + }, | |
| 342 | + ]) | |
| 343 | + .mockReturnValueOnce([ | |
| 344 | + { | |
| 345 | + isComplete: true, | |
| 346 | + searchContent: "const b = 2;", | |
| 347 | + replaceContent: "const b = 200;", | |
| 348 | + }, | |
| 349 | + ]); | |
| 350 | + mockIdeMessenger.ide.readFile.mockResolvedValue(originalContent); | |
| 351 | + | |
| 352 | + // Calculate positions for sequential replacements | |
| 353 | + const firstSearchText = "const a = 1;"; | |
| 354 | + const secondSearchText = "const b = 2;"; | |
| 355 | + | |
| 356 | + const firstStartIndex = originalContent.indexOf(firstSearchText); | |
| 357 | + const firstEndIndex = firstStartIndex + firstSearchText.length; | |
| 358 | + | |
| 359 | + // After first replacement: "const a = 100;\nconst b = 2;\nconst c = 3;" | |
| 360 | + const contentAfterFirstReplacement = | |
| 361 | + originalContent.substring(0, firstStartIndex) + | |
| 362 | + "const a = 100;" + | |
| 363 | + originalContent.substring(firstEndIndex); | |
| 364 | + | |
| 365 | + const secondStartIndex = | |
| 366 | + contentAfterFirstReplacement.indexOf(secondSearchText); | |
| 367 | + const secondEndIndex = secondStartIndex + secondSearchText.length; | |
| 368 | + | |
| 369 | + // Mock sequential search matches | |
| 370 | + mockFindSearchMatch | |
| 371 | + .mockReturnValueOnce({ | |
| 372 | + startIndex: firstStartIndex, | |
| 373 | + endIndex: firstEndIndex, | |
| 374 | + strategyName: "exactMatch", | |
| 375 | + }) | |
| 376 | + .mockReturnValueOnce({ | |
| 377 | + startIndex: secondStartIndex, | |
| 378 | + endIndex: secondEndIndex, | |
| 379 | + strategyName: "exactMatch", | |
| 380 | + }); | |
| 381 | + | |
| 382 | + mockIdeMessenger.request.mockResolvedValue({ status: "success" }); | |
| 383 | + | |
| 384 | + const result = await searchReplaceToolImpl( | |
| 385 | + { filepath: "test.js", diffs: ["first diff", "second diff"] }, | |
| 386 | + "tool-call-id", | |
| 387 | + mockExtras, | |
| 388 | + ); | |
| 389 | + | |
| 390 | + // Verify the result | |
| 391 | + expect(result).toEqual({ | |
| 392 | + respondImmediately: false, | |
| 393 | + output: undefined, | |
| 394 | + }); | |
| 395 | + | |
| 396 | + // Verify parseAllSearchReplaceBlocks was called for each diff | |
| 397 | + expect(mockParseAllSearchReplaceBlocks).toHaveBeenCalledTimes(2); | |
| 398 | + expect(mockParseAllSearchReplaceBlocks).toHaveBeenNthCalledWith( | |
| 399 | + 1, | |
| 400 | + "first diff", | |
| 401 | + ); | |
| 402 | + expect(mockParseAllSearchReplaceBlocks).toHaveBeenNthCalledWith( | |
| 403 | + 2, | |
| 404 | + "second diff", | |
| 405 | + ); | |
| 406 | + | |
| 407 | + // Verify final applyToFile call | |
| 408 | + expect(mockIdeMessenger.request).toHaveBeenCalledWith("applyToFile", { | |
| 409 | + text: expectedFinalContent, | |
| 410 | + streamId: "test-stream-id", | |
| 411 | + filepath: "/resolved/path/test.js", | |
| 412 | + toolCallId: "tool-call-id", | |
| 413 | + isSearchAndReplace: true, | |
| 414 | + }); | |
| 415 | + }); | |
| 416 | + }); | |
| 417 | + | |
| 228 | 418 | describe("deletion scenarios", () => { |
| 229 | 419 | it("should handle empty replacement (deletion)", async () => { |
| 230 | 420 | const originalContent = `keep this |
| @@ -253,7 +443,7 @@ | ||
| 253 | 443 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 254 | 444 | |
| 255 | 445 | const result = await searchReplaceToolImpl( |
| 256 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 446 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 257 | 447 | "tool-call-id", |
| 258 | 448 | mockExtras, |
| 259 | 449 | ); |
| @@ -293,7 +483,7 @@ | ||
| 293 | 483 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 294 | 484 | |
| 295 | 485 | await searchReplaceToolImpl( |
| 296 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 486 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 297 | 487 | "tool-call-id", |
| 298 | 488 | mockExtras, |
| 299 | 489 | ); |
| @@ -323,7 +513,7 @@ | ||
| 323 | 513 | |
| 324 | 514 | await expect( |
| 325 | 515 | searchReplaceToolImpl( |
| 326 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 516 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 327 | 517 | "tool-call-id", |
| 328 | 518 | mockExtras, |
| 329 | 519 | ), |
| @@ -361,7 +551,7 @@ | ||
| 361 | 551 | |
| 362 | 552 | await expect( |
| 363 | 553 | searchReplaceToolImpl( |
| 364 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 554 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 365 | 555 | "tool-call-id", |
| 366 | 556 | mockExtras, |
| 367 | 557 | ), |
| @@ -385,7 +575,7 @@ | ||
| 385 | 575 | |
| 386 | 576 | await expect( |
| 387 | 577 | searchReplaceToolImpl( |
| 388 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 578 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 389 | 579 | "tool-call-id", |
| 390 | 580 | mockExtras, |
| 391 | 581 | ), |
| @@ -411,7 +601,7 @@ | ||
| 411 | 601 | |
| 412 | 602 | await expect( |
| 413 | 603 | searchReplaceToolImpl( |
| 414 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 604 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 415 | 605 | "tool-call-id", |
| 416 | 606 | mockExtras, |
| 417 | 607 | ), |
| @@ -441,7 +631,7 @@ | ||
| 441 | 631 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 442 | 632 | |
| 443 | 633 | await searchReplaceToolImpl( |
| 444 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 634 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 445 | 635 | "tool-call-id", |
| 446 | 636 | mockExtras, |
| 447 | 637 | ); |
| @@ -476,7 +666,7 @@ | ||
| 476 | 666 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 477 | 667 | |
| 478 | 668 | await searchReplaceToolImpl( |
| 479 | - { filepath: "test.txt", diff: "mock diff content" }, | |
| 669 | + { filepath: "test.txt", diffs: ["mock diff content"] }, | |
| 480 | 670 | "tool-call-id", |
| 481 | 671 | mockExtras, |
| 482 | 672 | ); |
| @@ -512,7 +702,7 @@ | ||
| 512 | 702 | mockIdeMessenger.request.mockResolvedValue({ status: "success" }); |
| 513 | 703 | |
| 514 | 704 | await searchReplaceToolImpl( |
| 515 | - { filepath: "relative/test.txt", diff: "mock diff content" }, | |
| 705 | + { filepath: "relative/test.txt", diffs: ["mock diff content"] }, | |
| 516 | 706 | "tool-call-id", |
| 517 | 707 | mockExtras, |
| 518 | 708 | ); |
modified gui/src/util/clientTools/searchReplaceImpl.ts +16 −7
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | toolCallId, |
| 11 | 11 | extras, |
| 12 | 12 | ) => { |
| 13 | - const { filepath, diff } = args; | |
| 13 | + const { filepath, diffs } = args; | |
| 14 | 14 | |
| 15 | 15 | const state = extras.getState(); |
| 16 | 16 | const allowAnonymousTelemetry = state.config.config.allowAnonymousTelemetry; |
| @@ -26,11 +26,20 @@ | ||
| 26 | 26 | throw new Error(`File ${filepath} does not exist`); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - // Parse all search/replace blocks from the diff content | |
| 30 | - const blocks = parseAllSearchReplaceBlocks(diff); | |
| 29 | + // Parse all search/replace blocks from all diff strings | |
| 30 | + const allBlocks = []; | |
| 31 | + for (let diffIndex = 0; diffIndex < diffs.length; diffIndex++) { | |
| 32 | + const blocks = parseAllSearchReplaceBlocks(diffs[diffIndex]); | |
| 33 | + if (blocks.length === 0) { | |
| 34 | + throw new Error( | |
| 35 | + `No complete search/replace blocks found in diff ${diffIndex + 1}`, | |
| 36 | + ); | |
| 37 | + } | |
| 38 | + allBlocks.push(...blocks); | |
| 39 | + } | |
| 31 | 40 | |
| 32 | - if (blocks.length === 0) { | |
| 33 | - throw new Error("No complete search/replace blocks found"); | |
| 41 | + if (allBlocks.length === 0) { | |
| 42 | + throw new Error("No complete search/replace blocks found in any diffs"); | |
| 34 | 43 | } |
| 35 | 44 | |
| 36 | 45 | try { |
| @@ -40,8 +49,8 @@ | ||
| 40 | 49 | let currentContent = originalContent; |
| 41 | 50 | |
| 42 | 51 | // Apply all replacements sequentially to build the final content |
| 43 | - for (let i = 0; i < blocks.length; i++) { | |
| 44 | - const block = blocks[i]; | |
| 52 | + for (let i = 0; i < allBlocks.length; i++) { | |
| 53 | + const block = allBlocks[i]; | |
| 45 | 54 | const { searchContent, replaceContent } = block; |
| 46 | 55 | |
| 47 | 56 | // Find the search content in the current state of the file |