Send messages with Ctrl+Enter

Ctrl+Enter (Cmd+Enter on a Mac) submits the buyer's and the owner's message
boxes through the normal form, so the usual checks apply. Plain Enter still
adds a line. The empty box hints at the shortcut. Not added to the publish
description or the address-release note, where it could submit by accident.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:55:30 +01:00
co-authored by Claude Sonnet 5.5
parent 19fea7f524
commit 71e6dc8658
7 changed files with 80 additions and 6 deletions
+3 -2
View File
@@ -3,7 +3,7 @@
// only, and owner messages only after message.ts verified them.
import { HttpError, getListing, pollMailbox, postMessage } from "./api.ts";
import { append, clear, h } from "./dom.ts";
import { append, clear, h, sendOnCtrlEnter } from "./dom.ts";
import { date } from "./format.ts";
import { t, type Key } from "./i18n.ts";
import {
@@ -63,7 +63,8 @@ function composer(opts: {
button: Key;
send: (text: string) => Promise<void>;
}): HTMLElement {
const area = h("textarea", { name: "message", rows: 5, "aria-label": t("contact.label"), required: true });
const area = h("textarea", { name: "message", rows: 5, "aria-label": t("contact.label"), placeholder: t("compose.hint"), required: true });
sendOnCtrlEnter(area);
const counter = h("span", { class: "muted" });
const problem = h("p", { class: "error", role: "alert" });
const button = h("button", { type: "submit", class: "btn primary" }, t(opts.button));
+9
View File
@@ -34,3 +34,12 @@ export function append(parent: Node, children: Child[]): void {
export function clear(el: Element): void {
while (el.firstChild) el.removeChild(el.firstChild);
}
/** Lets Ctrl+Enter (Cmd+Enter on a Mac) send the form a text box belongs to, like its Send button. */
export function sendOnCtrlEnter(area: HTMLTextAreaElement): void {
area.addEventListener("keydown", (ev) => {
if (ev.key !== "Enter" || !(ev.ctrlKey || ev.metaKey) || ev.isComposing || area.disabled) return;
ev.preventDefault();
area.form?.requestSubmit();
});
}
+2
View File
@@ -53,6 +53,7 @@ const de = {
"contact.rules":
"Die erste Nachricht muss kurz sein und darf keine Links enthalten. Das schützt vor Betrug; nach der ersten Antwort des Anbieters entfällt es.",
"contact.label": "Deine Nachricht",
"compose.hint": "Strg+Enter sendet",
"contact.counter": "{used} / {max} Bytes",
"contact.send": "Verschlüsselt senden",
"contact.sending": "Wird vorbereitet … (eine kleine Rechenaufgabe gegen Spam)",
@@ -299,6 +300,7 @@ const en: Record<keyof typeof de, string> = {
"contact.rules":
"The first message must be short and must not contain links. This protects against scams; it ends once the owner has replied.",
"contact.label": "Your message",
"compose.hint": "Ctrl+Enter sends",
"contact.counter": "{used} / {max} bytes",
"contact.send": "Send encrypted",
"contact.sending": "Preparing … (a small puzzle against spam)",
+3 -2
View File
@@ -7,7 +7,7 @@
// with textContent only, never as links.
import { HttpError } from "./api.ts";
import { append, clear, h } from "./dom.ts";
import { append, clear, h, sendOnCtrlEnter } from "./dom.ts";
import { date, price, when } from "./format.ts";
import { t, type Key } from "./i18n.ts";
import * as o from "./ownerApi.ts";
@@ -405,7 +405,8 @@ function bubble(m: o.OwnerMessage): HTMLElement {
}
function composer(listingId: string, thread: string, done: () => void, release: (opener: HTMLElement) => void): HTMLElement {
const area = h("textarea", { rows: 3, "aria-label": t("own.reply"), name: "reply" });
const area = h("textarea", { rows: 3, "aria-label": t("own.reply"), name: "reply", placeholder: t("compose.hint") });
sendOnCtrlEnter(area);
const problem = h("p", { class: "error", role: "alert" });
const send = h("button", { type: "submit", class: "btn primary" }, t("own.send"));
const rel = h("button", { type: "button", class: "btn", onclick: () => release(rel) }, t("own.release"));