Edit the drafted merge message before confirming

This commit is contained in:
Ian Gulliver
2026-10-15 18:55:20 -07:00
parent de394b8c35
commit 5a07658523
16 changed files with 324 additions and 211 deletions
+20 -5
View File
@@ -74,9 +74,18 @@ export function errorText(err: unknown): string {
return err instanceof Error ? err.message : String(err);
}
function modal(text: string, buttons: { label: string; value: string; class?: string }[], anchor: Element | null = null): Promise<string> {
const actions = buttons.map((b) => h("button", { type: "submit", value: b.value, class: b.class ?? "" }, b.label));
const dialog = h("dialog", { class: "modal" }, h("form", { method: "dialog" }, h("p", { class: "modal-text" }, text), h("div", { class: "modal-actions" }, ...actions)));
function modal(content: string | Node[], buttons: { label: string; value: string; class?: string }[], anchor: Element | null = null): Promise<string> {
const actions = buttons.map((b) => h("button", { type: "submit", value: b.value, class: b.class ?? "", formNoValidate: b.value === "cancel" }, b.label));
const body = typeof content === "string" ? [h("p", { class: "modal-text" }, content)] : content;
const dialog = h("dialog", { class: "modal" }, h("form", { method: "dialog" }, ...body, h("div", { class: "modal-actions" }, ...actions)));
for (const input of dialog.querySelectorAll("input")) {
input.onkeydown = (e) => {
if (e.key === "Enter") {
e.preventDefault();
actions.at(-1)?.click();
}
};
}
if (anchor) {
const rect = anchor.getBoundingClientRect();
dialog.classList.add("anchored");
@@ -90,6 +99,12 @@ function modal(text: string, buttons: { label: string; value: string; class?: st
resolve(dialog.returnValue);
};
dialog.showModal();
const input = dialog.querySelector("input");
if (input) {
input.focus();
input.select();
return;
}
actions.at(-1)?.focus();
});
}
@@ -120,9 +135,9 @@ export async function showAlert(text: string): Promise<void> {
await modal(text, [{ label: "OK", value: "ok", class: "primary" }]);
}
export async function showConfirm(text: string, action: string, danger = false, anchor: Element | null = null): Promise<boolean> {
export async function showConfirm(content: string | Node[], action: string, danger = false, anchor: Element | null = null): Promise<boolean> {
const value = await modal(
text,
content,
[
{ label: "Cancel", value: "cancel" },
{ label: action, value: "ok", class: danger ? "danger-primary" : "primary" },