M2.4: Find tool window in a new bottom panel

- Bottom panel under editor and project tree (resizable, collapsible,
  closable) for Find and later tool windows.
- Find store: search.find with options and include/exclude globs, results
  streamed and sorted by file, events held until the searchId answer, a
  new search cancels the running one, refused queries shown in place.
- Find tool window: toggles, counts, cancel, truncated hint, highlighted
  previews, keyboard navigation, Enter or click runs editor.reveal.
- UI command find.open (Mod+Alt+F) with prefill from the selection or the
  word at the cursor; find.open {query} from agents searches at once.
- 26 Vitest tests; progress docs and architecture updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-17 12:42:53 +02:00
parent 864a468b34
commit 097bbd9409
16 changed files with 1923 additions and 25 deletions

View file

@ -0,0 +1,566 @@
<script setup lang="ts">
/**
* The Find tool window (M2.4), shown in the bottom panel: a query field
* with case, whole-word and regex toggles, include and exclude globs
* (comma-separated), a status line with counts, and the results grouped by
* file with the match highlighted in the line preview.
*
* - **Searching:** Enter in any field or the search button starts a search;
* toggling an option repeats the last one. The cancel button stops a
* running search. A refused query (bad regex or glob) shows its message
* under the fields.
* - **Results:** a listbox of matches; Up/Down, Page Up/Down, Home and End
* move the selection, Down in a field moves into the list. Enter or a
* click opens the match through the command `editor.reveal`.
* - State lives in the Find store (`stores/find.ts`), so the results survive
* closing the panel.
*/
import { CaseSensitive, CircleStop, Regex, Search, WholeWord } from "@lucide/vue";
import { computed, nextTick, onMounted, ref, watch } from "vue";
import { useCommandsStore } from "../../commands/store";
import { t } from "../../i18n";
import { baseName } from "../../stores/editor";
import { useFindStore, type FindMatch, type FindRow } from "../../stores/find";
const find = useFindStore();
const commands = useCommandsStore();
/** The query field. */
const queryInput = ref<HTMLInputElement | null>(null);
/** The result list. */
const list = ref<HTMLElement | null>(null);
/** Rows moved by Page Up and Page Down. */
const PAGE = 10;
/** The status line under the fields. */
const status = computed(() => {
const counts = { matches: String(find.matchCount), files: String(find.files.length) };
if (find.running) {
return t("find.status.running", counts);
}
const done = find.summary;
if (!done) {
return find.error === null ? t("find.status.idle") : "";
}
const totals = { matches: String(done.matches), files: String(done.files), ms: String(done.elapsedMs) };
if (done.cancelled) {
return t("find.status.cancelled", totals);
}
return done.matches === 0 ? t("find.status.none") : t("find.status.done", totals);
});
/**
* The DOM id of a row's option element.
*
* @param index - the row's index in the flat list.
*/
function optionId(index: number): string {
return `find-row-${String(index)}`;
}
/** A file with its rows and their indexes in the flat list. */
interface FindGroup {
/** Project-relative path. */
path: string;
/** The file's rows with their flat index. */
rows: { row: FindRow; index: number }[];
}
/** The rows grouped by file, in display order. */
const groups = computed<FindGroup[]>(() => {
const out: FindGroup[] = [];
find.rows.forEach((row, index) => {
const last = out[out.length - 1];
if (last?.path === row.path) {
last.rows.push({ row, index });
} else {
out.push({ path: row.path, rows: [{ row, index }] });
}
});
return out;
});
/**
* The preview split around the match, without leading indentation.
*
* @param match - the match.
* @returns the text before, the match and the text after.
*/
function parts(match: FindMatch): { before: string; hit: string; after: string } {
const text = match.preview;
const lead = Math.min(text.length - text.trimStart().length, match.previewColumn);
const end = Math.min(text.length, match.previewColumn + match.length);
return {
before: text.slice(lead, match.previewColumn),
hit: text.slice(match.previewColumn, end),
after: text.slice(end),
};
}
/**
* The directory part of a path, empty at the root.
*
* @param path - project-relative path.
*/
function dirName(path: string): string {
const slash = path.lastIndexOf("/");
return slash < 0 ? "" : path.slice(0, slash);
}
/**
* Opens a match in the editor.
*
* @param row - the row.
*/
function openRow(row: FindRow): void {
find.select(row.key);
void commands.execute("editor.reveal", { path: row.path, line: row.match.line, column: row.match.column });
}
/** Starts a search for the fields' current values. */
function submit(): void {
void find.search();
}
/**
* Toggles an option and repeats the last search, if there was one.
*
* @param option - which option.
*/
function toggle(option: "caseSensitive" | "wholeWord" | "regex"): void {
find[option] = !find[option];
if (find.query !== "" && (find.running || find.summary !== null || find.error !== null)) {
void find.search();
}
}
/**
* Moves from a field into the result list.
*
* @param event - the key event.
*/
function onFieldKey(event: KeyboardEvent): void {
if (event.key === "ArrowDown" && find.rows.length > 0) {
event.preventDefault();
if (find.selectedIndex < 0) {
find.move(1);
}
list.value?.focus();
}
}
/**
* Keyboard navigation in the result list.
*
* @param event - the key event.
*/
function onListKey(event: KeyboardEvent): void {
const moves: Record<string, number> = {
ArrowDown: 1,
ArrowUp: -1,
PageDown: PAGE,
PageUp: -PAGE,
Home: -Infinity,
End: Infinity,
};
const delta = moves[event.key];
if (delta !== undefined) {
event.preventDefault();
find.move(Number.isFinite(delta) ? delta : delta > 0 ? find.rows.length : -find.rows.length);
} else if (event.key === "Enter") {
const row = find.rows[find.selectedIndex];
if (row) {
event.preventDefault();
openRow(row);
}
}
}
/** Focuses and selects the query field. */
async function focusQuery(): Promise<void> {
await nextTick();
queryInput.value?.focus();
queryInput.value?.select();
}
watch(() => find.focusRequest, focusQuery);
watch(
() => find.selectedIndex,
async (index) => {
await nextTick();
const element = index < 0 ? null : document.getElementById(optionId(index));
if (element && typeof element.scrollIntoView === "function") {
element.scrollIntoView({ block: "nearest" });
}
},
);
onMounted(() => {
void focusQuery();
});
</script>
<template>
<div
class="find"
data-test="find"
>
<form
class="find__form"
@submit.prevent="submit"
>
<div class="find__line">
<span class="find__field find__field--query">
<Search
:size="14"
class="find__icon"
/>
<input
ref="queryInput"
v-model="find.query"
class="find__input"
type="text"
spellcheck="false"
:aria-label="t('find.query.label')"
:placeholder="t('find.query.placeholder')"
:aria-invalid="find.error !== null"
data-test="find-query"
@keydown="onFieldKey"
>
<button
type="button"
class="find__toggle"
:aria-pressed="find.caseSensitive"
:title="t('find.option.caseSensitive')"
:aria-label="t('find.option.caseSensitive')"
data-test="find-case"
@click="toggle('caseSensitive')"
>
<CaseSensitive :size="16" />
</button>
<button
type="button"
class="find__toggle"
:aria-pressed="find.wholeWord"
:title="t('find.option.wholeWord')"
:aria-label="t('find.option.wholeWord')"
data-test="find-word"
@click="toggle('wholeWord')"
>
<WholeWord :size="16" />
</button>
<button
type="button"
class="find__toggle"
:aria-pressed="find.regex"
:title="t('find.option.regex')"
:aria-label="t('find.option.regex')"
data-test="find-regex"
@click="toggle('regex')"
>
<Regex :size="16" />
</button>
</span>
<button
v-if="find.running"
type="button"
class="find__action"
data-test="find-cancel"
@click="find.cancel()"
>
<CircleStop :size="14" />
{{ t("common.cancel") }}
</button>
<button
v-else
type="submit"
class="find__action"
data-test="find-submit"
>
{{ t("find.action.search") }}
</button>
</div>
<div class="find__line">
<span class="find__field">
<input
v-model="find.include"
class="find__input"
type="text"
spellcheck="false"
:aria-label="t('find.include.label')"
:placeholder="t('find.include.placeholder')"
data-test="find-include"
@keydown="onFieldKey"
>
</span>
<span class="find__field">
<input
v-model="find.exclude"
class="find__input"
type="text"
spellcheck="false"
:aria-label="t('find.exclude.label')"
:placeholder="t('find.exclude.placeholder')"
data-test="find-exclude"
@keydown="onFieldKey"
>
</span>
</div>
</form>
<div
class="find__status"
role="status"
data-test="find-status"
>
<span>{{ status }}</span>
<span
v-if="find.summary?.truncated"
class="find__truncated"
data-test="find-truncated"
>{{ t("find.status.truncated", { matches: String(find.summary.matches) }) }}</span>
</div>
<div
v-if="find.error"
class="find__error"
role="alert"
data-test="find-error"
>
{{ find.error }}
</div>
<div
ref="list"
class="find__results"
role="listbox"
tabindex="0"
:aria-label="t('find.results.label')"
:aria-activedescendant="find.selectedIndex >= 0 ? optionId(find.selectedIndex) : undefined"
data-test="find-results"
@keydown="onListKey"
>
<div
v-for="group in groups"
:key="group.path"
role="group"
:aria-label="group.path"
class="find__file"
>
<div
class="find__file-header"
data-test="find-file"
>
<span class="find__file-name">{{ baseName(group.path) }}</span>
<span class="find__file-dir">{{ dirName(group.path) }}</span>
<span class="find__file-count">{{ group.rows.length }}</span>
</div>
<div
v-for="{ row, index } in group.rows"
:id="optionId(index)"
:key="row.key"
role="option"
class="find__row"
:class="{ 'find__row--selected': find.selectedKey === row.key }"
:aria-selected="find.selectedKey === row.key"
data-test="find-row"
@click="openRow(row)"
>
<span class="find__line-number">{{ row.match.line + 1 }}</span>
<span class="find__preview">{{ parts(row.match).before }}<mark
class="find__hit"
data-test="find-hit"
>{{ parts(row.match).hit }}</mark>{{ parts(row.match).after }}</span>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.find {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
}
.find__form {
display: flex;
flex-direction: column;
gap: var(--lt-space-s, 4px);
padding: var(--lt-space-s, 4px) var(--lt-space-m, 8px);
}
.find__line {
display: flex;
gap: var(--lt-space-s, 4px);
}
.find__field {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
gap: var(--lt-space-xs, 2px);
padding: 0 var(--lt-space-xs, 2px) 0 var(--lt-space-s, 4px);
background: var(--lt-editor-bg);
border: 1px solid var(--lt-border);
border-radius: var(--lt-radius, 4px);
}
.find__field:focus-within {
border-color: var(--lt-accent);
}
.find__icon {
flex: none;
color: var(--lt-fg-muted);
}
.find__input {
flex: 1;
min-width: 0;
padding: var(--lt-space-xs, 2px);
font: inherit;
color: var(--lt-fg);
background: transparent;
border: none;
outline: none;
}
.find__input::placeholder {
color: var(--lt-fg-muted);
}
.find__toggle {
display: inline-flex;
align-items: center;
justify-content: center;
padding: var(--lt-space-xs, 2px);
color: var(--lt-fg-muted);
background: transparent;
border: 1px solid transparent;
border-radius: var(--lt-radius, 4px);
cursor: pointer;
}
.find__toggle:hover {
color: var(--lt-fg);
}
.find__toggle[aria-pressed="true"] {
color: var(--lt-fg);
background: var(--lt-editor-match-bg);
border-color: var(--lt-accent);
}
.find__toggle:focus-visible,
.find__action:focus-visible {
outline: 2px solid var(--lt-accent);
}
.find__action {
display: inline-flex;
align-items: center;
gap: var(--lt-space-xs, 2px);
padding: 0 var(--lt-space-m, 8px);
font: inherit;
color: var(--lt-fg);
background: transparent;
border: 1px solid var(--lt-border);
border-radius: var(--lt-radius, 4px);
cursor: pointer;
}
.find__status {
display: flex;
gap: var(--lt-space-m, 8px);
padding: 0 var(--lt-space-m, 8px) var(--lt-space-s, 4px);
color: var(--lt-fg-muted);
}
.find__truncated {
color: var(--lt-fg);
}
.find__error {
padding: var(--lt-space-xs, 2px) var(--lt-space-m, 8px);
color: var(--lt-fg);
background: color-mix(in srgb, var(--lt-error) 15%, var(--lt-bg));
}
.find__results {
flex: 1;
min-height: 0;
overflow: auto;
border-top: 1px solid var(--lt-border);
outline: none;
}
.find__results:focus-visible {
box-shadow: inset 0 0 0 1px var(--lt-accent);
}
.find__file-header {
display: flex;
align-items: baseline;
gap: var(--lt-space-m, 8px);
padding: var(--lt-space-xs, 2px) var(--lt-space-m, 8px);
white-space: nowrap;
}
.find__file-name {
font-weight: 600;
}
.find__file-dir {
overflow: hidden;
text-overflow: ellipsis;
color: var(--lt-fg-muted);
}
.find__file-count {
margin-left: auto;
color: var(--lt-fg-muted);
}
.find__row {
display: flex;
gap: var(--lt-space-m, 8px);
padding: 0 var(--lt-space-m, 8px) 0 var(--lt-space-l, 24px);
font-family: var(--lt-font-mono);
white-space: pre;
cursor: pointer;
}
.find__row:hover {
background: color-mix(in srgb, var(--lt-fg) 6%, transparent);
}
.find__row--selected,
.find__row--selected:hover {
background: var(--lt-editor-selection-bg);
}
.find__line-number {
flex: none;
min-width: 4ch;
text-align: right;
color: var(--lt-fg-muted);
}
.find__row--selected .find__line-number {
color: var(--lt-fg);
}
.find__preview {
overflow: hidden;
text-overflow: ellipsis;
}
.find__hit {
color: var(--lt-fg);
background: var(--lt-editor-match-bg);
border-radius: 2px;
}
</style>

View file

@ -0,0 +1,239 @@
<script setup lang="ts">
/**
* The bottom panel of the main window: a tool window docked under the
* editor (Find since M2.4; later Problems, Terminal and others). A header
* with the title, a collapse/expand button and a close button, the content
* slot, and a splitter on the top edge to resize it.
*
* The splitter is dragged with the pointer or moved with Up/Down (Shift for
* larger steps) when focused. Collapsed, only the header shows. Height and
* expansion are view state, emitted through `v-model:height` and
* `v-model:open`; the close button emits `close`, and the owner decides
* what closing means.
*/
import { ChevronDown, ChevronUp, X } from "@lucide/vue";
import { computed } from "vue";
import { t } from "../../i18n";
/** Props of the bottom panel. */
const props = withDefaults(
defineProps<{
/** Title shown in the header and as the accessible name. */
title: string;
/** Height of the content in CSS pixels, header excluded. */
height?: number;
/** Smallest height the splitter allows. */
minHeight?: number;
/** Largest height the splitter allows. */
maxHeight?: number;
/** Whether the panel is expanded (true) or collapsed to its header. */
open?: boolean;
}>(),
{ height: 240, minHeight: 80, maxHeight: 900, open: true },
);
/** Events of the bottom panel. */
const emit = defineEmits<{
/** New height after a resize. */
"update:height": [height: number];
/** New expansion after collapse or expand. */
"update:open": [open: boolean];
/** The close button was pressed. */
close: [];
}>();
/** Inline style carrying the current height. */
const bodyStyle = computed(() => ({ height: `${String(props.height)}px` }));
/**
* Emits a height clamped to the allowed range.
*
* @param height - the wanted height.
*/
function setHeight(height: number): void {
emit("update:height", Math.round(Math.min(props.maxHeight, Math.max(props.minHeight, height))));
}
/**
* Starts a pointer drag on the splitter; dragging up makes the panel taller.
*
* @param event - the pointer-down event.
*/
function onSplitterDown(event: PointerEvent): void {
const target = event.currentTarget;
if (!(target instanceof HTMLElement)) {
return;
}
const startY = event.clientY;
const startHeight = props.height;
target.setPointerCapture(event.pointerId);
const move = (e: PointerEvent): void => {
setHeight(startHeight - (e.clientY - startY));
};
const up = (e: PointerEvent): void => {
target.releasePointerCapture(e.pointerId);
target.removeEventListener("pointermove", move);
target.removeEventListener("pointerup", up);
};
target.addEventListener("pointermove", move);
target.addEventListener("pointerup", up);
}
/**
* Resizes with the keyboard when the splitter has focus.
*
* @param event - the key event.
*/
function onSplitterKey(event: KeyboardEvent): void {
const step = event.shiftKey ? 48 : 12;
if (event.key === "ArrowUp") {
setHeight(props.height + step);
} else if (event.key === "ArrowDown") {
setHeight(props.height - step);
} else {
return;
}
event.preventDefault();
}
</script>
<template>
<section
class="bottom-panel"
:aria-label="title"
data-test="bottom-panel"
>
<div
v-if="open"
class="bottom-panel__splitter"
role="separator"
aria-orientation="horizontal"
tabindex="0"
:aria-valuenow="height"
:aria-valuemin="minHeight"
:aria-valuemax="maxHeight"
:aria-label="t('common.toolWindow.resize', { title })"
data-test="bottom-panel-splitter"
@pointerdown="onSplitterDown"
@keydown="onSplitterKey"
/>
<header class="bottom-panel__header">
<span class="bottom-panel__title">{{ title }}</span>
<span class="bottom-panel__actions">
<button
type="button"
class="bottom-panel__button"
:title="open ? t('common.toolWindow.collapse', { title }) : t('common.toolWindow.expand', { title })"
:aria-label="open ? t('common.toolWindow.collapse', { title }) : t('common.toolWindow.expand', { title })"
:aria-expanded="open"
data-test="bottom-panel-toggle"
@click="emit('update:open', !open)"
>
<ChevronDown
v-if="open"
:size="16"
/>
<ChevronUp
v-else
:size="16"
/>
</button>
<button
type="button"
class="bottom-panel__button"
:title="t('common.toolWindow.hide', { title })"
:aria-label="t('common.toolWindow.hide', { title })"
data-test="bottom-panel-close"
@click="emit('close')"
>
<X :size="16" />
</button>
</span>
</header>
<div
v-if="open"
class="bottom-panel__body"
:style="bodyStyle"
>
<slot />
</div>
</section>
</template>
<style scoped>
.bottom-panel {
position: relative;
display: flex;
flex-direction: column;
flex: none;
max-height: 75%;
background: var(--lt-bg);
border-top: 1px solid var(--lt-border);
}
.bottom-panel__header {
display: flex;
align-items: center;
justify-content: space-between;
flex: none;
height: var(--lt-header-height, 28px);
padding: 0 var(--lt-space-s, 4px) 0 var(--lt-space-m, 8px);
border-bottom: 1px solid var(--lt-border);
}
.bottom-panel__title {
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bottom-panel__actions {
display: inline-flex;
gap: var(--lt-space-xs, 2px);
}
.bottom-panel__body {
display: flex;
flex-direction: column;
min-height: 0;
flex-shrink: 1;
}
.bottom-panel__button {
display: inline-flex;
align-items: center;
justify-content: center;
padding: var(--lt-space-xs, 2px);
color: var(--lt-fg-muted);
background: transparent;
border: none;
border-radius: var(--lt-radius, 4px);
cursor: pointer;
}
.bottom-panel__button:hover {
color: var(--lt-fg);
background: color-mix(in srgb, var(--lt-fg) 8%, transparent);
}
.bottom-panel__button:focus-visible {
outline: 2px solid var(--lt-accent);
}
.bottom-panel__splitter {
position: absolute;
top: -3px;
right: 0;
left: 0;
height: 6px;
cursor: row-resize;
z-index: 1;
}
.bottom-panel__splitter:hover,
.bottom-panel__splitter:focus-visible {
outline: none;
background: color-mix(in srgb, var(--lt-accent) 50%, transparent);
}
</style>

View file

@ -1,41 +1,60 @@
<script setup lang="ts">
/**
* Layout of the main window: the Project tool window on the left, the
* editor area in the middle and the status bar along the bottom.
* editor area in the middle, the bottom panel under both (M2.4) and the
* status bar along the bottom.
*
* The editor area is a slot so the editor (M1.6) can replace the
* placeholder without touching the layout. The layout supplies the UI
* command `view.toggleProjectTree` (`Mod+1`), which shows or hides the
* Project tool window.
*
* The bottom panel ({@link BottomPanel}) holds the Find tool window. It
* appears with the UI command `find.open` (`Mod+Alt+F`, supplied here so it
* works before the panel exists), collapses to its header and closes from
* its header; the Find store keeps the results while it is closed.
*/
import { onBeforeUnmount, onMounted, ref } from "vue";
import { useCommandsStore } from "../../commands/store";
import { t } from "../../i18n";
import { useFindStore } from "../../stores/find";
import FindToolWindow from "../find/FindToolWindow.vue";
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
import StatusBar from "../StatusBar.vue";
import BottomPanel from "./BottomPanel.vue";
import ToolWindow from "./ToolWindow.vue";
/** Width of the left tool window in CSS pixels. */
const leftWidth = ref(260);
/** Whether the left tool window is shown. */
const leftOpen = ref(true);
/** Height of the bottom panel's content in CSS pixels. */
const bottomHeight = ref(240);
const commands = useCommandsStore();
const find = useFindStore();
/** Withdraws the command handler; set while mounted. */
let withdraw: (() => void) | null = null;
/** Withdraws the command handlers; filled while mounted. */
let withdraw: (() => void)[] = [];
onMounted(() => {
withdraw = commands.provide("view.toggleProjectTree", {
run: () => {
leftOpen.value = !leftOpen.value;
},
});
find.start();
withdraw = [
commands.provide("view.toggleProjectTree", {
run: () => {
leftOpen.value = !leftOpen.value;
},
}),
commands.provide("find.open", { run: (params) => find.open(params) }),
];
});
onBeforeUnmount(() => {
withdraw?.();
withdraw = null;
for (const fn of withdraw) {
fn();
}
withdraw = [];
find.stop();
});
</script>
@ -56,6 +75,15 @@ onBeforeUnmount(() => {
<slot />
</main>
</div>
<BottomPanel
v-if="find.visible"
v-model:height="bottomHeight"
v-model:open="find.expanded"
:title="t('find.toolWindow.title')"
@close="find.hide()"
>
<FindToolWindow />
</BottomPanel>
<StatusBar />
</div>
</template>