Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

989 B
Raw Blame
import type { TabStripHandle } from "@/ui/Tabs";

/** Content tab strips rendered in each tool window's header (Run sessions, Find tabs, terminals…). */
const strips = new Map<string, Set<TabStripHandle>>();
const registries = new Map<string, (handle: TabStripHandle) => () => void>();

/** The `TabStripRegistry` value for tool window `id` (stable per id). */
export function contentTabRegistry(id: string): (handle: TabStripHandle) => () => void {
  let fn = registries.get(id);
  if (!fn) {
    fn = (handle) => {
      let set = strips.get(id);
      if (!set) strips.set(id, (set = new Set()));
      set.add(handle);
      return () => void set.delete(handle);
    };
    registries.set(id, fn);
  }
  return fn;
}

/** Closes the selected content tab of tool window `id`; false when it has none that can be closed. */
export function closeSelectedContent(id: string): boolean {
  for (const strip of strips.get(id) ?? []) if (strip.closeSelected()) return true;
  return false;
}