Edit the drafted merge message before confirming
This commit is contained in:
+20
-5
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user