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

@ -8,13 +8,65 @@
* toasts beyond the visible limit collapse into a "+n more" button. The
* colours match the editor's in-place notices (`--lt-notice-bg`, the error
* tint).
*
* The stack never covers an area registered with `keepClearOf` (the commit
* box): it moves above it ({@link stackBottom}) and is placed again when
* toasts come, the window resizes or a kept area changes size.
*/
import { CircleAlert, Info, TriangleAlert, X } from "@lucide/vue";
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
import { t } from "../../i18n";
import { useNotificationsStore, type NotificationLevel } from "../../stores/notifications";
import { STACK_BOTTOM, stackBottom, useNotificationsStore, type NotificationLevel } from "../../stores/notifications";
const notifications = useNotificationsStore();
/** The stack's CSS `bottom`, in pixels. */
const bottom = ref(STACK_BOTTOM);
/** Watches the kept areas and their parents for size changes; null where unsupported. */
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(place);
/** Moves the stack above every kept area it would cover. */
function place(): void {
const areas = notifications.keepClear.map((element) => element.getBoundingClientRect());
bottom.value = stackBottom(window.innerWidth, window.innerHeight, areas);
}
/** Observes the kept areas and the elements around them (a resized panel moves them). */
function observe(): void {
if (!observer) {
return;
}
observer.disconnect();
for (const element of notifications.keepClear) {
observer.observe(element);
if (element.parentElement) {
observer.observe(element.parentElement);
}
}
}
watch(
() => notifications.keepClear,
() => {
observe();
place();
},
);
watch(() => notifications.toasts.length, place);
onMounted(() => {
window.addEventListener("resize", place);
observe();
place();
});
onBeforeUnmount(() => {
window.removeEventListener("resize", place);
observer?.disconnect();
});
/** Icon of each level. */
const ICONS = { info: Info, warning: TriangleAlert, error: CircleAlert } as const;
@ -32,6 +84,7 @@ function roleOf(level: NotificationLevel): "status" | "alert" {
<section
v-if="notifications.toasts.length > 0"
class="toasts"
:style="{ bottom: `${bottom}px`, maxHeight: `calc(100vh - ${bottom + STACK_BOTTOM}px)` }"
:aria-label="t('notification.stack.label')"
data-test="toasts"
>
@ -85,14 +138,12 @@ function roleOf(level: NotificationLevel): "status" | "alert" {
.toasts {
position: fixed;
right: 16px;
bottom: 36px;
z-index: 100;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
width: min(420px, calc(100vw - 32px));
max-height: calc(100vh - 72px);
overflow-y: auto;
user-select: text;
}

View file

@ -25,13 +25,14 @@
* Open, and Add to .gitignore for untracked files.
* - **Commit box:** the message, an Amend checkbox and Commit. Commit
* saves dirty buffers first (`flushDirty`); `Mod+Enter` in the box
* commits too.
* commits too. Toasts never cover the box: it is registered with the
* notifications store's `keepClearOf`.
* - State lives in the Changes store (`changes.ts`), so the status and the
* message survive hiding the window. Icons are Lucide's; colours are
* tokens.
*/
import { Archive, ArchiveRestore, RefreshCw } from "@lucide/vue";
import { computed, nextTick, onMounted, ref, watch } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { useCommandsStore } from "../../../commands/store";
import { isMac } from "../../../commands/keymap";
import { t } from "../../../i18n";
@ -50,6 +51,12 @@ const list = ref<HTMLElement | null>(null);
/** The commit message box. */
const messageBox = ref<HTMLTextAreaElement | null>(null);
/** The commit box, kept clear of toasts. */
const commitBox = ref<HTMLFormElement | null>(null);
/** Releases the commit box from the toast stack; null while not registered. */
let releaseCommitBox: (() => void) | null = null;
/** The open context menu: its row and where it shows; null when closed. */
const menu = ref<{ row: ChangeRow; x: number; y: number } | null>(null);
@ -317,6 +324,14 @@ watch(() => changes.focusRequest, takeFocus);
onMounted(() => {
void takeFocus();
if (commitBox.value) {
releaseCommitBox = notifications.keepClearOf(commitBox.value);
}
});
onBeforeUnmount(() => {
releaseCommitBox?.();
releaseCommitBox = null;
});
watch(
@ -465,6 +480,7 @@ watch(
@open="openRow"
/>
<form
ref="commitBox"
class="changes__commit"
data-test="changes-commit"
@submit.prevent="changes.commit()"

View file

@ -16,10 +16,14 @@
* deleted on one side offers to keep the other side's version; binary and
* too large files can only be marked resolved as they are on disk.
* - **Abort:** `git.mergeAbort` after a confirmation in the dialog.
* - **Conflict toast:** the warning a conflicted merge shows stays only
* while the status store lists conflicted files. Once they are resolved,
* the merge is committed or aborted, it closes; a new conflicted merge
* replaces it.
* - **Untrusted input:** every result is checked field by field.
*/
import { defineStore } from "pinia";
import { computed, ref, shallowRef } from "vue";
import { computed, ref, shallowRef, watch } from "vue";
import { t } from "../../../i18n";
import { runWaiting, type JsonValue } from "../../../ipc";
import { useAutosaveStore } from "../../../stores/autosave";
@ -169,6 +173,8 @@ export const useMergeStore = defineStore("merge", () => {
const busy = ref(false);
/** Bumped on every load, so only the newest one lands. */
let generation = 0;
/** Id of the shown conflict warning toast; null when none is shown. */
let conflictToast: string | null = null;
/** The conflicted files, sorted by path. */
const conflicts = computed(() =>
@ -177,6 +183,23 @@ export const useMergeStore = defineStore("merge", () => {
.map((file) => file.path),
);
/** Closes the conflict warning toast, if one is shown. */
function dismissConflictToast(): void {
if (conflictToast !== null) {
notifications.dismiss(conflictToast);
conflictToast = null;
}
}
watch(
() => conflicts.value.length,
(count) => {
if (count === 0) {
dismissConflictToast();
}
},
);
/** The current branch, null when detached or unknown. */
const currentBranch = computed(() => status.snapshot?.repo?.branch ?? null);
@ -254,8 +277,9 @@ export const useMergeStore = defineStore("merge", () => {
return null;
}
await status.refresh();
dismissConflictToast();
if (answer.result === "conflicts") {
notifications.notify({
conflictToast = notifications.notify({
level: "warning",
messageKey: "notification.vcs.mergeConflicts",
params: { branch, count: String(answer.conflicts.length) },
@ -292,6 +316,7 @@ export const useMergeStore = defineStore("merge", () => {
return false;
}
await status.refresh();
dismissConflictToast();
notifications.notify({ level: "info", messageKey: "notification.vcs.mergeAborted" });
close();
return true;

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,