Merge pull request 'Improve global search: Add diffing from results with query highlighting' (#1) from FixSearch into master
publish / publish-tauri (, windows-latest) (release) Successful in 6m34s
publish / publish-tauri (, windows-latest) (release) Successful in 6m34s
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -1338,6 +1338,10 @@ fn search_candidate_commits(
|
|||||||
OsString::from("--all"),
|
OsString::from("--all"),
|
||||||
OsString::from("--reverse"),
|
OsString::from("--reverse"),
|
||||||
OsString::from("--format=%H"),
|
OsString::from("--format=%H"),
|
||||||
|
// Skip textconv diff drivers so git does not extract binary files
|
||||||
|
// (e.g. .docx / Office temp "~$" lock files) to temp files, which can
|
||||||
|
// fail with "unsupported filetype" and abort the whole search.
|
||||||
|
OsString::from("--no-textconv"),
|
||||||
];
|
];
|
||||||
if !case_sensitive {
|
if !case_sensitive {
|
||||||
args.push(OsString::from("-i"));
|
args.push(OsString::from("-i"));
|
||||||
@@ -1447,7 +1451,7 @@ fn first_added_match_line(
|
|||||||
check_search_cancelled(cancellation)?;
|
check_search_cancelled(cancellation)?;
|
||||||
let output = run_git_with_paths_cancellable(
|
let output = run_git_with_paths_cancellable(
|
||||||
repo,
|
repo,
|
||||||
&["diff", "--unified=0", parent, commit],
|
&["diff", "--no-textconv", "--unified=0", parent, commit],
|
||||||
&[file.to_string()],
|
&[file.to_string()],
|
||||||
cancellation,
|
cancellation,
|
||||||
"Git-Diff fuer Suchtreffer fehlgeschlagen",
|
"Git-Diff fuer Suchtreffer fehlgeschlagen",
|
||||||
|
|||||||
+32
-13
@@ -96,8 +96,10 @@
|
|||||||
let comparison: GitCommitComparison | null = null;
|
let comparison: GitCommitComparison | null = null;
|
||||||
let compareDialogOpen = false;
|
let compareDialogOpen = false;
|
||||||
let selectedDiffPath = "";
|
let selectedDiffPath = "";
|
||||||
|
let diffHighlightQuery = "";
|
||||||
let pendingRestoreFile: { commit: GitCommit; file: GitCommitFile } | null = null;
|
let pendingRestoreFile: { commit: GitCommit; file: GitCommitFile } | null = null;
|
||||||
let globalSearchOpen = false;
|
let globalSearchOpen = false;
|
||||||
|
let lastSearchQuery = "";
|
||||||
let globalSearchResults: GitSearchHit[] = [];
|
let globalSearchResults: GitSearchHit[] = [];
|
||||||
let globalSearchBusy = false;
|
let globalSearchBusy = false;
|
||||||
let globalSearchError = "";
|
let globalSearchError = "";
|
||||||
@@ -746,6 +748,7 @@
|
|||||||
const result = await compareCommits(activeRepoPath, compareFrom, compareTo);
|
const result = await compareCommits(activeRepoPath, compareFrom, compareTo);
|
||||||
comparison = result;
|
comparison = result;
|
||||||
selectedDiffPath = result.files[0]?.path ?? "";
|
selectedDiffPath = result.files[0]?.path ?? "";
|
||||||
|
diffHighlightQuery = "";
|
||||||
pendingRestoreFile = null;
|
pendingRestoreFile = null;
|
||||||
compareDialogOpen = true;
|
compareDialogOpen = true;
|
||||||
});
|
});
|
||||||
@@ -757,6 +760,19 @@
|
|||||||
const result = await diffFileAgainstWorkingTree(activeRepoPath, historyCommit.hash, selectedExplorerPath);
|
const result = await diffFileAgainstWorkingTree(activeRepoPath, historyCommit.hash, selectedExplorerPath);
|
||||||
comparison = result;
|
comparison = result;
|
||||||
selectedDiffPath = result.files[0]?.path ?? selectedExplorerPath;
|
selectedDiffPath = result.files[0]?.path ?? selectedExplorerPath;
|
||||||
|
diffHighlightQuery = "";
|
||||||
|
pendingRestoreFile = null;
|
||||||
|
compareDialogOpen = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function diffSearchHit(hit: GitSearchHit) {
|
||||||
|
if (!activeRepoPath) return;
|
||||||
|
await runOperation(`Diffing ${hit.file}`, async () => {
|
||||||
|
const result = await diffFileAgainstWorkingTree(activeRepoPath, hit.commit_hash, hit.file);
|
||||||
|
comparison = result;
|
||||||
|
selectedDiffPath = result.files[0]?.path ?? hit.file;
|
||||||
|
diffHighlightQuery = lastSearchQuery;
|
||||||
pendingRestoreFile = null;
|
pendingRestoreFile = null;
|
||||||
compareDialogOpen = true;
|
compareDialogOpen = true;
|
||||||
});
|
});
|
||||||
@@ -785,6 +801,7 @@
|
|||||||
if (!activeRepoPath || globalSearchBusy) return;
|
if (!activeRepoPath || globalSearchBusy) return;
|
||||||
const searchId = `search-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
const searchId = `search-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
||||||
globalSearchId = searchId;
|
globalSearchId = searchId;
|
||||||
|
lastSearchQuery = query;
|
||||||
globalSearchBusy = true;
|
globalSearchBusy = true;
|
||||||
globalSearchError = "";
|
globalSearchError = "";
|
||||||
globalSearchResults = [];
|
globalSearchResults = [];
|
||||||
@@ -1109,19 +1126,6 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Compare diff dialog -->
|
|
||||||
{#if compareDialogOpen && comparison}
|
|
||||||
<CompareDialog
|
|
||||||
{comparison}
|
|
||||||
{selectedDiffPath}
|
|
||||||
{isBusy}
|
|
||||||
restoreLabel={pendingRestoreFile ? "Restore file" : ""}
|
|
||||||
onClose={closeCompareDialog}
|
|
||||||
onRestore={restorePreviewedCommitFile}
|
|
||||||
onSelectFile={selectDiffFile}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if globalSearchOpen}
|
{#if globalSearchOpen}
|
||||||
<GlobalSearchDialog
|
<GlobalSearchDialog
|
||||||
{hasRepository}
|
{hasRepository}
|
||||||
@@ -1132,6 +1136,21 @@
|
|||||||
onClose={closeGlobalSearchDialog}
|
onClose={closeGlobalSearchDialog}
|
||||||
onSearch={runGlobalSearch}
|
onSearch={runGlobalSearch}
|
||||||
onCancel={cancelGlobalSearch}
|
onCancel={cancelGlobalSearch}
|
||||||
|
onDiff={diffSearchHit}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<!-- Compare diff dialog (rendered last so it overlays the search dialog when opened from a hit) -->
|
||||||
|
{#if compareDialogOpen && comparison}
|
||||||
|
<CompareDialog
|
||||||
|
{comparison}
|
||||||
|
{selectedDiffPath}
|
||||||
|
{isBusy}
|
||||||
|
highlightQuery={diffHighlightQuery}
|
||||||
|
restoreLabel={pendingRestoreFile ? "Restore file" : ""}
|
||||||
|
onClose={closeCompareDialog}
|
||||||
|
onRestore={restorePreviewedCommitFile}
|
||||||
|
onSelectFile={selectDiffFile}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
+24
-1
@@ -1123,6 +1123,19 @@
|
|||||||
.split-cell.add { background: rgba(78,202,118,0.09); color: #5dd88a; }
|
.split-cell.add { background: rgba(78,202,118,0.09); color: #5dd88a; }
|
||||||
.split-cell.empty { background: rgba(0,0,0,0.06); }
|
.split-cell.empty { background: rgba(0,0,0,0.06); }
|
||||||
|
|
||||||
|
/* Search-hit highlight: amber, distinct from add (green) / del (red).
|
||||||
|
Higher specificity so it overrides the add/del backgrounds on a matched line. */
|
||||||
|
.split-diff .split-cell.match {
|
||||||
|
background: rgba(240,182,72,0.22);
|
||||||
|
color: #f3c969;
|
||||||
|
box-shadow: inset 2px 0 0 rgba(240,182,72,0.9);
|
||||||
|
}
|
||||||
|
.split-diff .split-num.match {
|
||||||
|
background: rgba(240,182,72,0.2);
|
||||||
|
color: rgba(240,182,72,0.9);
|
||||||
|
border-right-color: rgba(240,182,72,0.35);
|
||||||
|
}
|
||||||
|
|
||||||
.split-col-headers {
|
.split-col-headers {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
@@ -1254,11 +1267,21 @@
|
|||||||
}
|
}
|
||||||
.search-hit-top {
|
.search-hit-top {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
grid-template-columns: auto minmax(0, 1fr) auto auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
.search-hit-diff {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
padding: 3px 9px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
.search-hit-top .hash {
|
.search-hit-top .hash {
|
||||||
padding: 2px 7px;
|
padding: 2px 7px;
|
||||||
border: 1px solid rgba(90,140,248,0.22);
|
border: 1px solid rgba(90,140,248,0.22);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
selectedDiffPath: string;
|
selectedDiffPath: string;
|
||||||
isBusy: boolean;
|
isBusy: boolean;
|
||||||
restoreLabel?: string;
|
restoreLabel?: string;
|
||||||
|
/** When opened from a search hit, the term to highlight on matching lines. */
|
||||||
|
highlightQuery?: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onRestore?: () => void;
|
onRestore?: () => void;
|
||||||
onSelectFile: (file: GitDiffFile) => void;
|
onSelectFile: (file: GitDiffFile) => void;
|
||||||
@@ -25,11 +27,25 @@
|
|||||||
selectedDiffPath = "",
|
selectedDiffPath = "",
|
||||||
isBusy = false,
|
isBusy = false,
|
||||||
restoreLabel = "",
|
restoreLabel = "",
|
||||||
|
highlightQuery = "",
|
||||||
onClose = () => {},
|
onClose = () => {},
|
||||||
onRestore = undefined,
|
onRestore = undefined,
|
||||||
onSelectFile = () => {},
|
onSelectFile = () => {},
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
|
// Needle = first non-empty line of the search query, lowercased for matching.
|
||||||
|
let highlightNeedle = $derived(
|
||||||
|
highlightQuery
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.find((line) => line.length > 0)
|
||||||
|
?.toLowerCase() ?? ""
|
||||||
|
);
|
||||||
|
|
||||||
|
function isMatch(text?: string): boolean {
|
||||||
|
return highlightNeedle.length > 0 && !!text && text.toLowerCase().includes(highlightNeedle);
|
||||||
|
}
|
||||||
|
|
||||||
let beforePane = $state<HTMLDivElement | null>(null);
|
let beforePane = $state<HTMLDivElement | null>(null);
|
||||||
let afterPane = $state<HTMLDivElement | null>(null);
|
let afterPane = $state<HTMLDivElement | null>(null);
|
||||||
let isSyncingSplitScroll = false;
|
let isSyncingSplitScroll = false;
|
||||||
@@ -259,8 +275,8 @@
|
|||||||
{#if row.type === "span"}
|
{#if row.type === "span"}
|
||||||
<div class="split-span split-{row.kind}">{row.text}</div>
|
<div class="split-span split-{row.kind}">{row.text}</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="split-num" class:del={row.leftKind === "del"} class:empty={row.leftKind === "empty"}>{row.leftNum ?? ""}</div>
|
<div class="split-num" class:del={row.leftKind === "del"} class:empty={row.leftKind === "empty"} class:match={isMatch(row.leftText)}>{row.leftNum ?? ""}</div>
|
||||||
<div class="split-cell" class:del={row.leftKind === "del"} class:empty={row.leftKind === "empty"}>{row.leftText ?? " "}</div>
|
<div class="split-cell" class:del={row.leftKind === "del"} class:empty={row.leftKind === "empty"} class:match={isMatch(row.leftText)}>{row.leftText ?? " "}</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -276,8 +292,8 @@
|
|||||||
{#if row.type === "span"}
|
{#if row.type === "span"}
|
||||||
<div class="split-span split-{row.kind}">{row.text}</div>
|
<div class="split-span split-{row.kind}">{row.text}</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="split-num" class:add={row.rightKind === "add"} class:empty={row.rightKind === "empty"}>{row.rightNum ?? ""}</div>
|
<div class="split-num" class:add={row.rightKind === "add"} class:empty={row.rightKind === "empty"} class:match={isMatch(row.rightText)}>{row.rightNum ?? ""}</div>
|
||||||
<div class="split-cell" class:add={row.rightKind === "add"} class:empty={row.rightKind === "empty"}>{row.rightText ?? " "}</div>
|
<div class="split-cell" class:add={row.rightKind === "add"} class:empty={row.rightKind === "empty"} class:match={isMatch(row.rightText)}>{row.rightText ?? " "}</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { CalendarDays, FileCode, LoaderCircle, Search, User, X } from "@lucide/svelte";
|
import { CalendarDays, FileCode, GitCompare, LoaderCircle, Search, User, X } from "@lucide/svelte";
|
||||||
import type { GitSearchHit } from "../types";
|
import type { GitSearchHit } from "../types";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onSearch: (query: string, caseSensitive: boolean, limit: number) => void | Promise<void>;
|
onSearch: (query: string, caseSensitive: boolean, limit: number) => void | Promise<void>;
|
||||||
onCancel: () => void | Promise<void>;
|
onCancel: () => void | Promise<void>;
|
||||||
|
onDiff: (hit: GitSearchHit) => void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
onClose = () => {},
|
onClose = () => {},
|
||||||
onSearch = () => {},
|
onSearch = () => {},
|
||||||
onCancel = () => {},
|
onCancel = () => {},
|
||||||
|
onDiff = () => {},
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let query = $state("");
|
let query = $state("");
|
||||||
@@ -148,6 +150,16 @@
|
|||||||
{#if hit.matches_added > 1}
|
{#if hit.matches_added > 1}
|
||||||
<span class="pill pill-active">+{hit.matches_added} matches</span>
|
<span class="pill pill-active">+{hit.matches_added} matches</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
<button
|
||||||
|
class="btn-secondary search-hit-diff"
|
||||||
|
type="button"
|
||||||
|
disabled={isBusy}
|
||||||
|
title={`Compare this version of ${hit.file} with the current version`}
|
||||||
|
onclick={() => onDiff(hit)}
|
||||||
|
>
|
||||||
|
<GitCompare size={14} aria-hidden="true" />
|
||||||
|
DIFF
|
||||||
|
</button>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="search-hit-meta">
|
<div class="search-hit-meta">
|
||||||
|
|||||||
Reference in New Issue
Block a user