Порівняти коміти

...
8 змінених файлів з 240 додано та 122 видалено

No files matched your search

+63
Переглянути файл
@@ -44,3 +44,66 @@ test("a project's own icon replaces its initials; any project's colour changes f
await expect.poll(color).not.toBe(before);
expect(await page.evaluate(() => localStorage.getItem("openidea.tabColor.v1:/dev/acme-api"))).toBe("7");
});
test("changing a remote project's colour from its window tab updates both the tab and the remote window frame", async ({
workbench: page,
}) => {
await stubDesktop(page);
await page.evaluate(async () => {
const remoteMod = "/src/platform/remote.ts";
const windowGroupsMod = "/src/platform/windowGroups.ts";
const projectMod = "/src/platform/project.ts";
const { enableRemote, remoteLocation } = await import(/* @vite-ignore */ remoteMod);
const { useWindowGroup } = await import(/* @vite-ignore */ windowGroupsMod);
const { useProject } = await import(/* @vite-ignore */ projectMod);
const target = { kind: "ssh" as const, config: "coder" };
const remoteRoot = "/home/coder/git/acme-api";
const cur = useProject.getState().project;
if (cur) {
useProject.setState({ project: { ...cur, name: "acme-api", displayName: "acme-api", root: remoteRoot } });
}
enableRemote({
target,
root: remoteRoot,
host: "[email protected]:22",
os: "linux",
commands: [],
idlePolicy: null,
takenOver: false,
});
useWindowGroup.setState({
tabs: [
{ label: "local", name: "acme-api", root: "/Users/deng/acme-api", current: false },
{
label: "main",
name: "acme-api [[email protected]:22]",
root: remoteLocation(target, remoteRoot),
current: true,
},
],
});
});
const widget = page.getByRole("button", { name: "acme-api", exact: true });
const avatar = widget.locator("span[aria-hidden]").first();
const avatarBg = () => avatar.evaluate((el) => getComputedStyle(el).backgroundImage);
const beforeAvatar = await avatarBg();
const remoteTab = page.locator('[data-project-tab="main"]');
await expect(remoteTab).toBeVisible();
await expect(remoteTab).not.toHaveAttribute("data-tinted");
await remoteTab.click({ button: "right" });
await page.getByRole("menuitem", { name: "Change Project Color…" }).click();
const picker = page.getByRole("dialog", { name: "Project Color" });
await expect(picker).toBeVisible();
await picker.getByRole("radio", { name: "Rose" }).click();
await expect(picker).toBeHidden();
await expect(remoteTab).toHaveAttribute("data-tinted", "");
await expect.poll(avatarBg).not.toBe(beforeAvatar);
expect(
await page.evaluate(() => localStorage.getItem("openidea.tabColor.v1:ssh://coder/home/coder/git/acme-api")),
).toBe("6");
});
+9 -4
Переглянути файл
@@ -817,6 +817,7 @@ pub async fn remote_connect(
}
state.host.close_project(&label);
state.host.mcp_reports.set_remote(&label, std::path::PathBuf::from(&connection.root));
crate::window_groups::notify_changed(window.app_handle());
let weak = Arc::downgrade(&connection);
let peer = connection.peer.clone();
let auth_plugins = state.plugins.clone();
@@ -1187,6 +1188,7 @@ pub async fn remote_stop_forwarding(
pub fn remote_disconnect(window: Window, state: State<'_, AppState>) {
state.host.mcp_reports.remove_remote(AppState::owner_window(window.label()));
state.remote_dev.disconnect(AppState::owner_window(window.label()));
crate::window_groups::notify_changed(window.app_handle());
}
/// Stops the persistent `openidea-server` daemon for this window's remote project,
@@ -1215,11 +1217,14 @@ pub async fn remote_stop_backend(window: Window, state: State<'_, AppState>) ->
c.stopping.store(false, Ordering::Release);
}
result?;
let mut connections = state.remote_dev.windows.lock();
if connections.get(&label).is_some_and(|current| Arc::ptr_eq(current, &c)) {
connections.remove(&label);
state.host.mcp_reports.remove_remote(&label);
{
let mut connections = state.remote_dev.windows.lock();
if connections.get(&label).is_some_and(|current| Arc::ptr_eq(current, &c)) {
connections.remove(&label);
state.host.mcp_reports.remove_remote(&label);
}
}
crate::window_groups::notify_changed(window.app_handle());
Ok(())
}
+33 -15
Переглянути файл
@@ -34,25 +34,43 @@ pub fn current(app: &AppHandle, caller: &str) -> Vec<WindowTab> {
.iter()
.filter_map(|label| {
let window = app.get_webview_window(label)?;
let project = host.project(label).ok();
let name = project.as_ref().map(|p| ide_host::ops::project::info(p).display_name).unwrap_or_else(|| {
// Taken its launch but not finished opening: name the tab after that project.
state
.pending(label)
.and_then(|launch| launch.project)
.and_then(|p| p.file_name().map(|n| n.to_string_lossy().into_owned()))
.unwrap_or_else(|| window.title().unwrap_or_default())
});
Some(WindowTab {
label: label.clone(),
name,
root: project.map(|p| p.root.clone().into()),
current: label == caller,
})
let (name, root) = if let Some(c) = host.remote_dev.get(label) {
let loc = crate::remote_dev::remote_location(&c.target, &c.root);
(window.title().unwrap_or_default(), Some(PathBuf::from(loc).into()))
} else if let Ok(p) = host.project(label) {
(ide_host::ops::project::info(&p).display_name, Some(p.root.clone().into()))
} else if let Some(launch) = state.pending(label) {
if let Some(remote) = launch.remote {
let loc = crate::remote_dev::remote_location(&remote.target, &remote.path);
let name = remote
.path
.trim_end_matches('/')
.rsplit('/')
.next()
.filter(|s| !s.is_empty())
.map(str::to_owned)
.unwrap_or_else(|| window.title().unwrap_or_default());
(name, Some(PathBuf::from(loc).into()))
} else {
let name = launch
.project
.as_ref()
.and_then(|p| p.file_name().map(|n| n.to_string_lossy().into_owned()))
.unwrap_or_else(|| window.title().unwrap_or_default());
(name, launch.project)
}
} else {
(window.title().unwrap_or_default(), None)
};
Some(WindowTab { label: label.clone(), name, root, current: label == caller })
})
.collect()
}
pub(crate) fn notify_changed(app: &AppHandle) {
changed(app);
}
fn changed(app: &AppHandle) {
app.state::<AppState>().sink.emit(IdeEvent::WindowGroupsChanged);
}
+3 -1
Переглянути файл
@@ -484,10 +484,12 @@ export function windowActions(): Action[] {
const label = typeof arg === "string" ? arg : tabs.find((tab) => tab.current)?.label;
const tab = tabs.find((t) => t.label === label);
if (!tab?.root) return;
const remote = parseRemoteLocation(tab.root);
const colorName = remote ? basename(remote.path) || tab.name : tab.name;
const rect = document.querySelector(`[data-project-tab="${CSS.escape(tab.label)}"]`)?.getBoundingClientRect();
openTabColorPicker({
root: tab.root,
name: tab.name,
name: colorName,
x: rect ? rect.left : window.innerWidth / 2 - 110,
y: rect ? rect.bottom : 64,
});
+1
Переглянути файл
@@ -4,6 +4,7 @@ import { startupLaunchHandled, useProject } from "./project";
import { setContext } from "./context";
export const useWindowGroup = create<{ tabs: WindowTab[] }>(() => ({ tabs: [] }));
useWindowGroup.subscribe((s) => setContext("windowGrouped", s.tabs.length > 1));
export function reorderedTabs(tabs: readonly WindowTab[], source: string, target: string): string[] {
const labels = tabs.map((tab) => tab.label);
+21
Переглянути файл
@@ -114,6 +114,27 @@ it("tints only tabs with a stored colour override", () => {
expect(back.hasAttribute("data-tinted")).toBe(true);
});
it("keys remote project tab colours by remote location and hashes the remote folder name by default", () => {
const remoteRoot = "ssh://coder/home/coder/git/openidea_all";
useWindowGroup.setState({
tabs: [
{ label: "main", name: "openidea_all", root: "/Users/me/openidea_all", current: false },
{ label: "project-1", name: "openidea_all [dengliu@deng-devbox]", root: remoteRoot, current: true },
],
});
const { rerender } = render(<WindowGroupTabs />);
const remoteItem = document.querySelector('[data-project-tab="project-1"]') as HTMLElement;
expect(remoteItem.style.getPropertyValue("--project-color")).toBe(
projectColorVars("openidea_all")["--project-color"],
);
expect(remoteItem.hasAttribute("data-tinted")).toBe(false);
setTabColorOverride(remoteRoot, "#d24b8f");
rerender(<WindowGroupTabs />);
expect(remoteItem.style.getPropertyValue("--project-color")).toBe("#d24b8f");
expect(remoteItem.hasAttribute("data-tinted")).toBe(true);
});
describe("WindowGroupTabs drag reordering", () => {
let hit: Element | null;
const pointer = (el: Element | Window, type: string, x: number, y = 15, extra: MouseEventInit = {}) =>
+107 -101
Переглянути файл
@@ -1,6 +1,8 @@
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, type CSSProperties } from "react";
import { executeAction } from "@/platform/actions";
import { useTx } from "@/platform/i18n";
import { basename } from "@/platform/project";
import { parseRemoteLocation } from "@/platform/remote";
import { refreshWindowGroup, reorderedTabs, useWindowGroup } from "@/platform/windowGroups";
import { dropIndex, IconButton, registerDropTarget, showContextMenu, startPointerDrag } from "@/ui";
import { notifications } from "./contributions";
@@ -125,111 +127,115 @@ export function WindowGroupTabs() {
aria-label={tx("Project windows")}
data-dragging={dragging ? "" : undefined}
>
{tabs.map((tab, index) => (
<div
ref={(el) => {
if (el) itemRefs.current.set(tab.label, el);
else itemRefs.current.delete(tab.label);
}}
className={`${styles.item} ${tab.current ? styles.selected : ""} ${dragging === tab.label ? styles.dragging : ""} ${drop === index ? styles.dropBefore : ""} ${drop === tabs.length && index === tabs.length - 1 ? styles.dropAfter : ""}`}
key={tab.label}
data-project-tab={tab.label}
data-tinted={tab.root && tabColorOverride(tab.root) ? "" : undefined}
style={tabColorVars(tab.name, tab.root ? tabColorOverride(tab.root) : null) as CSSProperties}
onPointerDown={(e) => {
if (!(e.target as Element).closest('[role="tab"]')) return;
cancelDrag.current = startPointerDrag(
e,
e.currentTarget,
{ type: PROJECT_TAB_DRAG, payload: tab.label },
{
ghostContext: styles.tabs,
onStart: () => setDragging(tab.label),
onEnd: (dragged) => {
cancelDrag.current = undefined;
setDragging(null);
setDrop(null);
if (!dragged) return;
dragEnded.current = true;
window.setTimeout(() => {
dragEnded.current = false;
}, 0);
},
},
);
}}
onContextMenu={(e) => {
e.preventDefault();
showContextMenu(e, [
{
label: "Move Tab to New Window",
run: () => executeAction("window.detachTab", tab.label),
},
{
label: tx("Change Project Color…"),
run: () => executeAction("window.setTabColor", tab.label),
},
{ kind: "separator" },
{
label: "Close Tab",
run: () => executeAction("window.closeTab", tab.label),
},
{
label: "Close Other Tabs",
run: () => executeAction("window.closeOtherTabs", tab.label),
},
{
label: "Close Tabs to the Left",
disabled: index <= 0,
run: () => executeAction("window.closeTabsToLeft", tab.label),
},
{
label: "Close Tabs to the Right",
disabled: index >= tabs.length - 1,
run: () => executeAction("window.closeTabsToRight", tab.label),
},
]);
}}
>
<button
className={styles.tab}
role="tab"
aria-selected={tab.current}
tabIndex={tab.current ? 0 : -1}
title={tab.root ?? tab.name}
onClick={() => {
if (!dragEnded.current) run(executeAction("window.selectTab", tab.label));
{tabs.map((tab, index) => {
const remote = tab.root ? parseRemoteLocation(tab.root) : null;
const colorName = remote ? basename(remote.path) || tab.name : tab.name;
return (
<div
ref={(el) => {
if (el) itemRefs.current.set(tab.label, el);
else itemRefs.current.delete(tab.label);
}}
onKeyDown={(e) => {
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key)) return;
className={`${styles.item} ${tab.current ? styles.selected : ""} ${dragging === tab.label ? styles.dragging : ""} ${drop === index ? styles.dropBefore : ""} ${drop === tabs.length && index === tabs.length - 1 ? styles.dropAfter : ""}`}
key={tab.label}
data-project-tab={tab.label}
data-tinted={tab.root && tabColorOverride(tab.root) ? "" : undefined}
style={tabColorVars(colorName, tab.root ? tabColorOverride(tab.root) : null) as CSSProperties}
onPointerDown={(e) => {
if (!(e.target as Element).closest('[role="tab"]')) return;
cancelDrag.current = startPointerDrag(
e,
e.currentTarget,
{ type: PROJECT_TAB_DRAG, payload: tab.label },
{
ghostContext: styles.tabs,
onStart: () => setDragging(tab.label),
onEnd: (dragged) => {
cancelDrag.current = undefined;
setDragging(null);
setDrop(null);
if (!dragged) return;
dragEnded.current = true;
window.setTimeout(() => {
dragEnded.current = false;
}, 0);
},
},
);
}}
onContextMenu={(e) => {
e.preventDefault();
const next =
e.key === "Home"
? 0
: e.key === "End"
? tabs.length - 1
: (index + (e.key === "ArrowRight" ? 1 : -1) + tabs.length) % tabs.length;
run(executeAction("window.selectTab", tabs[next]!.label));
showContextMenu(e, [
{
label: "Move Tab to New Window",
run: () => executeAction("window.detachTab", tab.label),
},
{
label: tx("Change Project Color…"),
run: () => executeAction("window.setTabColor", tab.label),
},
{ kind: "separator" },
{
label: "Close Tab",
run: () => executeAction("window.closeTab", tab.label),
},
{
label: "Close Other Tabs",
run: () => executeAction("window.closeOtherTabs", tab.label),
},
{
label: "Close Tabs to the Left",
disabled: index <= 0,
run: () => executeAction("window.closeTabsToLeft", tab.label),
},
{
label: "Close Tabs to the Right",
disabled: index >= tabs.length - 1,
run: () => executeAction("window.closeTabsToRight", tab.label),
},
]);
}}
>
<span>{tab.name}</span>
</button>
<IconButton
icon="close"
size="small"
className={styles.close}
title={tx`Close ${tab.name}`}
onClick={() => run(executeAction("window.closeTab", tab.label))}
/>
<IconButton
icon="external-link"
size="small"
className={styles.detach}
title={tx`Move ${tab.name} to New Window`}
onClick={() => run(executeAction("window.detachTab", tab.label))}
/>
</div>
))}
<button
className={styles.tab}
role="tab"
aria-selected={tab.current}
tabIndex={tab.current ? 0 : -1}
title={tab.root ?? tab.name}
onClick={() => {
if (!dragEnded.current) run(executeAction("window.selectTab", tab.label));
}}
onKeyDown={(e) => {
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key)) return;
e.preventDefault();
const next =
e.key === "Home"
? 0
: e.key === "End"
? tabs.length - 1
: (index + (e.key === "ArrowRight" ? 1 : -1) + tabs.length) % tabs.length;
run(executeAction("window.selectTab", tabs[next]!.label));
}}
>
<span>{tab.name}</span>
</button>
<IconButton
icon="close"
size="small"
className={styles.close}
title={tx`Close ${tab.name}`}
onClick={() => run(executeAction("window.closeTab", tab.label))}
/>
<IconButton
icon="external-link"
size="small"
className={styles.detach}
title={tx`Move ${tab.name} to New Window`}
onClick={() => run(executeAction("window.detachTab", tab.label))}
/>
</div>
);
})}
</div>
</div>
);
+3 -1
Переглянути файл
@@ -8,6 +8,7 @@ import { useSyncExternalStore } from "react";
import { useEditorRegistry } from "@/editor/api";
import { Breadcrumbs } from "@/editor/core";
import { basename, useProject } from "@/platform/project";
import { remoteLocation, useRemote } from "@/platform/remote";
import { isUntitledUri, untitledTitle } from "@/platform/virtualDocs";
import { useT } from "@/platform/i18n";
import { ProgressBar } from "@/ui";
@@ -88,6 +89,7 @@ export function Workbench() {
const lightEdit = useProject((s) => s.lightEdit);
const standaloneTitle = useStandaloneEditor((s) => s.title);
const openingPath = useProject((s) => s.openingPath);
const remoteTarget = useRemote((s) => s.session?.target ?? null);
const root = project?.root ?? null;
const distractionFree = useDistractionFree((s) => s.active);
const mainToolbar = useAppearanceFlag("showMainToolbar");
@@ -95,7 +97,7 @@ export function Workbench() {
const navBarPosition = useNavigationBarPosition();
const frame = project ? styles.framed : lightEdit || standaloneTitle ? styles.lightEditFrame : undefined;
const tintName = openingPath ? basename(openingPath) || openingPath : project?.name;
const tintRoot = openingPath ?? root;
const tintRoot = openingPath ?? (remoteTarget && root ? remoteLocation(remoteTarget, root) : root);
return (
<div