mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47f8805045 |
No files matched your search
@@ -241,15 +241,6 @@ impl PathFilter {
|
||||
(!rel.is_empty()).then_some(rel)
|
||||
}
|
||||
|
||||
/// Recent Files' stored form: the store key for a project file, the absolute
|
||||
/// path for one outside it (a scratch file). Loading joins it to the root,
|
||||
/// which leaves an absolute path as it is.
|
||||
pub(crate) fn recent_key(&self, path: &Path) -> Option<String> {
|
||||
self.store_key(path).or_else(|| {
|
||||
(path.is_absolute() && !path.starts_with(&self.root)).then(|| path.to_str().map(str::to_owned))?
|
||||
})
|
||||
}
|
||||
|
||||
fn excluded_rel(&self, rel: &str) -> bool {
|
||||
self.excludes.is_match(rel)
|
||||
}
|
||||
|
||||
+15
-18
@@ -400,10 +400,15 @@ impl ProjectIndex {
|
||||
|
||||
/// Boost for "recent files" ranking.
|
||||
/// Records a recently opened file; a virtual document's URI (library
|
||||
/// class) is kept verbatim, and a file outside the project (a scratch file)
|
||||
/// by its absolute path.
|
||||
/// class) is kept verbatim, like IDEA lists library classes in Recent Files.
|
||||
pub fn mark_recent(&self, path: &Path) {
|
||||
let Some(path) = self.recent_key(path) else { return };
|
||||
let path = match path.to_str() {
|
||||
Some(s) if ide_core::text::is_virtual_uri(s) => path.to_owned(),
|
||||
_ => match self.normalize(path) {
|
||||
Some(p) => p,
|
||||
None => return,
|
||||
},
|
||||
};
|
||||
{
|
||||
let mut r = self.shared.recent.lock();
|
||||
r.retain(|p| p != &path);
|
||||
@@ -415,7 +420,13 @@ impl ProjectIndex {
|
||||
|
||||
/// Drops a file from Recent Files (Delete in the ⌘E popup).
|
||||
pub fn remove_recent(&self, path: &Path) {
|
||||
let Some(path) = self.recent_key(path) else { return };
|
||||
let path = match path.to_str() {
|
||||
Some(s) if ide_core::text::is_virtual_uri(s) => path.to_owned(),
|
||||
_ => match self.normalize(path) {
|
||||
Some(p) => p,
|
||||
None => return,
|
||||
},
|
||||
};
|
||||
{
|
||||
let mut r = self.shared.recent.lock();
|
||||
let before = r.len();
|
||||
@@ -462,20 +473,6 @@ impl ProjectIndex {
|
||||
&self.root
|
||||
}
|
||||
|
||||
/// How Recent Files stores `path`: a virtual URI verbatim, a project file normalized,
|
||||
/// and an existing file outside the root canonicalized. Excluded files under the root
|
||||
/// are left out.
|
||||
fn recent_key(&self, path: &Path) -> Option<PathBuf> {
|
||||
if path.to_str().is_some_and(ide_core::text::is_virtual_uri) {
|
||||
return Some(path.to_owned());
|
||||
}
|
||||
if let Some(p) = self.normalize(path) {
|
||||
return Some(p);
|
||||
}
|
||||
let p = dunce::canonicalize(path).ok().filter(|p| p.is_file())?;
|
||||
(!p.starts_with(&self.root)).then_some(p)
|
||||
}
|
||||
|
||||
/// Absolute path inside the root (or a content root), or `None` for paths outside the project.
|
||||
fn normalize(&self, path: &Path) -> Option<PathBuf> {
|
||||
let filter = self.shared.filter();
|
||||
|
||||
@@ -251,26 +251,6 @@ fn recent_files_skip_deleted_files_but_keep_virtual_documents() {
|
||||
assert_eq!(idx.recent_files(), vec![virt]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recent_files_keep_files_outside_the_project() {
|
||||
let fx = sample();
|
||||
let scratches = tempfile::tempdir().unwrap();
|
||||
let scratch = dunce::canonicalize(scratches.path()).unwrap().join("generated-requests.http");
|
||||
std::fs::write(&scratch, "GET http://localhost\n").unwrap();
|
||||
let app = fx.root.join("web/app.py");
|
||||
{
|
||||
let idx = fx.open();
|
||||
idx.mark_recent(&app);
|
||||
idx.mark_recent(&scratch);
|
||||
assert_eq!(idx.recent_files(), vec![scratch.clone(), app.clone()]);
|
||||
assert!(idx.wait_idle(WAIT));
|
||||
}
|
||||
let idx = fx.open();
|
||||
assert_eq!(idx.recent_files(), vec![scratch.clone(), app.clone()], "persisted by absolute path");
|
||||
idx.remove_recent(&scratch);
|
||||
assert_eq!(idx.recent_files(), vec![app]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persistence_skips_unchanged_files_on_reopen() {
|
||||
let fx = sample();
|
||||
|
||||
@@ -591,7 +591,7 @@ impl Shared {
|
||||
let update_elapsed = update_started.elapsed();
|
||||
let snapshot_started = Instant::now();
|
||||
if let Some(store) = &self.store {
|
||||
let recent: Vec<String> = self.recent.lock().iter().filter_map(|p| filter.recent_key(p)).collect();
|
||||
let recent: Vec<String> = self.recent.lock().iter().filter_map(|p| filter.store_key(p)).collect();
|
||||
let d = self.data.read();
|
||||
let snapshot_started = Instant::now();
|
||||
if let Err(e) = store.save_snapshot(&d, &filter, guard) {
|
||||
@@ -976,7 +976,7 @@ impl Shared {
|
||||
}
|
||||
}
|
||||
if save_recent && let Some(store) = &self.store {
|
||||
let rels: Vec<String> = self.recent.lock().iter().filter_map(|p| filter.recent_key(p)).collect();
|
||||
let rels: Vec<String> = self.recent.lock().iter().filter_map(|p| filter.store_key(p)).collect();
|
||||
if let Err(e) = store.save_recent(&rels) {
|
||||
tracing::warn!("index cache: saving recent files failed: {e}");
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0 -3px;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.sideTabsResizer:focus-visible::after {
|
||||
background: color-mix(in srgb, var(--focus-ring) 55%, transparent);
|
||||
|
||||
@@ -62,7 +62,7 @@ export function SideTabsResizer({ side }: { side: "left" | "right" }) {
|
||||
handle.setPointerCapture(e.pointerId);
|
||||
const origin = e.clientX;
|
||||
const previous = pane.style.getPropertyValue(LIMIT_VAR);
|
||||
const releaseCursor = lockDragCursor("col-resize");
|
||||
const releaseCursor = lockDragCursor("ew-resize");
|
||||
let next: number | null = null;
|
||||
// Only this pane follows the pointer; every group takes the new width on release.
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
|
||||
@@ -38,7 +38,7 @@ export function ChangesResizer() {
|
||||
const start = pane.getBoundingClientRect().width;
|
||||
const origin = e.clientX;
|
||||
const previous = session.style.getPropertyValue(WIDTH_VAR);
|
||||
const releaseCursor = lockDragCursor("col-resize");
|
||||
const releaseCursor = lockDragCursor("ew-resize");
|
||||
let next: number | null = null;
|
||||
// Only this session follows the pointer; every task takes the new width on release.
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
|
||||
@@ -1253,7 +1253,7 @@
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0 -3px;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.changesResizer:focus-visible::after {
|
||||
background: color-mix(in srgb, var(--focus-ring) 55%, transparent);
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
right: -3px;
|
||||
width: 6px;
|
||||
height: 100%;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.rowNumber {
|
||||
display: flex;
|
||||
|
||||
@@ -574,7 +574,7 @@ export function Grid(props: GridProps) {
|
||||
const startResize = (e: MouseEvent, col: number) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const releaseCursor = lockDragCursor("col-resize");
|
||||
const releaseCursor = lockDragCursor("ew-resize");
|
||||
const startX = e.clientX;
|
||||
const start = widths[col] ?? 100;
|
||||
const move = (ev: globalThis.MouseEvent) => {
|
||||
|
||||
@@ -132,23 +132,6 @@ describe("recent files switcher", () => {
|
||||
).toEqual(["README.md"]);
|
||||
});
|
||||
|
||||
it("shows a scratch file under its root's label", () => {
|
||||
const labelled = [{ path: "/data/scratches", label: "Scratches" }];
|
||||
const items = filterRecentFiles(
|
||||
["/data/scratches/api/generated-requests.http", "/p/src/Main.kt", "/elsewhere/a.txt"],
|
||||
"",
|
||||
{
|
||||
root: "/p",
|
||||
labelled,
|
||||
},
|
||||
);
|
||||
expect(items.map((f) => [f.rel, f.dir])).toEqual([
|
||||
["Scratches/api/generated-requests.http", "Scratches/api"],
|
||||
["src/Main.kt", "src"],
|
||||
["/elsewhere/a.txt", "/elsewhere"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("preselects the previous file when the current one is first", () => {
|
||||
const items = filterRecentFiles(paths, "", { root: "/p" });
|
||||
expect(initialFileIndex(items, "/p/src/Main.kt", "")).toBe(1);
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
maybeEditorService,
|
||||
toolWindowService,
|
||||
useContributions,
|
||||
useProjectViewRoots,
|
||||
useFileDecoration,
|
||||
type OpenEditorTab,
|
||||
type ToolWindowContribution,
|
||||
@@ -92,14 +91,6 @@ function RecentFilesDialog() {
|
||||
const step = useRecentPopup((s) => s.step);
|
||||
const edited = useTracking((s) => s.edited);
|
||||
const root = useProject((s) => s.project?.root ?? null);
|
||||
const viewRoots = useProjectViewRoots((s) => s.roots);
|
||||
const labelled = useMemo(
|
||||
() =>
|
||||
[...viewRoots.values()].flatMap((r) =>
|
||||
r.scope === "scratches" && r.path ? [{ path: r.path, label: r.label }] : [],
|
||||
),
|
||||
[viewRoots],
|
||||
);
|
||||
const toolWindows = useContributions((s) => s.toolWindows);
|
||||
const [paths, setPaths] = useState<string[] | null>(null);
|
||||
// Switcher: the open editor tabs (files and others), when the editor service lists them.
|
||||
@@ -144,13 +135,13 @@ function RecentFilesDialog() {
|
||||
const files = useMemo(
|
||||
() =>
|
||||
tabs
|
||||
? switcherItems(paths ?? [], tabs, query, root, labelled).filter((f) => !removed.has(f.path))
|
||||
? switcherItems(paths ?? [], tabs, query, root).filter((f) => !removed.has(f.path))
|
||||
: filterRecentFiles(
|
||||
(paths ?? []).filter((p) => !removed.has(p)),
|
||||
query,
|
||||
{ root, labelled, edited, editedOnly },
|
||||
{ root, edited, editedOnly },
|
||||
),
|
||||
[paths, tabs, removed, query, root, labelled, edited, editedOnly],
|
||||
[paths, tabs, removed, query, root, edited, editedOnly],
|
||||
);
|
||||
const fileRows = useMemo(() => files.map((f) => ({ ...f, key: f.path })), [files]);
|
||||
const tools = useMemo(() => switcherToolWindows(toolWindows.values(), !!root, query), [toolWindows, root, query]);
|
||||
|
||||
@@ -18,27 +18,10 @@ export interface RecentFileItem {
|
||||
editor?: { input: EditorInput; icon: string };
|
||||
}
|
||||
|
||||
/** A folder outside the project shown by its label (the Scratches root): `Scratches/requests.http`. */
|
||||
export interface LabelledRoot {
|
||||
path: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
function displayPath(path: string, root: string | null, labelled: readonly LabelledRoot[] = []): string {
|
||||
if (root && path.startsWith(root + "/")) return path.slice(root.length + 1);
|
||||
const outside = labelled.find((r) => path.startsWith(r.path + "/"));
|
||||
return outside ? `${outside.label}/${path.slice(outside.path.length + 1)}` : path;
|
||||
}
|
||||
|
||||
export function filterRecentFiles(
|
||||
paths: readonly string[],
|
||||
query: string,
|
||||
opts: {
|
||||
root: string | null;
|
||||
labelled?: readonly LabelledRoot[];
|
||||
edited?: ReadonlySet<string>;
|
||||
editedOnly?: boolean;
|
||||
},
|
||||
opts: { root: string | null; edited?: ReadonlySet<string>; editedOnly?: boolean },
|
||||
): RecentFileItem[] {
|
||||
const out: RecentFileItem[] = [];
|
||||
const seen = new Set<string>();
|
||||
@@ -46,7 +29,7 @@ export function filterRecentFiles(
|
||||
if (seen.has(path)) continue;
|
||||
seen.add(path);
|
||||
if (opts.editedOnly && !opts.edited?.has(path)) continue;
|
||||
const rel = displayPath(path, opts.root, opts.labelled);
|
||||
const rel = opts.root && path.startsWith(opts.root + "/") ? path.slice(opts.root.length + 1) : path;
|
||||
const name = basename(rel);
|
||||
let indices: number[] = [];
|
||||
if (query.trim()) {
|
||||
@@ -87,7 +70,6 @@ export function switcherItems(
|
||||
tabs: readonly OpenEditorTab[],
|
||||
query: string,
|
||||
root: string | null,
|
||||
labelled: readonly LabelledRoot[] = [],
|
||||
): RecentFileItem[] {
|
||||
const fileTabs = new Map(tabs.filter(isFileTab).map((t) => [t.input.path!, t]));
|
||||
const ordered = [
|
||||
@@ -101,7 +83,7 @@ export function switcherItems(
|
||||
const out: RecentFileItem[] = [];
|
||||
for (const t of ordered) {
|
||||
if (isFileTab(t)) {
|
||||
out.push(...filterRecentFiles([t.input.path!], query, { root, labelled }));
|
||||
out.push(...filterRecentFiles([t.input.path!], query, { root }));
|
||||
continue;
|
||||
}
|
||||
let indices: number[] = [];
|
||||
|
||||
@@ -252,7 +252,7 @@
|
||||
background: var(--bg-app);
|
||||
border-left: 1px solid var(--border);
|
||||
border-right: 1px solid var(--border);
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
touch-action: none;
|
||||
}
|
||||
.host :global(.cm-diffDivider:hover) {
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
overflow:hidden, so any rule drawn into the 8px gap would be clipped away. */
|
||||
inset-inline-start: -4px;
|
||||
width: 8px;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
touch-action: none;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
|
||||
@@ -120,7 +120,7 @@ export function useColumnResize(target: ResizeTarget) {
|
||||
x: e.clientX,
|
||||
element: e.currentTarget,
|
||||
pointerId: e.pointerId,
|
||||
releaseCursor: lockDragCursor("col-resize"),
|
||||
releaseCursor: lockDragCursor("ew-resize"),
|
||||
};
|
||||
listeners.current = { blur, escape };
|
||||
e.currentTarget.setPointerCapture?.(e.pointerId);
|
||||
|
||||
@@ -352,7 +352,7 @@ const theme = EditorView.baseTheme({
|
||||
height: "4px",
|
||||
borderRadius: "2px",
|
||||
background: "var(--focus-ring, #3574f0)",
|
||||
cursor: "row-resize",
|
||||
cursor: "ns-resize",
|
||||
},
|
||||
".cm-reviewHandle[data-disabled]": { opacity: "0.4", cursor: "default" },
|
||||
".cm-reviewHandle-start": { top: "-2px" },
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
outline: none;
|
||||
transition: background var(--dur) var(--ease);
|
||||
}
|
||||
/* Dividers use col-/row-resize: WebKit on macOS 26.2 shows the arrow for ew-/ns-resize. */
|
||||
.handle[aria-orientation="vertical"] {
|
||||
width: 1px;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.handle[aria-orientation="horizontal"] {
|
||||
height: 1px;
|
||||
cursor: row-resize;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
.handle::after {
|
||||
content: "";
|
||||
|
||||
@@ -10,9 +10,9 @@ afterEach(() => {
|
||||
|
||||
describe("lockDragCursor", () => {
|
||||
it("holds the cursor until the drag ends", () => {
|
||||
const release = lockDragCursor("col-resize");
|
||||
const release = lockDragCursor("ew-resize");
|
||||
expect(html.getAttribute("data-drag-cursor")).toBe("");
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("col-resize");
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("ew-resize");
|
||||
|
||||
release();
|
||||
expect(html.hasAttribute("data-drag-cursor")).toBe(false);
|
||||
@@ -20,27 +20,27 @@ describe("lockDragCursor", () => {
|
||||
});
|
||||
|
||||
it("ignores a repeated release", () => {
|
||||
const release = lockDragCursor("row-resize");
|
||||
const release = lockDragCursor("ns-resize");
|
||||
release();
|
||||
release();
|
||||
expect(html.hasAttribute("data-drag-cursor")).toBe(false);
|
||||
});
|
||||
|
||||
it("restores an outer drag after a nested one ends", () => {
|
||||
const outer = lockDragCursor("col-resize");
|
||||
const outer = lockDragCursor("ew-resize");
|
||||
const inner = lockDragCursor("nwse-resize");
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("nwse-resize");
|
||||
|
||||
inner();
|
||||
expect(html.getAttribute("data-drag-cursor")).toBe("");
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("col-resize");
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("ew-resize");
|
||||
|
||||
outer();
|
||||
expect(html.hasAttribute("data-drag-cursor")).toBe(false);
|
||||
});
|
||||
|
||||
it("releases when the pointer goes up outside the handle", () => {
|
||||
lockDragCursor("col-resize");
|
||||
lockDragCursor("ew-resize");
|
||||
document.dispatchEvent(new Event("pointerup", { bubbles: true }));
|
||||
expect(html.hasAttribute("data-drag-cursor")).toBe(false);
|
||||
expect(html.style.getPropertyValue("--drag-cursor")).toBe("");
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* default one mid-drag. `global.css` keys off `data-drag-cursor` instead and
|
||||
* wins over those cursors with `!important`.
|
||||
*/
|
||||
export type DragCursor = "col-resize" | "row-resize" | "ew-resize" | "ns-resize" | "nwse-resize";
|
||||
export type DragCursor = "ew-resize" | "ns-resize" | "nwse-resize";
|
||||
|
||||
const active = new Set<() => void>();
|
||||
let listening = false;
|
||||
|
||||
@@ -179,17 +179,17 @@
|
||||
.undocked[data-slot^="left"] > .undockEdge {
|
||||
inset: 0 0 0 auto;
|
||||
width: var(--island-gap);
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.undocked[data-slot^="right"] > .undockEdge {
|
||||
inset: 0 auto 0 0;
|
||||
width: var(--island-gap);
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.undocked[data-slot^="bottom"] > .undockEdge {
|
||||
inset: 0 0 auto;
|
||||
height: var(--island-gap);
|
||||
cursor: row-resize;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
.undockEdge:focus-visible {
|
||||
background: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
@@ -210,10 +210,10 @@
|
||||
grid-area: gap-bottom;
|
||||
}
|
||||
.gap[aria-orientation="vertical"] {
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.gap[aria-orientation="horizontal"] {
|
||||
cursor: row-resize;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
/* A slightly wider hit area than the gap itself. */
|
||||
.gap::before {
|
||||
@@ -286,7 +286,7 @@
|
||||
flex: none;
|
||||
width: 0;
|
||||
outline: none;
|
||||
cursor: col-resize;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.stripeHandle::before {
|
||||
content: "";
|
||||
|
||||
@@ -269,7 +269,7 @@ function StripeHandle({
|
||||
const origin = e.clientX;
|
||||
const icons = parseFloat(getComputedStyle(stripe).getPropertyValue("--stripe-icon-button")) || 30;
|
||||
const start = names ? width : icons;
|
||||
const releaseCursor = lockDragCursor("col-resize");
|
||||
const releaseCursor = lockDragCursor("ew-resize");
|
||||
let next = { names, width, px: start };
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
if (!(ev.buttons & 1)) return end();
|
||||
@@ -945,7 +945,7 @@ function SplitHandle({ anchor, hidden }: { anchor: ToolWindowAnchor; hidden: boo
|
||||
e.preventDefault();
|
||||
el.setPointerCapture(e.pointerId);
|
||||
const origin = stacked ? e.clientY : e.clientX;
|
||||
const releaseCursor = lockDragCursor(stacked ? "row-resize" : "col-resize");
|
||||
const releaseCursor = lockDragCursor(stacked ? "ns-resize" : "ew-resize");
|
||||
let ratio: number | null = null;
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
if (!(ev.buttons & 1)) return end();
|
||||
@@ -1018,7 +1018,7 @@ function UndockEdge({ anchor }: { anchor: ToolWindowAnchor }) {
|
||||
e.preventDefault();
|
||||
el.setPointerCapture(e.pointerId);
|
||||
const origin = vertical ? e.clientX : e.clientY;
|
||||
const releaseCursor = lockDragCursor(vertical ? "col-resize" : "row-resize");
|
||||
const releaseCursor = lockDragCursor(vertical ? "ew-resize" : "ns-resize");
|
||||
let next = m.size;
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
if (!(ev.buttons & 1)) return end();
|
||||
@@ -1201,7 +1201,7 @@ function GapHandle({
|
||||
const el = e.currentTarget;
|
||||
el.setPointerCapture(e.pointerId);
|
||||
const origin = vertical ? e.clientX : e.clientY;
|
||||
const releaseCursor = lockDragCursor(vertical ? "col-resize" : "row-resize");
|
||||
const releaseCursor = lockDragCursor(vertical ? "ew-resize" : "ns-resize");
|
||||
let next = m.size;
|
||||
const move = (ev: globalThis.PointerEvent) => {
|
||||
if (!(ev.buttons & 1)) return end();
|
||||
|
||||
Reference in new issue
Block a user