mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d3c8d0061 | ||
|
|
ad3a968713 | ||
|
|
83ecbc7b1c |
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { expect, test } from "./fixtures";
|
||||
|
||||
test("Run Anything keeps its command field and shortcuts visible as its results scroll", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 1080, height: 740 });
|
||||
await page.evaluate(async () => {
|
||||
const projectModule = "/src/platform/project.ts";
|
||||
const contributionsModule = "/src/workbench/contributions.ts";
|
||||
const historyModule = "/src/features/run-anything/model.ts";
|
||||
const [{ useProject }, { registerRunAnythingProvider }, { pushHistory }] = await Promise.all([
|
||||
import(/* @vite-ignore */ projectModule),
|
||||
import(/* @vite-ignore */ contributionsModule),
|
||||
import(/* @vite-ignore */ historyModule),
|
||||
]);
|
||||
const root = useProject.getState().project.root;
|
||||
for (const command of ["git status", "git diff --stat", "pnpm lint", "pnpm test"]) pushHistory(root, command);
|
||||
const tasks = Array.from({ length: 8 }, (_, i) => {
|
||||
const command = `npm run verify-${i + 1}`;
|
||||
return {
|
||||
key: command,
|
||||
label: `Verify checkout configuration ${i + 1}`,
|
||||
detail: "checkout-service / workspace verification",
|
||||
completion: command,
|
||||
run: () => {
|
||||
document.body.dataset.runAnythingCommand = command;
|
||||
},
|
||||
};
|
||||
});
|
||||
registerRunAnythingProvider({
|
||||
id: "test-verify",
|
||||
order: -100,
|
||||
group: "Run Configurations",
|
||||
items: (line: string) => tasks.filter((task) => task.completion.includes(line)),
|
||||
});
|
||||
});
|
||||
await page.keyboard.press("Control");
|
||||
await page.keyboard.press("Control");
|
||||
|
||||
const popup = page.getByRole("dialog", { name: "Run Anything", exact: true });
|
||||
const field = popup.getByLabel("Command line", { exact: true });
|
||||
const results = popup.getByRole("listbox", { name: "Run Anything entries" });
|
||||
const hint = popup.getByText(/Enter to run, Tab to complete|Tab to complete, Enter to run/);
|
||||
await expect(field).toBeFocused();
|
||||
await page.setViewportSize({ width: 560, height: 340 });
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const [shell, footer] = await Promise.all([popup.boundingBox(), hint.boundingBox()]);
|
||||
return (
|
||||
!!shell &&
|
||||
!!footer &&
|
||||
Math.abs(shell.x - (560 - shell.width) / 2) < 2 &&
|
||||
shell.x >= 14 &&
|
||||
footer.y + footer.height <= shell.y + shell.height + 1
|
||||
);
|
||||
})
|
||||
.toBe(true);
|
||||
await expect.poll(() => results.evaluate((el) => el.scrollHeight > el.clientHeight)).toBe(true);
|
||||
|
||||
await field.fill("verify");
|
||||
await field.press("ArrowDown");
|
||||
await expect(field).toHaveValue("npm run verify-1");
|
||||
const selected = results.getByRole("option", { selected: true });
|
||||
await expect(selected).toContainText("Verify checkout configuration 1");
|
||||
await expect(field).toHaveAttribute("aria-activedescendant", (await selected.getAttribute("id"))!);
|
||||
await field.press("Tab");
|
||||
await expect(field).toHaveValue("npm run verify-1");
|
||||
await expect(field).toBeFocused();
|
||||
await field.press("Shift+Tab");
|
||||
const history = popup.getByRole("button", { name: "Clear History" });
|
||||
await expect(history).toBeFocused();
|
||||
await history.press("Enter");
|
||||
await expect(history).toBeHidden();
|
||||
await expect(field).toBeFocused();
|
||||
await field.press("ArrowDown");
|
||||
await field.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect(page.locator("body")).toHaveAttribute("data-run-anything-command", "npm run verify-1");
|
||||
});
|
||||
@@ -1,61 +1,67 @@
|
||||
.popup {
|
||||
width: 620px;
|
||||
max-width: calc(100vw - 32px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(670px, calc(100vw - 32px));
|
||||
overflow: hidden;
|
||||
}
|
||||
.body {
|
||||
flex: 1 1 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
font-family: var(--font-ui);
|
||||
}
|
||||
.header {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
height: var(--h-row);
|
||||
padding: 4px 10px 0;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
min-height: var(--h-field);
|
||||
padding: var(--space-0-5) var(--space-3);
|
||||
border-bottom: 1px solid var(--border-popup);
|
||||
background: var(--bg-frame, var(--bg-app));
|
||||
}
|
||||
.title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: var(--fs-ui);
|
||||
font-weight: 600;
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.link {
|
||||
flex: none;
|
||||
max-width: 50%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--link);
|
||||
font: inherit;
|
||||
font-size: var(--fs-small);
|
||||
cursor: pointer;
|
||||
}
|
||||
.link:hover {
|
||||
color: var(--link-hover);
|
||||
}
|
||||
.inputRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid var(--border-popup);
|
||||
}
|
||||
.inputIcon {
|
||||
.query {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.input {
|
||||
flex: 1;
|
||||
font-family: var(--font-ui);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
.rows {
|
||||
max-height: 360px;
|
||||
height: auto;
|
||||
flex: 1 1 auto;
|
||||
min-height: var(--h-row);
|
||||
max-height: 600px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
gap: 10px;
|
||||
gap: var(--space-3);
|
||||
padding: 0;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
@@ -93,23 +99,35 @@
|
||||
.detail {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
max-width: 45%;
|
||||
max-width: min(36%, 26ch);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-style: italic;
|
||||
margin-left: auto;
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.activeRow .detail {
|
||||
color: var(--fg);
|
||||
}
|
||||
.empty {
|
||||
padding: 6px 10px;
|
||||
padding: var(--space-1) var(--space-3) var(--space-2);
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.footer {
|
||||
padding: 6px 10px;
|
||||
flex: none;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-0-5) var(--space-3);
|
||||
padding: var(--space-1-5) var(--space-3);
|
||||
border-top: 1px solid var(--border-popup);
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.navigationHint {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
@@ -4,14 +4,15 @@
|
||||
* the selected entry, or the line itself: a provider that claims it, else the
|
||||
* shell in the project directory, its output in the Run tool window.
|
||||
*/
|
||||
import { useMemo, useState, type KeyboardEvent } from "react";
|
||||
import { useId, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import { create } from "zustand";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { Icon, Input, List, Popup, T, listNavigate } from "@/ui";
|
||||
import { Icon, Kbd, List, Popup, SearchField, T, firstSelectable, listNavigate } from "@/ui";
|
||||
import { runAnythingProviderList } from "@/workbench/contributions";
|
||||
import { useRowHeight } from "@/ui/density";
|
||||
import { buildRows, clearHistory, pushHistory, readHistory, shellRunConfig, type Row } from "./model";
|
||||
import styles from "./RunAnything.module.css";
|
||||
|
||||
@@ -44,8 +45,13 @@ export function RunAnythingHost() {
|
||||
}
|
||||
|
||||
const isSection = (r: Row) => r.kind === "section";
|
||||
const ROW_HEIGHT = 24;
|
||||
const commandAnchor = { getBoundingClientRect: () => new DOMRect(window.innerWidth / 2, 72, 0, 0) };
|
||||
|
||||
function RunAnythingPopup({ root }: { root: string }) {
|
||||
const field = useRef<HTMLInputElement>(null);
|
||||
const rowHeight = useRowHeight(ROW_HEIGHT);
|
||||
const listId = useId();
|
||||
const [line, setLine] = useState("");
|
||||
const [active, setActive] = useState(-1);
|
||||
const [history, setHistory] = useState(() => readHistory(root));
|
||||
@@ -57,6 +63,10 @@ function RunAnythingPopup({ root }: { root: string }) {
|
||||
}),
|
||||
[line, history],
|
||||
);
|
||||
const selected = rows[active];
|
||||
const first = firstSelectable(rows, isSection);
|
||||
const hasRows = first >= 0;
|
||||
const command = selected?.kind === "item" ? (selected.item.completion ?? selected.item.label) : line;
|
||||
|
||||
const run = (row: Row | undefined) => {
|
||||
if (!row || row.kind !== "item") return;
|
||||
@@ -75,21 +85,25 @@ function RunAnythingPopup({ root }: { root: string }) {
|
||||
setActive(-1);
|
||||
};
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.nativeEvent.isComposing || e.altKey || e.ctrlKey || e.metaKey) return;
|
||||
if (["ArrowDown", "ArrowUp", "PageDown", "PageUp"].includes(e.key)) {
|
||||
const next = listNavigate(e.key, { items: rows, active: Math.max(active, 0), wrap: true, isSection });
|
||||
if (next !== null) {
|
||||
const height = e.currentTarget.ownerDocument.getElementById(listId)?.clientHeight ?? rowHeight;
|
||||
const pageSize = Math.max(1, Math.floor(height / rowHeight) - 1);
|
||||
const next = listNavigate(e.key, { items: rows, active, wrap: true, isSection, pageSize });
|
||||
if (next !== null && hasRows) {
|
||||
e.preventDefault();
|
||||
setActive(active < 0 && e.key === "ArrowDown" ? rows.findIndex((r) => !isSection(r)) : next);
|
||||
setActive(next < 0 ? first : next);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e.key === "Tab") {
|
||||
if (e.key === "Tab" && !e.shiftKey && hasRows) {
|
||||
e.preventDefault();
|
||||
complete(rows[active >= 0 ? active : rows.findIndex((r) => !isSection(r))]);
|
||||
e.stopPropagation();
|
||||
complete(selected ?? rows[first]);
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (active >= 0) run(rows[active]);
|
||||
if (selected) run(selected);
|
||||
else runLine();
|
||||
}
|
||||
};
|
||||
@@ -97,7 +111,7 @@ function RunAnythingPopup({ root }: { root: string }) {
|
||||
return (
|
||||
<Popup
|
||||
open
|
||||
anchor={{ x: window.innerWidth / 2, y: 72 }}
|
||||
anchor={commandAnchor}
|
||||
placement="bottom"
|
||||
onClose={close}
|
||||
role="dialog"
|
||||
@@ -117,58 +131,83 @@ function RunAnythingPopup({ root }: { root: string }) {
|
||||
onClick={() => {
|
||||
clearHistory(root);
|
||||
setHistory([]);
|
||||
setActive(-1);
|
||||
field.current?.focus();
|
||||
}}
|
||||
>
|
||||
<T>Clear History</T>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.inputRow}>
|
||||
<Icon name="run-anything" size={16} className={styles.inputIcon} />
|
||||
<Input
|
||||
<div className={styles.query}>
|
||||
<SearchField
|
||||
ref={field}
|
||||
data-autofocus
|
||||
variant="bare"
|
||||
className={styles.input}
|
||||
value={line}
|
||||
leadingIcon="run-anything"
|
||||
clearable={false}
|
||||
role="combobox"
|
||||
aria-autocomplete="list"
|
||||
aria-expanded={hasRows}
|
||||
aria-controls={hasRows ? listId : undefined}
|
||||
aria-activedescendant={selected?.kind === "item" ? `${listId}-${active}` : undefined}
|
||||
value={command}
|
||||
placeholder="Run a command, configuration or goal"
|
||||
aria-label="Command line"
|
||||
onChange={(e) => {
|
||||
setLine(e.target.value);
|
||||
onChange={(value) => {
|
||||
setLine(value);
|
||||
setActive(-1);
|
||||
}}
|
||||
onKeyDown={onKeyDown}
|
||||
/>
|
||||
</div>
|
||||
<List
|
||||
items={rows}
|
||||
getKey={(r) => r.key}
|
||||
isSection={isSection}
|
||||
renderSection={(r) => <div className={styles.section}>{r.kind === "section" && <T>{r.label}</T>}</div>}
|
||||
activeIndex={active}
|
||||
onActiveChange={setActive}
|
||||
onActivate={(r) => run(r)}
|
||||
focusable={false}
|
||||
hoverSelects={false}
|
||||
className={styles.rows}
|
||||
aria-label="Run Anything entries"
|
||||
empty={
|
||||
<div className={styles.empty}>
|
||||
{line.trim() ? <T>Press Enter to run the command in the project directory</T> : <T>Type a command</T>}
|
||||
{hasRows ? (
|
||||
<>
|
||||
<List
|
||||
id={listId}
|
||||
items={rows}
|
||||
getKey={(r) => r.key}
|
||||
isSection={isSection}
|
||||
renderSection={(r) => <div className={styles.section}>{r.kind === "section" && <T>{r.label}</T>}</div>}
|
||||
activeIndex={active}
|
||||
onActiveChange={setActive}
|
||||
onActivate={(r) => run(r)}
|
||||
focusable={false}
|
||||
hoverSelects={false}
|
||||
rowHeight={rowHeight}
|
||||
className={styles.rows}
|
||||
aria-label="Run Anything entries"
|
||||
renderItem={(r, state) =>
|
||||
r.kind === "item" ? (
|
||||
<div className={clsx(styles.row, state.active && styles.activeRow)}>
|
||||
<Icon name={r.item.icon ?? "run"} size={16} className={styles.rowIcon} />
|
||||
<span className={styles.label} title={r.item.label}>
|
||||
{r.item.label}
|
||||
</span>
|
||||
{r.item.detail && (
|
||||
<span className={styles.detail} title={r.item.detail}>
|
||||
{r.item.detail}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
<div className={styles.footer}>
|
||||
<span className={styles.navigationHint}>
|
||||
<Kbd>↑</Kbd>
|
||||
<Kbd>↓</Kbd>
|
||||
<T>Navigate</T>
|
||||
</span>
|
||||
<T>Tab to complete, Enter to run</T>
|
||||
</div>
|
||||
}
|
||||
renderItem={(r, state) =>
|
||||
r.kind === "item" ? (
|
||||
<div className={clsx(styles.row, state.active && styles.activeRow)}>
|
||||
<Icon name={r.item.icon ?? "run"} size={16} className={styles.rowIcon} />
|
||||
<span className={styles.label}>{r.item.label}</span>
|
||||
{r.item.detail && <span className={styles.detail}>{r.item.detail}</span>}
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
<div className={styles.footer}>
|
||||
<T>Enter to run, Tab to complete. Other commands run in the project directory.</T>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
line.trim() && (
|
||||
<div className={styles.empty}>
|
||||
<T>Press Enter to run the command in the project directory</T>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</Popup>
|
||||
);
|
||||
|
||||
@@ -2915,8 +2915,6 @@
|
||||
"Run a command, configuration or goal": "Ejecutar un comando, configuración o meta",
|
||||
"Run Anything entries": "Entradas de Ejecutar cualquier cosa",
|
||||
"Press Enter to run the command in the project directory": "Presiona Enter para ejecutar el comando en el directorio del proyecto",
|
||||
"Type a command": "Escribe un comando",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "Enter para ejecutar, Tab para completar. Otros comandos se ejecutan en el directorio del proyecto.",
|
||||
"Recent": "Recientes",
|
||||
"Search types": "Buscar tipos",
|
||||
"Search configuration types": "Buscar tipos de configuración",
|
||||
|
||||
@@ -2815,8 +2815,6 @@
|
||||
"Run a command, configuration or goal": "Exécuter une commande, une configuration ou un goal",
|
||||
"Run Anything entries": "Entrées d'Exécuter n'importe quoi",
|
||||
"Press Enter to run the command in the project directory": "Appuyez sur Entrée pour exécuter la commande dans le répertoire du projet",
|
||||
"Type a command": "Saisissez une commande",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "Entrée pour exécuter, Tab pour compléter. Les autres commandes s'exécutent dans le répertoire du projet.",
|
||||
"Recent": "Récents",
|
||||
"Search types": "Rechercher des types",
|
||||
"Search configuration types": "Rechercher des types de configuration",
|
||||
|
||||
@@ -2965,8 +2965,6 @@
|
||||
"Run a command, configuration or goal": "명령, 구성 또는 목표 실행",
|
||||
"Run Anything entries": "무엇이든 실행 항목",
|
||||
"Press Enter to run the command in the project directory": "Enter를 눌러 프로젝트 디렉터리에서 명령을 실행하세요",
|
||||
"Type a command": "명령 입력",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "Enter로 실행, Tab으로 완성합니다. 그 밖의 명령은 프로젝트 디렉터리에서 실행됩니다.",
|
||||
"Recent": "최근",
|
||||
"Search types": "유형 검색",
|
||||
"Search configuration types": "구성 유형 검색",
|
||||
|
||||
@@ -2887,8 +2887,6 @@
|
||||
"Run a command, configuration or goal": "Uruchom polecenie, konfigurację lub cel",
|
||||
"Run Anything entries": "Wpisy funkcji 'Uruchom cokolwiek'",
|
||||
"Press Enter to run the command in the project directory": "Naciśnij Enter, aby uruchomić polecenie w katalogu projektu",
|
||||
"Type a command": "Wpisz polecenie",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "Enter, aby uruchomić, Tab, aby uzupełnić. Inne polecenia uruchamiają się w katalogu projektu.",
|
||||
"Recent": "Niedawne",
|
||||
"Search types": "Szukaj typów",
|
||||
"Search configuration types": "Szukaj typów konfiguracji",
|
||||
|
||||
@@ -2888,8 +2888,6 @@
|
||||
"Run a command, configuration or goal": "Executar um comando, configuração ou meta",
|
||||
"Run Anything entries": "Entradas de Executar qualquer coisa",
|
||||
"Press Enter to run the command in the project directory": "Pressione Enter para executar o comando no diretório do projeto",
|
||||
"Type a command": "Digite um comando",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "Enter para executar, Tab para completar. Outros comandos são executados no diretório do projeto.",
|
||||
"Recent": "Recentes",
|
||||
"Search types": "Pesquisar tipos",
|
||||
"Search configuration types": "Pesquisar tipos de configuração",
|
||||
|
||||
@@ -3706,8 +3706,6 @@
|
||||
"Run a command, configuration or goal": "运行命令、配置或目标",
|
||||
"Run Anything entries": "“运行任何内容”条目",
|
||||
"Press Enter to run the command in the project directory": "按 Enter 在项目目录中运行命令",
|
||||
"Type a command": "输入命令",
|
||||
"Enter to run, Tab to complete. Other commands run in the project directory.": "按 Enter 运行,按 Tab 补全。其他命令将在项目目录中运行。",
|
||||
"Recent": "最近",
|
||||
"Search types": "搜索类型",
|
||||
"Search configuration types": "搜索配置类型",
|
||||
|
||||
Reference in new issue
Block a user