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
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue