дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 11:15:40 +02:00
fix(search): scope Find in Files to the focused folder (#534)
Find in Files from the keyboard ignored the selected folder and reused the saved scope; only the context menu passed a directory. Focused trees now publish the selected folder, or a file's parent, as an action context, and Find and Replace in Files use it when no explicit directory is given. This covers the Project view, Commit and Changes, Bookmarks and Scratches. Group rows and editor focus keep the previous behaviour. Fixes #526
Цей коміт міститься в:
1 джерело
a553dafa7a
коміт
c5cb217c7c
11 files changed
+352
-9
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { useLayoutEffect, type RefObject } from "react";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { isVirtualUri } from "@/platform/virtualDocs";
|
||||
|
||||
let owner: HTMLElement | null = null;
|
||||
|
||||
/** Only the focused tree contributes its selected directory to actions. */
|
||||
export function useTreeDirectoryContext(
|
||||
ref: RefObject<HTMLElement | null>,
|
||||
directory: string | null | undefined,
|
||||
enabled: boolean,
|
||||
) {
|
||||
useLayoutEffect(() => {
|
||||
if (!enabled) return;
|
||||
const element = ref.current;
|
||||
if (!element) return;
|
||||
const clear = () => {
|
||||
if (owner !== element) return;
|
||||
owner = null;
|
||||
setContext("focusedDirectory", undefined);
|
||||
};
|
||||
const publish = () => {
|
||||
if (document.activeElement !== element) return;
|
||||
owner = element;
|
||||
setContext("focusedDirectory", directory && !isVirtualUri(directory) ? directory : undefined);
|
||||
};
|
||||
element.addEventListener("focus", publish);
|
||||
element.addEventListener("blur", clear);
|
||||
publish();
|
||||
return () => {
|
||||
element.removeEventListener("focus", publish);
|
||||
element.removeEventListener("blur", clear);
|
||||
clear();
|
||||
};
|
||||
}, [ref, directory, enabled]);
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача