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
@@ -59,9 +59,18 @@ export function ago(iso) {
export function errorText(err) {
return err instanceof Error ? err.message : String(err);
}
function modal(text, buttons, anchor = null) {
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, buttons, anchor = null) {
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");
@@ -75,6 +84,12 @@ function modal(text, buttons, anchor = null) {
resolve(dialog.returnValue);
};
dialog.showModal();
const input = dialog.querySelector("input");
if (input) {
input.focus();
input.select();
return;
}
actions.at(-1)?.focus();
});
}
@@ -102,8 +117,8 @@ export function openPanel(title, mount) {
export async function showAlert(text) {
await modal(text, [{ label: "OK", value: "ok", class: "primary" }]);
}
export async function showConfirm(text, action, danger = false, anchor = null) {
const value = await modal(text, [
export async function showConfirm(content, action, danger = false, anchor = null) {
const value = await modal(content, [
{ label: "Cancel", value: "cancel" },
{ label: action, value: "ok", class: danger ? "danger-primary" : "primary" },
], anchor);