mirror of
https://github.com/gogs/gogs.git
synced 2026-05-28 21:30:36 +00:00
231
This commit is contained in:
@@ -54,7 +54,7 @@ const TREE_UNSAFE_CSS = `
|
||||
}
|
||||
`;
|
||||
|
||||
export interface CommitFileTreeHandle {
|
||||
export interface DiffFileTreeHandle {
|
||||
expandAll(): void;
|
||||
collapseAll(): void;
|
||||
focusSearch(): void;
|
||||
@@ -105,7 +105,7 @@ function collectDirectoryPaths(paths: readonly string[]): string[] {
|
||||
return Array.from(dirs);
|
||||
}
|
||||
|
||||
export const CommitFileTree = forwardRef<CommitFileTreeHandle, Props>(function CommitFileTreeImpl(
|
||||
export const DiffFileTree = forwardRef<DiffFileTreeHandle, Props>(function DiffFileTreeImpl(
|
||||
{ items, onSelectItem, searchOpen = true, header, className, style },
|
||||
ref,
|
||||
) {
|
||||
@@ -138,11 +138,8 @@ export const CommitFileTree = forwardRef<CommitFileTreeHandle, Props>(function C
|
||||
onSelectItemRef.current = onSelectItem;
|
||||
}, [onSelectItem]);
|
||||
|
||||
const searchOpenRef = useRef(searchOpen);
|
||||
useEffect(() => {
|
||||
searchOpenRef.current = searchOpen;
|
||||
}, [searchOpen]);
|
||||
|
||||
// Set when a row is clicked, then consumed by the search-restore effect so
|
||||
// we only reopen search on selection (not on blur from clicks outside).
|
||||
const selectionJustFiredRef = useRef(false);
|
||||
const onSelectionChange = useCallback((selectedPaths: readonly string[]) => {
|
||||
const target = selectedPaths[0];
|
||||
@@ -190,18 +187,16 @@ export const CommitFileTree = forwardRef<CommitFileTreeHandle, Props>(function C
|
||||
initialExpansion: "open",
|
||||
flattenEmptyDirectories: true,
|
||||
search: true,
|
||||
searchBlurBehavior: "retain",
|
||||
stickyFolders: true,
|
||||
gitStatus,
|
||||
onSelectionChange,
|
||||
unsafeCSS: TREE_UNSAFE_CSS,
|
||||
});
|
||||
|
||||
// Pierre closes search in two cases we do NOT want: row clicks and input
|
||||
// blur (clicking outside the tree). It only calls closeSearch() — not a
|
||||
// prop toggle — so `searchOpen` (the prop) stays true while Pierre's
|
||||
// internal state flips to false. Reopen with the last typed value whenever
|
||||
// Pierre closes search while our prop says it should be open.
|
||||
// Pierre closes search on row click. Reopen with the last typed value so
|
||||
// the user does not have to retype after navigating to a matched file.
|
||||
// Blur (clicking outside the tree) is intentionally NOT restored — only
|
||||
// row-click closures are, gated by `selectionJustFiredRef`.
|
||||
const search = useFileTreeSearch(model);
|
||||
const searchValueRef = useRef(search.value);
|
||||
const searchOpenFnRef = useRef(search.open);
|
||||
@@ -210,7 +205,7 @@ export const CommitFileTree = forwardRef<CommitFileTreeHandle, Props>(function C
|
||||
if (search.value !== "") {
|
||||
searchValueRef.current = search.value;
|
||||
}
|
||||
if (!search.isOpen && searchOpenRef.current && searchValueRef.current !== "") {
|
||||
if (!search.isOpen && selectionJustFiredRef.current && searchValueRef.current !== "") {
|
||||
searchOpenFnRef.current(searchValueRef.current);
|
||||
}
|
||||
selectionJustFiredRef.current = false;
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import { type CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { CommitFileTree, type CommitFileTreeHandle } from "@/components/CommitFileTree";
|
||||
import { DiffFileTree, type DiffFileTreeHandle } from "@/components/DiffFileTree";
|
||||
import { DiffSearch } from "@/components/DiffSearch";
|
||||
import { DiffToolbar, type DiffToolbarSettings, type WhitespaceMode } from "@/components/DiffToolbar";
|
||||
import { FileHeaderMenu } from "@/components/FileHeaderMenu";
|
||||
@@ -196,8 +196,8 @@ export function RepoCommit() {
|
||||
const { theme } = useTheme();
|
||||
const resolvedTheme = resolveTheme(theme);
|
||||
const viewRef = useRef<CodeViewHandle<undefined> | null>(null);
|
||||
const treeRef = useRef<CommitFileTreeHandle | null>(null);
|
||||
const mobileTreeRef = useRef<CommitFileTreeHandle | null>(null);
|
||||
const treeRef = useRef<DiffFileTreeHandle | null>(null);
|
||||
const mobileTreeRef = useRef<DiffFileTreeHandle | null>(null);
|
||||
const stickyWorkspaceRef = useRef<HTMLDivElement | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [mobileTreeOpen, setMobileTreeOpen] = useState(false);
|
||||
@@ -855,7 +855,7 @@ export function RepoCommit() {
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<CommitFileTree
|
||||
<DiffFileTree
|
||||
ref={treeRef}
|
||||
items={items}
|
||||
searchOpen={treeSearchOpen}
|
||||
@@ -952,7 +952,7 @@ export function RepoCommit() {
|
||||
</SheetClose>
|
||||
</span>
|
||||
</SheetTitle>
|
||||
<CommitFileTree
|
||||
<DiffFileTree
|
||||
ref={mobileTreeRef}
|
||||
items={items}
|
||||
searchOpen
|
||||
|
||||
Reference in New Issue
Block a user