F1: conflict toast closes when the merge ends, toasts keep off the commit box

The merge store dismisses its conflict warning once the status lists no
conflicted file (resolved, committed or aborted) and replaces it on a new
conflicted merge. The toast stack moves above areas registered with
keepClearOf; the Changes window registers its commit box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-02 18:53:08 +01:00
parent e228d11ef9
commit 750ecf5e51
7 changed files with 235 additions and 9 deletions

View file

@ -10,9 +10,12 @@
* Info toasts dismiss themselves after {@link INFO_TIMEOUT_MS}; warnings
* and errors stay until closed. At most {@link MAX_VISIBLE} toasts show;
* older ones collapse into a "+n more" entry.
*
* Areas the stack must never cover (the commit box) register themselves
* with `keepClear`; the stack then sits above them ({@link stackBottom}).
*/
import { defineStore } from "pinia";
import { computed, ref } from "vue";
import { computed, ref, shallowRef } from "vue";
import { hasMessage, t, type MessageParams } from "../i18n";
import { onEngineEvent, type EngineError, type EngineEventPayload } from "../ipc";
@ -34,6 +37,55 @@ export const KEY_WATCH_FAILED = "notification.watch.failed";
/** Catalog key of the toast for a failed command. Params: `command`, `message`. */
export const KEY_COMMAND_FAILED = "notification.command.failed";
/** Distance of the stack from the window's bottom edge, in pixels. */
export const STACK_BOTTOM = 36;
/** Distance of the stack from the window's right edge, in pixels. */
export const STACK_RIGHT = 16;
/** Widest the stack gets, in pixels. */
export const STACK_WIDTH = 420;
/** Gap kept between the stack and an area it must not cover, in pixels. */
export const KEEP_CLEAR_GAP = 8;
/** Where an area sits in the window, as `getBoundingClientRect` gives it. */
export interface Area {
/** Left edge. */
left: number;
/** Right edge. */
right: number;
/** Top edge. */
top: number;
/** Bottom edge. */
bottom: number;
}
/**
* The stack's distance from the window's bottom edge so that it covers
* none of the given areas, however tall it grows: above the highest one
* it overlaps horizontally, else {@link STACK_BOTTOM}. Hidden areas (no
* width or height, as under `v-show`) are skipped.
*
* @param width - the window's inner width.
* @param height - the window's inner height.
* @param areas - the areas to keep clear.
* @returns the CSS `bottom` in pixels.
*/
export function stackBottom(width: number, height: number, areas: readonly Area[]): number {
const right = width - STACK_RIGHT;
const left = right - Math.min(STACK_WIDTH, width - 2 * STACK_RIGHT);
let bottom = STACK_BOTTOM;
for (const area of areas) {
const hidden = area.right <= area.left || area.bottom <= area.top;
const beside = area.right <= left || area.left >= right;
if (!hidden && !beside) {
bottom = Math.max(bottom, height - area.top + KEEP_CLEAR_GAP);
}
}
return bottom;
}
/** A toast as the stack shows it. */
export interface Toast {
/** Unique id: the engine's (`n1`…) or a frontend one (`ui1`…). */
@ -134,6 +186,8 @@ export const useNotificationsStore = defineStore("notifications", () => {
let made = 0;
/** Auto-dismiss timers of info toasts, by id. */
const timers = new Map<string, ReturnType<typeof setTimeout>>();
/** Elements the stack must not cover, in registration order. */
const keepClear = shallowRef<HTMLElement[]>([]);
/** Ends the engine event subscription; set while started. */
let unsubscribe: (() => void) | null = null;
@ -228,6 +282,19 @@ export const useNotificationsStore = defineStore("notifications", () => {
expanded.value = false;
}
/**
* Keeps the stack off an element until the returned function is called.
*
* @param element - the element, e.g. the commit box.
* @returns a function that releases the element again.
*/
function keepClearOf(element: HTMLElement): () => void {
keepClear.value = [...keepClear.value, element];
return () => {
keepClear.value = keepClear.value.filter((kept) => kept !== element);
};
}
/** Shows the toasts collapsed into "+n more". */
function expand(): void {
expanded.value = true;
@ -262,6 +329,8 @@ export const useNotificationsStore = defineStore("notifications", () => {
visible,
hiddenCount,
expanded,
keepClear,
keepClearOf,
notify,
notifyError,
dismiss,