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;