erlinerd's patch on #2721 (profile.Rename, /api/state profile/rename, a Rename button in the details), reviewed against main and adapted: - profile.Rename trims both names, refuses an empty, taken or missing name and leaves profiles.json as it was, renames by case only (home -> Home), and keeps what the profile holds. - GUI: Rename turns the details' name into a field. Enter renames through profileAction, so the chip is renamed at once, pending, and rolled back with the error if magpie refuses; the details stay open under the new name, with In use kept. Escape or a click away puts the name back. The field lives in profilerename.js, imported on press, so the core script stays under its budget (no raise; 50 bytes under after comments in app.js were cut). While the field is open In use, Apply and Rename hide so a 360px panel's field has room. - TUI: ctrl+e on a profile renames it on the name line. - CLI: `magpie rename <old> <new>`; a flag is never taken for a name. - WebDAV: a rename syncs as the old name gone and the new one in (davsync test). Run on mote at 47672f11c (on70b96126e), and again after rebasing on52195b6b0(backup), as 3b279fdee: - go test ./internal/profile ./internal/cli ./internal/gui ./internal/tui ./internal/davsync: ok except TestEveryRouteHasACommandOrIsNamed (#4826) and TestMainWindowCorners (#3949), both red on origin/main07f4d46c5too. gofmt clean; GOOS=linux (-tags nogui) and GOOS=windows go vet ok. - GUI, chromium and webkit: profile-rename (en, zh, zh-TW, ja, de; 900x560 window and 360x420 panel), panel-profiles, profile-confirm, profile-in-use, profile-details, hermes-profiles, view-wheel-after-click, i18n-keys, gui-de, gui-ja, gui-zh-tw, editor-roomy: 219 pass, 0 fail. After the rebase: profile, cli, gui, tui and vet again (same two reds only, core budget ok), and the GUI files above with auto-backup in place of editor-roomy: 161 pass. Then rebased overea51526b6(gateway, plugin, provider only; no file of this change, no GUI asset) without another run. Broken by hand, each red, then restored: - Rename comparing names with EqualFold: TestRename red (case-only). - Dropping the CLI's "-" check: TestRenameCommand red. - Dropping `profileOpen = to`: profile-rename 22 of 22 red, both engines. Not tried: the real app on Linux (WebKitGTK) or Windows; a rename synced over a real WebDAV server. Co-authored-by: erlinerd <erlinerd@outlook.com>
28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
// A profile's Rename (#2721, erlinerd): the details' name becomes a field
|
||
// holding it, Enter renames through profileAction (its pending chip and
|
||
// rollback), Escape or a click away puts the name back. app.js imports
|
||
// this when Rename is pressed, so it weighs nothing on the core.
|
||
window.profRename = function (d, p) {
|
||
const name = d.querySelector(".pd-name");
|
||
if (!name) return;
|
||
const input = el("input", "chip-input pd-rename-input");
|
||
input.value = p.name;
|
||
input.setAttribute("aria-label", t("Profile name"));
|
||
// while it is open the field has the head, × aside: In use, Apply and
|
||
// Rename left a narrow panel's field no room to type in
|
||
const rest = [...d.querySelectorAll(".pd-cur, .pd-apply, .pd-rename")];
|
||
const show = (on) => rest.forEach((b) => (b.hidden = !on));
|
||
show(false);
|
||
const back = () => { if (input.isConnected) { input.replaceWith(name); show(true); } };
|
||
input.onkeydown = (e) => {
|
||
e.stopPropagation(); // Escape is the field's, not the details'
|
||
const to = input.value.trim();
|
||
if (e.key === "Enter" && to && to !== p.name) { input.onblur = null; profileAction("rename", p.name, false, to); }
|
||
else if (e.key === "Enter" || e.key === "Escape") back();
|
||
};
|
||
input.onblur = () => setTimeout(back, 100);
|
||
name.replaceWith(input);
|
||
input.focus(NO_SCROLL);
|
||
input.select();
|
||
};
|