Repository navigation
feat(web): find in diffs with Cmd+F #14623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93b3ee5
feat(web): find in diffs with Cmd+F
juliusmarminge deabf78
fix(web): find only ever unfolds a file
juliusmarminge 9f4ddb0
fix(web): find highlights both split columns and survives item renames
juliusmarminge 4865aa6
fix(web): find reveals matches in unrendered files and on long lines
juliusmarminge cf829ed
fix(web): closing find or clearing its query cancels a pending reveal
juliusmarminge ba67aed
fix(web): find ignores a closed panel's first search and clears on reset
juliusmarminge 9e2e2c3
fix(web): find centers a match below its panel and documents lazy diffs
juliusmarminge e5f0384
fix(web): find starts at the first match below the viewport top
juliusmarminge 4e5cee3
fix(web): find ignores keys pressed while an input method is composing
juliusmarminge b5071c4
fix(web): find keeps a query typed before its panel's first frame
juliusmarminge fbafadd
fix(web): find shortcuts work while a panel button has focus
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import type { CodeViewItem } from "@pierre/diffs"; | ||
| import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| // Find-in-diff lives in our @pierre/diffs patch and is not a package export. | ||
| const searchUrl = new URL("./components/CodeViewSearch.js", import.meta.resolve("@pierre/diffs")); | ||
| const { collectMatches } = (await import(/* @vite-ignore */ searchUrl.href)) as { | ||
| collectMatches( | ||
| items: ReadonlyArray<CodeViewItem<undefined>>, | ||
| params: { text: string; caseSensitive: boolean; wholeWord: boolean; regex: boolean }, | ||
| ): Array<{ | ||
| id: string; | ||
| side: string; | ||
| isContext: boolean; | ||
| lineNumber: number; | ||
| start: number; | ||
| end: number; | ||
| }>; | ||
| }; | ||
|
|
||
| const PATCH = `diff --git a/src/a.ts b/src/a.ts | ||
| index 1111111..2222222 100644 | ||
| --- a/src/a.ts | ||
| +++ b/src/a.ts | ||
| @@ -1,4 +1,5 @@ | ||
| const keep = 1; | ||
| -const oldName = 2; | ||
| +const newName = 2; | ||
| +const added = oldName; | ||
| const tail = 4; | ||
| @@ -20,3 +21,3 @@ function x() { | ||
| ctx20 name | ||
| -del21 Name | ||
| +add22 names | ||
| ctx22 | ||
| diff --git a/src/b.ts b/src/b.ts | ||
| index 3333333..4444444 100644 | ||
| --- a/src/b.ts | ||
| +++ b/src/b.ts | ||
| @@ -1,1 +1,1 @@ | ||
| -nil | ||
| +: nil | ||
| `; | ||
|
|
||
| const items: CodeViewItem<undefined>[] = parsePatchFiles(PATCH)[0]!.files.map( | ||
| (fileDiff, index) => ({ id: `file-${index}`, type: "diff", fileDiff, collapsed: index === 1 }), | ||
| ); | ||
|
|
||
| function find( | ||
| text: string, | ||
| flags: { caseSensitive?: boolean; wholeWord?: boolean; regex?: boolean } = {}, | ||
| ) { | ||
| return collectMatches(items, { | ||
| text, | ||
| caseSensitive: flags.caseSensitive ?? false, | ||
| wholeWord: flags.wholeWord ?? false, | ||
| regex: flags.regex ?? false, | ||
| }).map(({ id, side, lineNumber, start, end }) => `${id}:${side}:${lineNumber}:${start}-${end}`); | ||
| } | ||
|
|
||
| describe("collectMatches", () => { | ||
| it("finds removed, added, and context lines in render order, folded files included", () => { | ||
| expect(find("oldName")).toEqual(["file-0:deletions:2:6-13", "file-0:additions:3:14-21"]); | ||
| expect(find("nil")).toEqual(["file-1:deletions:1:0-3", "file-1:additions:1:2-5"]); | ||
| }); | ||
|
|
||
| it("honours case, whole-word, and regex toggles", () => { | ||
| expect(find("Name", { caseSensitive: true })).toEqual([ | ||
| "file-0:deletions:2:9-13", | ||
| "file-0:additions:2:9-13", | ||
| "file-0:additions:3:17-21", | ||
| "file-0:deletions:21:6-10", | ||
| ]); | ||
| expect(find("name", { wholeWord: true })).toEqual([ | ||
| "file-0:additions:21:6-10", | ||
| "file-0:deletions:21:6-10", | ||
| ]); | ||
| expect(find("n[a-z]+e", { regex: true })).toHaveLength(6); | ||
| }); | ||
|
|
||
| it("marks unchanged lines, which split view draws in both columns", () => { | ||
| const flags = collectMatches(items, { | ||
| text: "ctx", | ||
| caseSensitive: false, | ||
| wholeWord: false, | ||
| regex: false, | ||
| }).map(({ lineNumber, isContext }) => [lineNumber, isContext]); | ||
| expect(flags).toEqual([ | ||
| [21, true], | ||
| [23, true], | ||
| ]); | ||
| expect( | ||
| collectMatches(items, { | ||
| text: "oldName", | ||
| caseSensitive: false, | ||
| wholeWord: false, | ||
| regex: false, | ||
| }).map(({ isContext }) => isContext), | ||
| ).toEqual([false, false]); | ||
| }); | ||
|
|
||
| it("returns nothing for an empty query or an invalid pattern", () => { | ||
| expect(find("")).toEqual([]); | ||
| expect(find("(", { regex: true })).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // @vitest-environment jsdom | ||
|
|
||
| import { afterEach, describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { isEditableFocused } from "./editableFocus"; | ||
|
|
||
| afterEach(() => { | ||
| document.body.replaceChildren(); | ||
| }); | ||
|
|
||
| describe("isEditableFocused", () => { | ||
| it("sees a text field focused inside an open shadow root", () => { | ||
| // A key event from a shadow input is retargeted to its host, so the host is | ||
| // what page-level shortcut handlers receive as the event target. | ||
| const host = document.createElement("div"); | ||
| const input = document.createElement("input"); | ||
| host.attachShadow({ mode: "open" }).append(input); | ||
| document.body.append(host); | ||
|
|
||
| expect(isEditableFocused(host)).toBe(false); | ||
| input.focus(); | ||
| expect(isEditableFocused(host)).toBe(true); | ||
| expect(isEditableFocused()).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.