Commit d5cd988ef5

d5cd988ef5e0a330cfce630f45782975923b1b44

parent: 314b019a40

Verified · cmc ci/build: success ci/quality: success ci/test: success

cmc <hello@cleberg.net> · 2026-11-25 09:33 UTC

web: polish authoring forms, add Cmd+Enter submit and no-reload preview

Layout: unified · split

Changed files (5)
internal/web/static/app.js +42 −4
@@ -47,9 +47,9 @@
4747 }
4848 });
4949
50 // ---- 2. Copy buttons on clone & copyable blocks ----
50 // ---- 2. Copy buttons on clone, copyable & rendered code blocks ----
5151 function initCopyButtons(root = document) {
52 for (const pre of root.querySelectorAll('.clone pre, pre.copyable')) {
52 for (const pre of root.querySelectorAll('.clone pre, pre.copyable, .rendered pre')) {
5353 if (pre.dataset.copyWired) continue;
5454 pre.dataset.copyWired = '1';
5555 const code = pre.querySelector('code') || pre;
@@ -61,7 +61,7 @@
6161 btn.type = 'button';
6262 btn.className = 'copybtn';
6363 btn.textContent = 'Copy';
64 btn.setAttribute('aria-label', 'Copy command');
64 btn.setAttribute('aria-label', 'Copy code');
6565 btn.addEventListener('click', async () => {
6666 try {
6767 await navigator.clipboard.writeText(code.textContent.trim());
@@ -76,10 +76,41 @@
7676 }
7777 }
7878
79 // ---- 3. In-place fragment swaps (reactions, header toggles, sidebar pickers) ----
79 // ---- 3. In-place fragment swaps (previews, reactions, header toggles, sidebar pickers) ----
8080 document.addEventListener('submit', async (e) => {
8181 const form = e.target;
8282 if (!(form instanceof HTMLFormElement) || form.method.toLowerCase() !== 'post') return;
83
84 // No-reload markup preview on any form with a Preview button
85 if (e.submitter && e.submitter.name === 'preview') {
86 e.preventDefault();
87 const btn = e.submitter;
88 const data = new FormData(form);
89 data.append('preview', btn.value || '1');
90 btn.disabled = true;
91 try {
92 const res = await fetch(form.action, {
93 method: 'POST',
94 body: new URLSearchParams(data),
95 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
96 credentials: 'same-origin',
97 });
98 if (!res.ok) { form.submit(); return; }
99 const doc = new DOMParser().parseFromString(await res.text(), 'text/html');
100 const nextPrev = doc.querySelector('.preview');
101 if (!nextPrev) { showToast('Nothing to preview'); return; }
102 const prev = form.previousElementSibling;
103 if (prev && prev.classList.contains('preview')) prev.replaceWith(nextPrev);
104 else form.insertAdjacentElement('beforebegin', nextPrev);
105 initCopyButtons(nextPrev);
106 } catch {
107 form.submit();
108 } finally {
109 btn.disabled = false;
110 }
111 return;
112 }
113
83114 let swapSel = null;
84115 if (form.classList.contains('reactions')) {
85116 swapSel = 'main#content';
@@ -306,6 +337,13 @@
306337 if (inline) inline.remove();
307338 return;
308339 }
340 if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && e.target instanceof HTMLTextAreaElement && e.target.form) {
341 e.preventDefault();
342 const btn = e.target.form.querySelector('button[type="submit"]:not([name="preview"]), button:not([type]):not([name="preview"])');
343 if (btn) e.target.form.requestSubmit(btn);
344 else e.target.form.requestSubmit();
345 return;
346 }
309347 if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
310348 e.preventDefault();
311349 openPalette();
internal/web/static/style.css +20
@@ -2447,3 +2447,23 @@ article.release.setcard {
24472447 border-top: 1px solid var(--faint);
24482448 padding: var(--sp-5);
24492449}
2450
2451/* ---- authoring forms polish ---- */
2452.meta-fields {
2453 display: grid;
2454 grid-template-columns: repeat(3, minmax(0, 1fr));
2455 gap: var(--sp-3);
2456 margin: var(--sp-3) 0;
2457}
2458@media (max-width: 44rem) {
2459 .meta-fields { grid-template-columns: 1fr; }
2460}
2461.commitbar {
2462 display: flex;
2463 align-items: center;
2464 gap: var(--sp-2);
2465 flex-wrap: wrap;
2466 margin: var(--sp-3) 0 var(--sp-2);
2467}
2468.commitbar input { flex: 1 1 16rem; min-width: 0; }
2469.rendered .copywrap .copybtn { top: var(--sp-2); transform: none; }
internal/web/templates/edit.html +14 −5
@@ -1,20 +1,29 @@
11{{define "width"}}wide{{end}}
22{{define "title"}}edit {{.Path}} · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}}
33{{define "content"}}
4<h1>edit {{.Repo.OwnerName}}/{{.Repo.Name}} : {{.Path}} @ {{.Ref}}</h1>
4<div class="pagehead">
5 <h1>Edit <code>{{.Path}}</code> <span class="refchip">{{.Ref}}</span></h1>
6 <span class="grow"></span>
7 <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/blob/{{.Ref}}/{{.Path}}">Cancel</a>
8</div>
59<div class="blobgrid">
610{{template "filenav" .Nav}}
711<div class="blobmain">
812{{if .Error}}<p class="error" role="alert">{{.Error}}</p>{{end}}
913{{if .Blocked}}<p class="empty-note">{{.Blocked}}</p>{{else}}
14<section class="setcard">
1015{{if .Creating}}<p class="meta"><code>{{.Path}}</code> does not exist on {{.Ref}}; committing creates it.</p>{{end}}
1116{{if .Draft.Is "content"}}{{template "previewblock" .Draft.HTML}}{{end}}
1217<form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/edit/{{.Ref}}/{{.Path}}" class="editform">
13<p><textarea name="content" aria-label="File contents" rows="24" spellcheck="false">{{.Content}}</textarea></p>
14<p><input name="message" aria-label="Commit message" placeholder="commit message" value="{{.Draft.Or "content" "message" ""}}">
15<button type="submit">Commit to {{.Ref}}</button>{{if .Markup}} {{template "previewbtn"}}{{end}}</p>
16<p class="crumbs">this commit will be unsigned and authored as {{.Viewer}}</p>
18 <p><textarea name="content" aria-label="File contents" rows="24" spellcheck="false">{{.Content}}</textarea></p>
19 <div class="commitbar">
20 <input name="message" aria-label="Commit message" placeholder="Commit message" value="{{.Draft.Or "content" "message" ""}}">
21 <button type="submit">Commit to {{.Ref}}</button>
22 {{if .Markup}}{{template "previewbtn"}}{{end}}
23 </div>
24 <p class="crumbs">this commit will be unsigned and authored as {{.Viewer}} · ⌘↵ to commit</p>
1725</form>
26</section>
1827{{end}}
1928</div>
2029</div>
internal/web/templates/issuenew.html +19 −11
@@ -1,20 +1,28 @@
11{{define "width"}}bounded{{end}}
22{{define "title"}}new issue · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}}
33{{define "content"}}
4<h1>New issue</h1>
4<div class="pagehead">
5 <h1>New issue</h1>
6 <span class="grow"></span>
7 <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/issues">Back to issues</a>
8</div>
59{{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}}
6{{if gt (len .Templates) 1}}<p class="meta">template:
10{{if gt (len .Templates) 1}}<p class="meta">Template:
711{{range .Templates}}{{if eq .Name $.Template}}<strong>{{.Name}}</strong>{{else}}<a href="?template={{.Name}}">{{.Name}}</a>{{end}} {{end}}</p>{{end}}
12<section class="setcard">
813{{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}}
914<form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/issues/new" class="commentform">
10<p><input type="text" name="title" aria-label="Title" placeholder="title" value="{{.Title}}" required></p>
11<p><textarea name="body" aria-label="Description" rows="12">{{.Body}}</textarea></p>
12{{template "formatpicker" .Format}}
13{{if .CanWrite}}
14<p><input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}"></p>
15<p><input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}"></p>
16<p><input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}"></p>
17{{end}}
18<p><button type="submit">Open issue</button> {{template "previewbtn"}}</p>
15 <p><input type="text" name="title" aria-label="Title" placeholder="Title" value="{{.Title}}" required></p>
16 <p><textarea name="body" aria-label="Description" rows="12" placeholder="Describe the issue…">{{.Body}}</textarea></p>
17 {{template "formatpicker" .Format}}
18 {{if .CanWrite}}
19 <div class="meta-fields">
20 <input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}">
21 <input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}">
22 <input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}">
23 </div>
24 {{end}}
25 <p class="btngroup"><button type="submit">Open issue</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p>
1926</form>
27</section>
2028{{end}}
internal/web/templates/mrnew.html +22 −16
@@ -1,26 +1,32 @@
11{{define "width"}}bounded{{end}}
22{{define "title"}}new merge request · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}}
33{{define "content"}}
4<h1>New merge request</h1>
4<div class="pagehead">
5 <h1>New merge request</h1>
6 <span class="grow"></span>
7 <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs">Back to merge requests</a>
8</div>
59{{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}}
10<section class="setcard">
611{{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}}
712<form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs/new" class="commentform">
8<p class="branchpick">
9 <label for="source">Merge</label>
10 <select id="source" name="source" required>
11 <option value="">Choose a branch…</option>
12 {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}}
13 </select>
14 <label for="target">into</label>
15 <select id="target" name="target">
16 {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}}
17 </select>
18</p>
19<p><input type="text" name="title" aria-label="Title" placeholder="title" value="{{.Title}}" required></p>
20<p><textarea name="body" aria-label="Description" rows="10" placeholder="what changes, and why">{{.Body}}</textarea></p>
21{{template "formatpicker" .Format}}
22<p><button type="submit">Open merge request</button> {{template "previewbtn"}}</p>
13 <p class="branchpick">
14 <label for="source">Merge</label>
15 <select id="source" name="source" required>
16 <option value="">Choose a branch…</option>
17 {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}}
18 </select>
19 <label for="target">into</label>
20 <select id="target" name="target">
21 {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}}
22 </select>
23 </p>
24 <p><input type="text" name="title" aria-label="Title" placeholder="Title" value="{{.Title}}" required></p>
25 <p><textarea name="body" aria-label="Description" rows="10" placeholder="what changes, and why">{{.Body}}</textarea></p>
26 {{template "formatpicker" .Format}}
27 <p class="btngroup"><button type="submit">Open merge request</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p>
2328</form>
29</section>
2430<p class="meta">Branches of a fork you can push to are offered as
2531<code>owner/name:branch</code>. Fork this repository to propose a change
2632without write access here: <code>gitbay repo fork {{.Repo.OwnerName}}/{{.Repo.Name}}</code></p>