Files
magpie/internal/gui/assets/profilerename.js
T
yetoneanderlinerd 1cb4d43013 profiles: a saved profile renames, in its details, the TUI and magpie rename (#2721, erlinerd)
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 (on 70b96126e), and again after rebasing on
52195b6b0 (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/main
  07f4d46c5 too. 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 over ea51526b6 (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>
2026-11-02 18:37:25 +08:00

28 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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();
};