M1.15: one modal at a time, restore dialog follows outside restores
- Modal rule (ui/src/commands/modals.ts): palette, settings dialog and the
close question are exclusive; opening one closes the other. Running any
command but palette.open (keyboard, palette, uiCommand) closes the
palette. The restore dialog is queued: hidden while another modal is
open, back with its list intact afterwards.
- recovery.restore / recovery.discard emit recoveryResolved {paths}; the
restore dialog drops the settled paths and closes when none are left.
Rust was needed: discard gave the UI no signal, and a restored entry
stays in the journal as the buffer's own entry.
- Dimmed restored text (C2 screenshot 09) was the dialog overlay, not an
editor style; no editor change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d12a517009
commit
1a38e68480
13 changed files with 442 additions and 12 deletions
89
ui/src/commands/modals.ts
Normal file
89
ui/src/commands/modals.ts
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* The modal rule (M1.15): at most one modal is open at a time.
|
||||
*
|
||||
* - **Exclusive modals:** the command palette, the settings dialog and the
|
||||
* close question of a dirty tab. Opening one closes the one that is open
|
||||
* (the close question closes as Cancel). Each reports itself with
|
||||
* {@link useModalsStore}'s `opened` and `closed`; the close question is
|
||||
* followed from the editor store, so the editor needs no code for it.
|
||||
* - **The restore dialog is queued:** it never closes another modal and is
|
||||
* never closed by one. While an exclusive modal is open it is hidden, and
|
||||
* it shows again, with its list intact, when that modal closes. Its
|
||||
* offer stays until the user decides, so it must not be lost to a
|
||||
* palette opened by an agent.
|
||||
* - **The palette is a launcher:** running any command other than
|
||||
* `palette.open` closes it first (see `store.ts` › `execute`), so a
|
||||
* `uiCommand` from the control channel never leaves it open behind
|
||||
* what the command shows.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, watch } from "vue";
|
||||
import { useEditorStore } from "../stores/editor";
|
||||
|
||||
/** The exclusive modals. */
|
||||
export type ModalId = "palette" | "settings" | "closePrompt";
|
||||
|
||||
/** Store of the open exclusive modal. */
|
||||
export const useModalsStore = defineStore("modals", () => {
|
||||
const editor = useEditorStore();
|
||||
/** The exclusive modal that is open, or null. */
|
||||
const current = ref<ModalId | null>(null);
|
||||
/** Closes {@link current}; set while one is open. */
|
||||
let closeCurrent: (() => void) | null = null;
|
||||
|
||||
/**
|
||||
* Forgets `id` as the open modal; the modal closed itself.
|
||||
*
|
||||
* @param id - the modal.
|
||||
*/
|
||||
function closed(id: ModalId): void {
|
||||
if (current.value === id) {
|
||||
current.value = null;
|
||||
closeCurrent = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes `id` if it is the open modal.
|
||||
*
|
||||
* @param id - the modal.
|
||||
*/
|
||||
function dismiss(id: ModalId): void {
|
||||
if (current.value !== id) {
|
||||
return;
|
||||
}
|
||||
const close = closeCurrent;
|
||||
closed(id);
|
||||
close?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* Records `id` as the open modal and closes the one open before.
|
||||
* Call it before the modal takes the focus, so the closed modal gives
|
||||
* the focus back first.
|
||||
*
|
||||
* @param id - the modal that opens.
|
||||
* @param close - closes it when another modal opens.
|
||||
*/
|
||||
function opened(id: ModalId, close: () => void): void {
|
||||
if (current.value !== null && current.value !== id) {
|
||||
dismiss(current.value);
|
||||
}
|
||||
current.value = id;
|
||||
closeCurrent = close;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => editor.closePrompt !== null,
|
||||
(asking) => {
|
||||
if (asking) {
|
||||
opened("closePrompt", () => void editor.resolveClose("cancel"));
|
||||
} else {
|
||||
closed("closePrompt");
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
return { current, opened, closed, dismiss };
|
||||
});
|
||||
|
|
@ -14,12 +14,15 @@
|
|||
* buffer) with {@link useCommandsStore}'s `provide`. Other engine
|
||||
* commands run with empty params.
|
||||
* - **Errors:** a failed command raises an error toast (M1.12).
|
||||
* - **Palette:** running any command but `palette.open` closes the palette
|
||||
* first (the modal rule, `modals.ts`).
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowReactive } from "vue";
|
||||
import { hasMessage, t } from "../i18n";
|
||||
import { listCommands, onEngineEvent, run, type CommandInfo, type EngineEventPayload, type JsonValue } from "../ipc";
|
||||
import { useNotificationsStore } from "../stores/notifications";
|
||||
import { useModalsStore } from "./modals";
|
||||
import { buildKeymap, commandFor, formatShortcut, isMac } from "./keymap";
|
||||
import { UI_COMMANDS } from "./uiCommands";
|
||||
|
||||
|
|
@ -84,6 +87,7 @@ function labelOf(info: CommandInfo): string {
|
|||
/** Store of the commands, the keymap and the recently run commands. */
|
||||
export const useCommandsStore = defineStore("commands", () => {
|
||||
const notifications = useNotificationsStore();
|
||||
const modals = useModalsStore();
|
||||
/** Commands as the engine lists them; empty until loaded. */
|
||||
const infos = ref<CommandInfo[]>([]);
|
||||
/** Handlers supplied by components, by command id. */
|
||||
|
|
@ -179,7 +183,8 @@ export const useCommandsStore = defineStore("commands", () => {
|
|||
/**
|
||||
* Runs a command the user chose (keyboard or palette): through its
|
||||
* handler if a component supplied one, else through the engine. A
|
||||
* disabled command does nothing. A failure raises an error toast.
|
||||
* disabled command does nothing. A failure raises an error toast. Any
|
||||
* command but `palette.open` closes the palette before it runs.
|
||||
*
|
||||
* @param id - the command id.
|
||||
* @param params - the params.
|
||||
|
|
@ -189,6 +194,9 @@ export const useCommandsStore = defineStore("commands", () => {
|
|||
return;
|
||||
}
|
||||
remember(id);
|
||||
if (id !== "palette.open") {
|
||||
modals.dismiss("palette");
|
||||
}
|
||||
const handler = handlers.get(id);
|
||||
if (handler) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,18 @@
|
|||
* Arrow keys move the selection, Enter runs it, Escape or a click outside
|
||||
* closes. The command runs after the palette closed and gave the focus
|
||||
* back, so a command that asks something (closing a dirty tab) gets it.
|
||||
* Only one modal is open at a time (see `commands/modals.ts`): opening the
|
||||
* palette closes the settings dialog or the close question, and running
|
||||
* any other command, also through a `uiCommand`, closes the palette.
|
||||
*/
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { rank } from "../../commands/rank";
|
||||
import { useModalsStore } from "../../commands/modals";
|
||||
import { useCommandsStore, type PaletteEntry } from "../../commands/store";
|
||||
import { t } from "../../i18n";
|
||||
|
||||
const commands = useCommandsStore();
|
||||
const modals = useModalsStore();
|
||||
|
||||
/** Whether the palette is shown. */
|
||||
const open = ref(false);
|
||||
|
|
@ -44,6 +49,7 @@ watch(query, () => {
|
|||
|
||||
/** Opens the palette with an empty query and refreshes the enabled states. */
|
||||
async function show(): Promise<void> {
|
||||
modals.opened("palette", close);
|
||||
if (!open.value) {
|
||||
const active = document.activeElement;
|
||||
returnFocus = active instanceof HTMLElement ? active : null;
|
||||
|
|
@ -62,6 +68,7 @@ function close(): void {
|
|||
return;
|
||||
}
|
||||
open.value = false;
|
||||
modals.closed("palette");
|
||||
returnFocus?.focus();
|
||||
returnFocus = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,16 @@
|
|||
* not replayed after a page reload, `projectOpened` also asks the engine with
|
||||
* `recovery.list`. Every action names its paths explicitly, so entries of
|
||||
* files restored earlier in the dialog are never discarded by accident.
|
||||
*
|
||||
* `recoveryResolved` (M1.15) drops the paths that `recovery.restore` or
|
||||
* `recovery.discard` settled from elsewhere (the control channel, an
|
||||
* agent), so the dialog closes when nothing is left to decide. The dialog
|
||||
* is queued behind the other modals (`commands/modals.ts`): hidden while
|
||||
* the palette, the settings dialog or the close question is open.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import { useModalsStore } from "../../commands/modals";
|
||||
import { onEngineEvent, run, type EngineEventPayload, type JsonValue } from "../../ipc";
|
||||
|
||||
/** One unsaved text the journal holds. */
|
||||
|
|
@ -78,6 +85,7 @@ function toFailures(raw: unknown): RecoveryFailure[] {
|
|||
|
||||
/** Store behind the restore dialog. */
|
||||
export const useRecoveryStore = defineStore("recovery", () => {
|
||||
const modals = useModalsStore();
|
||||
/** Entries still waiting for a decision; the dialog shows while non-empty. */
|
||||
const entries = ref<RecoveryEntry[]>([]);
|
||||
/** Paths ticked for "Restore selected". */
|
||||
|
|
@ -88,8 +96,10 @@ export const useRecoveryStore = defineStore("recovery", () => {
|
|||
const error = ref<string | null>(null);
|
||||
/** A restore or discard is running. */
|
||||
const busy = ref(false);
|
||||
/** Whether the dialog is shown. */
|
||||
const open = computed(() => entries.value.length > 0 || failures.value.length > 0);
|
||||
/** Whether there is something to show: entries or failures. */
|
||||
const pending = computed(() => entries.value.length > 0 || failures.value.length > 0);
|
||||
/** Whether the dialog is shown: pending and no other modal open. */
|
||||
const open = computed(() => pending.value && modals.current === null);
|
||||
|
||||
/** Ends the event subscription; null while not subscribed. */
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
|
@ -111,6 +121,20 @@ export const useRecoveryStore = defineStore("recovery", () => {
|
|||
show([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops paths settled elsewhere from the list and the ticks.
|
||||
*
|
||||
* @param raw - the `paths` of `recoveryResolved`, untrusted.
|
||||
*/
|
||||
function resolve(raw: unknown): void {
|
||||
if (!Array.isArray(raw)) {
|
||||
return;
|
||||
}
|
||||
const done = new Set(raw.filter((p): p is string => typeof p === "string"));
|
||||
entries.value = entries.value.filter((e) => !done.has(e.path));
|
||||
selected.value = new Set([...selected.value].filter((p) => !done.has(p)));
|
||||
}
|
||||
|
||||
/** Asks the engine for the entries, after a project opened. */
|
||||
async function refresh(): Promise<void> {
|
||||
const result = await run<{ entries?: unknown }>("recovery.list");
|
||||
|
|
@ -129,6 +153,9 @@ export const useRecoveryStore = defineStore("recovery", () => {
|
|||
case "recoveryAvailable":
|
||||
show(toRecoveryEntries((event as { entries?: unknown }).entries));
|
||||
break;
|
||||
case "recoveryResolved":
|
||||
resolve((event as { paths?: unknown }).paths);
|
||||
break;
|
||||
case "projectOpened":
|
||||
void refresh();
|
||||
break;
|
||||
|
|
@ -223,6 +250,7 @@ export const useRecoveryStore = defineStore("recovery", () => {
|
|||
failures,
|
||||
error,
|
||||
busy,
|
||||
pending,
|
||||
open,
|
||||
handleEvent,
|
||||
start,
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
* so a change over the control channel shows while the dialog is open.
|
||||
* - **Keyboard:** Escape closes, Tab and Shift+Tab stay inside the dialog,
|
||||
* and the focus returns to where it was.
|
||||
* - **One modal:** opening the dialog closes the palette or the close
|
||||
* question (see `commands/modals.ts`).
|
||||
*/
|
||||
import { X } from "@lucide/vue";
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
||||
import { useModalsStore } from "../../commands/modals";
|
||||
import { useCommandsStore } from "../../commands/store";
|
||||
import { t } from "../../i18n";
|
||||
import {
|
||||
|
|
@ -34,6 +37,7 @@ import {
|
|||
|
||||
const commands = useCommandsStore();
|
||||
const settings = useSettingsStore();
|
||||
const modals = useModalsStore();
|
||||
|
||||
/** Whether the dialog is shown. */
|
||||
const open = ref(false);
|
||||
|
|
@ -200,6 +204,7 @@ function choose(id: string): void {
|
|||
|
||||
/** Opens the dialog (or focuses its search field) and reloads the settings. */
|
||||
async function show(): Promise<void> {
|
||||
modals.opened("settings", close);
|
||||
if (!open.value) {
|
||||
const active = document.activeElement;
|
||||
returnFocus = active instanceof HTMLElement ? active : null;
|
||||
|
|
@ -217,6 +222,7 @@ function close(): void {
|
|||
return;
|
||||
}
|
||||
open.value = false;
|
||||
modals.closed("settings");
|
||||
for (const key of Object.keys(drafts)) {
|
||||
Reflect.deleteProperty(drafts, key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@ export type EngineEventPayload =
|
|||
id: unknown;
|
||||
/** The params it was run with, as given; unchecked. */
|
||||
params?: unknown;
|
||||
}
|
||||
| {
|
||||
kind: "recoveryResolved";
|
||||
/** Paths restored or discarded; unchecked, it comes from the engine. */
|
||||
paths: unknown;
|
||||
};
|
||||
|
||||
/** Callback receiving engine events. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue