mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(search): improve structural template layout (#5298)
- Put the language picker in the Search template header and keep each label next to its template. - Give both templates 150 px of editing space in a standard window. Tighten the editors on shorter screens and keep the dialog footer accessible. - Use the configured editor font, size, and line height in both templates.
This commit is contained in:
@@ -231,21 +231,39 @@
|
||||
flex: 1 1 12ch;
|
||||
min-width: 0;
|
||||
}
|
||||
.templateSection {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
color: var(--fg);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.templateHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.languageSelect {
|
||||
min-width: 180px;
|
||||
max-width: 50%;
|
||||
}
|
||||
.template {
|
||||
width: 100%;
|
||||
min-height: 96px;
|
||||
height: clamp(96px, 24vh, 150px);
|
||||
min-height: 50px;
|
||||
resize: vertical;
|
||||
padding: 6px 8px;
|
||||
padding: var(--space-1-5) var(--space-2);
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: var(--radius-control);
|
||||
background: var(--bg-input);
|
||||
background: var(--bg-editor);
|
||||
color: var(--fg-editor);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-code);
|
||||
line-height: 1.5;
|
||||
line-height: var(--lh-code);
|
||||
}
|
||||
.replaceForm .template {
|
||||
/* Leave room for the scope and dialog controls when both templates are shown. */
|
||||
height: clamp(96px, calc(50vh - 205px), 150px);
|
||||
}
|
||||
.template:focus {
|
||||
outline: none;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** Inspect Code, Locate Duplicates and Search / Replace Structurally dialogs. */
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import {
|
||||
call,
|
||||
commands,
|
||||
@@ -10,6 +11,8 @@ import {
|
||||
type WorkspaceEdit,
|
||||
} from "@/platform/ipc";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { editorPrefs } from "@/platform/editorSettings";
|
||||
import { monoFontFamily } from "@/platform/fonts";
|
||||
import { activeProfileId, listProfiles, validateInspections, type ProfileId } from "@/platform/inspections";
|
||||
import { basename, relativePath, useProject } from "@/platform/project";
|
||||
import { Button, Checkbox, Dialog, Input, Select, Spinner, T } from "@/ui";
|
||||
@@ -319,6 +322,15 @@ function StructuralDialog({ replace, onClose }: { replace: boolean; onClose: ()
|
||||
const [form, setForm] = useState<StructuralForm>(loadStructuralForm);
|
||||
const [scope, setScope] = useState<ScopeChoice>(() => defaultScope());
|
||||
const [busy, setBusy] = useState(false);
|
||||
const settings = useProject((s) => s.settings);
|
||||
const font = settings?.editor;
|
||||
const fallback = editorPrefs(settings).fallbackFont;
|
||||
const templateFont = {
|
||||
fontFamily:
|
||||
font?.fontFamily || fallback ? monoFontFamily(font?.fontFamily, fallback, "var(--font-mono)") : undefined,
|
||||
fontSize: font?.fontSize ?? undefined,
|
||||
lineHeight: font?.lineHeight != null ? `${font.lineHeight}px` : undefined,
|
||||
};
|
||||
const languages = useStructuralLanguages();
|
||||
// The editor's language when it has a grammar, else the first supported one.
|
||||
const language =
|
||||
@@ -357,47 +369,49 @@ function StructuralDialog({ replace, onClose }: { replace: boolean; onClose: ()
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<div className={styles.form}>
|
||||
<div className={styles.fieldRow}>
|
||||
<span>
|
||||
<T>Language</T>
|
||||
</span>
|
||||
<Select
|
||||
value={language || null}
|
||||
options={options}
|
||||
onChange={(language) => setForm({ ...form, language })}
|
||||
placeholder={languages ? "No languages" : "Loading…"}
|
||||
className={styles.languageSelect}
|
||||
aria-label="Language"
|
||||
<div className={clsx(styles.form, replace && styles.replaceForm)}>
|
||||
<div className={styles.templateSection}>
|
||||
<div className={styles.templateHeader}>
|
||||
<label htmlFor="ssr-template">
|
||||
<T>Search template</T>
|
||||
</label>
|
||||
<Select
|
||||
value={language || null}
|
||||
options={options}
|
||||
onChange={(language) => setForm({ ...form, language })}
|
||||
placeholder={languages ? "No languages" : "Loading…"}
|
||||
className={styles.languageSelect}
|
||||
variant="ghost"
|
||||
aria-label="Language"
|
||||
/>
|
||||
</div>
|
||||
<textarea
|
||||
id="ssr-template"
|
||||
className={styles.template}
|
||||
style={templateFont}
|
||||
spellCheck={false}
|
||||
value={form.pattern}
|
||||
placeholder="$a$.equals($b$)"
|
||||
onChange={(e) => setForm({ ...form, pattern: e.target.value })}
|
||||
data-autofocus=""
|
||||
/>
|
||||
{error && <div className={styles.error}>{error}</div>}
|
||||
</div>
|
||||
<label className={styles.fieldLabel} htmlFor="ssr-template">
|
||||
<T>Search template</T>
|
||||
</label>
|
||||
<textarea
|
||||
id="ssr-template"
|
||||
className={styles.template}
|
||||
spellCheck={false}
|
||||
value={form.pattern}
|
||||
placeholder="$a$.equals($b$)"
|
||||
onChange={(e) => setForm({ ...form, pattern: e.target.value })}
|
||||
data-autofocus=""
|
||||
/>
|
||||
{error && <div className={styles.error}>{error}</div>}
|
||||
{replace && (
|
||||
<>
|
||||
<label className={styles.fieldLabel} htmlFor="ssr-replacement">
|
||||
<div className={styles.templateSection}>
|
||||
<label htmlFor="ssr-replacement">
|
||||
<T>Replace template</T>
|
||||
</label>
|
||||
<textarea
|
||||
id="ssr-replacement"
|
||||
className={styles.template}
|
||||
style={templateFont}
|
||||
spellCheck={false}
|
||||
value={form.replacement}
|
||||
placeholder="Objects.equals($a$, $b$)"
|
||||
onChange={(e) => setForm({ ...form, replacement: e.target.value })}
|
||||
/>
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.hint}>
|
||||
<T>Placeholders:</T> <code>$name$</code> or <code>$NAME</code> <T>match one node,</T> <code>$$$NAME</code>{" "}
|
||||
|
||||
Reference in New Issue
Block a user