Put every shortcut on one shared keymap and make the app keyboard-reachable

The keymap was scattered over ShortcutsService if-chains, the file panel's
key switch, macOS-only menu accelerators and hand-typed hints in 16
tooltips x 7 locales, and large parts of the app had no keyboard path at
all. src/shared/keymap.ts is now the one table: scopes, per-platform
defaults, exact matching, formatting with localized key names, conflicts,
reserved combos and native-menu accelerators, proven by keymap.spec.ts.

- ShortcutsService resolves against the effective keymap: claim() takes
  the key (preventDefault, held keys repeat only movement, never mid-IME),
  and from a text field only chords and F-keys fire. The file panel, App,
  editor, manager and Settings windows all dispatch through it.
- FileActionsService.run is the one file-command dispatcher for the list
  keys, the row menu, the macOS menu bar and the toolbar.
- New keys: the row menu (Shift+F10 / Menu / Ctrl+Return), the source
  picker (Mod+K), the path bar (Mod+L), transfers (Mod+J), sorting
  (Alt+1-7), Shift+movement selection, close other tabs, move and
  disconnect tabs, refresh and edit on Windows/Linux, permissions, copy
  path, reveal, trash, open in default app, editor find next/previous.
- Right-click menus: soft shortcut hints, icons on the everyday verbs
  (the toolbar's glyphs), section headers, scrolling, item keys while
  open, a highlighted first item when opened from the keyboard. The panel
  source picker now renders through the same menu.
- Dialogs: role=dialog, a Tab trap via cycleFocus (WKWebView skips
  buttons on Tab without Keyboard navigation), initial focus, Esc that
  stops propagating; the chmod dialog takes focus and applies on Enter.
- Fixed: Ctrl+Tab also flipped the active panel; Esc in a manager dialog
  closed the manager; Ctrl-F/T fired Cmd shortcuts on macOS; shortcuts
  fired under dialogs; keys died after any button click on macOS; the
  editor's save prompt and find box never got focus; WebView2 reload keys;
  a window could save default settings before its first load.
- Settings closes on its own close-window key (new settingsClose request).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-10-05 14:48:11 +02:00
co-authored by Claude
parent 0eb5608873
commit d361297690
44 changed files with 2531 additions and 700 deletions
+139 -26
View File
@@ -78,9 +78,12 @@ Re-opening focuses the existing window. The webview fetches its own content
**Close safety** (designed when electrobun window `close` was NOT cancellable —
1.18.1 had no `allow` response like `before-quit`; 2.x adds a cancellable
`will-close` for the titlebar close, not used yet — see gotchas):
1. ⌘W (routed via the app menu → `editorCloseRequest`) / Close button →
styled in-window Save/Don't Save/Cancel; the confirm path calls
`editorClose` which sets `suppressPrompt` before `win.close()`.
1. ⌘W (the page's own `close-window` key; a ⌘W it doesn't claim falls through
to the app menu, which bun routes back as `editorCloseRequest`) / Close
button → styled in-window Save/Don't Save/Cancel, which takes focus (Save;
⌘S = Save, Esc = Cancel, Tab cycles) so keys can't edit the text behind it;
the confirm path calls `editorClose` which sets `suppressPrompt` before
`win.close()`.
2. Traffic-light close → the window is already gone, but the editor mirrored
its draft to bun (`editorState`, 400 ms debounce + flush on blur/dirty-flip)
→ native Save/Discard box from the held draft. A failed save (dead session)
@@ -96,7 +99,11 @@ to the main window (panels showing that directory refresh). Editor upgrades:
scroll-synced line gutter (hidden when wrap is on — wrapped line numbers would
need per-edit height measurement), Alt/⌥Z wrap toggle, custom find bar
(matches computed in TS, `setSelectionRange` + scrollTop math — deliberately
not `findInPage`, which is a shim on WebView2).
not `findInPage`, which is a shim on WebView2). Find next / previous (⌘G /
⇧⌘G, F3 / ⇧F3) step from the caret with the bar open or closed — the query
survives closing it. Focus after a state change goes through
`afterNextRender({ injector })`: under zoneless CD a microtask runs BEFORE the
render that creates the `@if` element.
### Connection-manager window (`src/bun/manager-window.ts`)
@@ -119,11 +126,12 @@ would float over editor windows).
Single instance, centered over main, **not modal**: every control is a plain
`SettingsService` setter, so each edit is an ordinary save that bun
rebroadcasts — the other windows follow live while it stays open. Opened by
the tab-bar gear and Ctrl+, (`openSettings` from main) and, on macOS, the app
menu's "Settings…" (⌘,, which the menu intercepts first). Its RPC serves only
`getSettings`/`saveSettings`/`pickEditorApp`/`showAbout`. ⌘W reaches bun as
the main window's `close-tab` menu action, so bun checks the Settings window's
focus FIRST and closes it (see gotchas). Sidebar sections: Appearance,
the tab-bar gear and the open-settings key (⌘, / Ctrl+,, `openSettings` from
main) and, on macOS, the app menu's "Settings…". Its RPC serves only
`getSettings`/`saveSettings`/`pickEditorApp`/`showAbout`/`settingsClose`. Its
page claims its own close-window key (`settingsClose`); a ⌘W it doesn't claim
falls through to the app menu's Close Tab, and bun checks the Settings
window's focus FIRST and closes it (see gotchas). Sidebar sections: Appearance,
Transfers, Editor, File list (visible columns — the column-header right-click
menu toggles the same setting), About (opens the native About box). The
native title is `options.title`, retitled on a locale switch.
@@ -251,11 +259,22 @@ component; tokens → `ui/src/styles.css`.
save too — the scale shortcuts — and the Settings window is nothing but
saves); bun's `settingsSaved()` in index.ts runs the
side effects once and rebroadcasts to every window **except the sender**, so
there is no echo to fight a held Cmd+. `applyAll` never persists. New setting
= five touches here + types.ts (backend merges automatically).
there is no echo to fight a held Cmd+. `applyAll` never persists. Saves are
whole-object, so **nothing persists until the first `getSettings` landed**
(`loaded`): a ⌘+ pressed while a window opens would otherwise write the
defaults over every remap. New setting = five touches here + types.ts
(backend merges automatically; sanitize hand-editable shapes in
`SettingsStore.load`).
- `focus.service.ts` — dependency-free `tick`/`bump()`; dialogs bump it, the
main window's panels listen. Exists so dialogs don't inject PanelsService
(whose constructor spawns a workspace — fatal in secondary windows).
main window's panels listen — but a panel only takes focus while NO dialog or
menu is up (a run of overwrite questions reuses one dialog instance; focusing
the list behind it handed Enter/Delete to the panel). Exists so dialogs don't
inject PanelsService (whose constructor spawns a workspace — fatal in
secondary windows).
- `shortcuts.service.ts` — the keyboard layer over `src/shared/keymap.ts`; see
"Keyboard" below.
- `focus-cycle.ts` — `cycleFocus(root, event)`: Tab / ⇧Tab by hand (see
"Keyboard").
- `connections.service.ts` — store mirror + ssh-config hosts; reloads on the
`connectionsChanged` push.
- `i18n.service.ts` — runtime translator. `locale` signal + `t('ns.key', params)`
@@ -267,20 +286,42 @@ component; tokens → `ui/src/styles.css`.
/`speed()` so the file list reformats on switch. `SettingsService.applyLocale`
resolves the `locale` setting (`system` → `navigator.language`) into it, on
boot and on the `settingsChanged` broadcast (so editor/manager windows follow).
- `file-actions.service.ts` — toolbar/keyboard/context-menu file ops, always
against an explicit panel; `menuTarget` remembers the right-clicked row.
- `file-actions.service.ts` — **one file-command dispatcher**,
`run(id, { side, panel, entry })`, for every entry point: list keys (the
cursor row), row-menu picks (the right-clicked row, captured in the menu's
`onPick` closure), the macOS menu bar's File/View items and the panel
toolbar. Ids are keymap `FileCommand`s (`open`, `open-default`, `send`,
`edit`, `rename`, `new-folder`, `new-file`, `chmod`, `delete`, `trash`,
`copy-path`, `reveal`, `refresh`, `sort-*`). Selection if any, else the
target row; `..` stands for the folder. `open` enters folders and opens a
LOCAL file in its default app only when `openFilesOnEnter` is set (Settings
→ File list); `open-default` (the menu's Open on a local file) always does.
`trash` walks the selection one `moveToTrash` at a time. Main-window only
(it injects TransfersService).
- `context-menu.service.ts` + `skins/shadlike/context-menu.ts` — the panel and tab right-click
menus, in HTML. Electrobun's native `showContextMenu` is a no-op on Linux, so it was
retired on ALL platforms rather than kept as a second code path (see
platform-notes.md). The service builds the item list (row / empty-space menu,
and the header column picker) and holds the open request as a signal; the
component renders it at the pointer with edge-flip clamping, arrow/Enter/Escape
keys, and close-on-blur/resize/scroll. Picked items are emitted verbatim as
`ctx-*` / `col:*` / `tab:*` strings through `RpcService.emitMenuAction`, so they
land in the SAME `App.handleMenuAction` dispatcher the macOS app menubar uses —
one handler, two sources. The three shell actions the webview cannot perform
(reveal, open-with-default, copy path) go back to bun via the `shellItemAction`
RPC, which is all that remains of the old native menu.
the header column picker, and the panel **source picker** — Local, drives,
connections under per-stack `header` items, `~/.ssh/config` hosts — which
replaced a bespoke popover so it gets the same keys and look) and holds the
open request as a signal; the component renders it at a point
(`MenuPoint`: a MouseEvent, or a row rect for a keyboard-opened menu) with
edge-flip clamping, a scrolling clamped box, and close-on-blur/resize/scroll.
Items carry `shortcut` (a keymap id: its first key is the soft hint at 60%
of the row colour, and pressing it while the menu is open picks the item)
and `icon` (drawn in the check column; only the everyday verbs get one —
Send, Edit, Rename, Delete, New Folder, New/Close Tab, the toolbar's own
glyphs). Keys: ↑↓ Home End move the one highlight (mouse hover shares it),
Enter/Space pick, Esc closes, items are not Tab stops; every handled key
stops propagation so the window handler never runs it twice. A keyboard-opened
menu starts with its first item highlighted (`initialIndex`). A request's
`onPick` takes the pick (row menu → `FileActionsService.run`, source picker →
`FilePanel`); otherwise `col:*` / `tab:*` strings go through
`RpcService.emitMenuAction` to the SAME `App.handleMenuAction` dispatcher the
macOS app menubar uses. The three shell actions the webview cannot perform
(reveal, open-with-default, copy path) go back to bun via the
`shellItemAction` RPC, which is all that remains of the old native menu.
`tabItems()` builds the workspace-tab menu (`tab:new`, and
`tab:close|close-others|close-right|disconnect:<id>`), served by
`PanelsService.closeOtherWorkspaces` / `closeWorkspacesToRight` /
@@ -298,9 +339,12 @@ component; tokens → `ui/src/styles.css`.
the build never checks them: an unregistered name renders nothing (console error
only), so every name used anywhere must be listed here.
- `platform.ts` — preload-global readers (`PLATFORM`, `APP_MODE`,
`EDITOR_CONTEXT`, `IS_MAC`/`IS_MAC_CHROME`, `IS_WINDOWS`, `IS_LINUX`,
`MOD_LABEL`/`ALT_LABEL`) + `blockNativeContextMenu` (kills WebKit's
Reload/Inspect menu outside text fields — the app draws its own menu instead).
`EDITOR_CONTEXT`, `IS_MAC`/`IS_MAC_CHROME`, `IS_WINDOWS`, `IS_LINUX`) +
`blockNativeContextMenu` (kills WebKit's Reload/Inspect menu outside text
fields — the app draws its own menu instead) + `blockReloadKeys` (swallows
unclaimed F5 / Ctrl+R / Ctrl+F5 / Ctrl+Shift+R on Windows, where WebView2
would reload the page and drop every session; each window root calls it
last).
- `updater.service.ts` — auto-updater state for the tab-bar pill. Signals
`state` (`idle→available→downloading→ready`|`error`), `version`, `progress`.
Subscribes the `updateStatus` push (backend `Updater.checkForUpdate` on
@@ -310,6 +354,75 @@ component; tokens → `ui/src/styles.css`.
`src/bun/index.ts`; feed is `release.baseUrl` (`https://miniscp.com/dl`, the
`/dl` host in `site/`). See build-and-release.md "Auto-updater".
## Keyboard
**One keymap** — `src/shared/keymap.ts`, shared so the webviews and bun (the
macOS menu bar) read the same table. `BINDINGS` lists every command: `id`,
`group` (Settings sections), `scopes`, and default combos per platform
(`mac` / `other`, best first: the first is the hint menus and tooltips show).
Combos are platform-neutral strings (`Mod+Shift+N`: Mod = ⌘ on macOS, Ctrl
elsewhere; `Ctrl` a literal ⌃ only macOS tells apart). Letters match the
layout's character (AZERTY's A is A) and fall back to the physical key under
Alt (⌥Z types Ω) and on non-Latin layouts; digits match physically (AZERTY
types "&" on 1); punctuation by character first (AZERTY's comma is on the M
key), physical second (⇧] makes "}"). **Matching is exact**: ⌃F is not ⌘F,
Ctrl+Tab is not Tab, and neither the Windows key nor AltGr is ever part of a
binding. `effectiveKeymap(overrides)` applies `AppSettings.keybindings`
(rows that differ from the defaults; `[]` unbinds) and drops anything
malformed. `conflicts()` / `ownerOf()` work over overlapping scopes; the
spec (`keymap.spec.ts`) proves the defaults conflict-free, round-trippable and
unshadowed on both platforms.
**Scopes.** `panel` = the focused file list (navigation, file commands,
sorting); `main` = anywhere in the main window (tabs, window commands); `editor`
/ `manager` / `settings` per window; `any` = every window (interface scale).
`panel` sits inside `main`, so they conflict-check together.
**`ShortcutsService`** resolves keydowns against the effective keymap
(reactive: a remap applies live in every window via the settings broadcast) and
formats hints — `label(id)` / `labels(id)` / `tip(text, id)` /
`tipFixed(text, 'Shift+Enter')`, with **localized key names** off macOS
(`keys.names.*`: German says Strg+Entf). `claim()` = resolve + `preventDefault`
(so the macOS menu never runs it twice) + auto-repeat only for movement-like
commands (holding ⌘W closes one tab). IME composition is never a shortcut.
From a text field only `firesInTextField()` combos count: ⌘/Ctrl and Alt chords
and F-keys, but not plain keys, not text-editing chords (⌘⌫, ⌥←, ⌘A) and not
Ctrl+Alt off macOS (AltGr).
**Dispatch** (one place per window): an open context menu owns its keys; an
open dialog owns Enter / Esc / Tab while the main window swallows window
commands and the panel commands the macOS menu bar carries (an unclaimed ⌘T
would otherwise reach the menu and open a tab behind the dialog); the focused
list (`FilePanel.onKeydown`) runs, in order, the fixed filter-editing keys
while a query is typed, the `panel` keymap (Shift + a movement key extends the
selection over the rows passed — a fixed rule that follows remaps), lets
`main` matches bubble, then type-to-filter, then Esc's fixed chain (clear the
filter → cancel a connect → clear the selection); `App` runs `main`. Every root
ends with `blockReloadKeys`. Keys that land on `<body>` (a click dropped focus)
are forwarded to the active list (`PanelsService.forwardListKey`), and `App`'s
`(mousedown)` keeps focus on the list after chrome-button clicks.
**macOS key equivalents are page-first.** WKWebView hands ⌘-keys to the page
before the app menu (WebKit `WebViewImpl::performKeyEquivalent`); only keys the
page doesn't `preventDefault` reach the menu bar. So the page owns every app
shortcut, and a window that doesn't claim a key lets it fall through to the
menu (⌘W in a window whose close-window was remapped away still hits Close Tab,
which bun routes to the focused Settings / editor window first).
**Focus without Keyboard navigation.** WKWebView's Tab skips buttons,
checkboxes and radios unless the user turned on System Settings → Keyboard →
Keyboard navigation, so `cycleFocus(root, event)` walks Tab / ⇧Tab by hand
(DOM order, wrap, a radio group is one stop): every dialog (it is also their
focus trap), the transfer list (⌘J opens it focused), the editor's save prompt.
Dialogs carry `role="dialog" aria-modal`, take initial focus (the chmod dialog
on its octal field, Enter applies) and stop Esc from propagating — a
window-level Esc (the connection manager closes on it) must not see it too. A
base-layer `:focus-visible` ring in `--ring` marks the focused control.
**Opening a row's menu from the keyboard**: ⇧F10 / the Menu key / ⌃↩ (macOS)
open the cursor row's menu under the row, first item highlighted; the
selection is kept, its commands act on it like the F-keys do.
## Theming
`ui/src/styles.css`: OKLCH tokens adapted from **Oxide's design system**
+54 -5
View File
@@ -136,11 +136,18 @@ touching the adjacent code.
update-initiated) — a plain `Utils.quit()` there quits without installing.
`Utils.quit()` runs the same approval, which is why the guard checks
`quitConfirmed` first.
- **⌘W in any secondary window arrives as the MAIN window's `close-tab`
menu action** (macOS: the app menu intercepts it before the webview sees
the key). bun must check the focused secondary window first — the Settings
window, then editors — and close THAT; a new window kind that skips this
check makes ⌘W close a main-window tab behind it.
- **macOS ⌘-keys go to the PAGE first; only unclaimed ones reach the app
menu.** WKWebView's `performKeyEquivalent` hands key equivalents to the page
while the webview is first responder (WebKit `WebViewImpl.mm`: "lets
webpages have a crack at intercepting key-modified keypresses"); a key the
page `preventDefault`s never reaches the menu. Old comments here claimed the
opposite ("the menu intercepts ⌘W first") — what was really happening is that
windows which didn't claim ⌘W let it fall through to the menu's Close Tab.
Two consequences: a handled shortcut MUST `preventDefault` (`claim()` does),
or the menu runs it a second time; and a ⌘W a secondary window doesn't claim
still arrives as the MAIN window's `close-tab` action — bun checks the
focused Settings window, then editors, first and closes THAT, so a new
window kind must either claim close-window or join that check.
- **One rpc instance per window** — BrowserView binding steals the rpc's
transport; a shared instance silently sends to the wrong webview.
- **RPC before socket open was silently lost on 1.18.1.** 2.x Electroview queues
@@ -270,6 +277,44 @@ touching the adjacent code.
`libayatana-appindicator is deprecated. Please use libayatana-appindicator-glib`
(upstream electrobun's choice, not ours).
## Keyboard (`src/shared/keymap.ts`, `ui/src/app/core/shortcuts.service.ts`)
- **WKWebView skips buttons, checkboxes and radios on Tab** unless the user
turned on System Settings → Keyboard → Keyboard navigation (or presses ⌥Tab).
Dialogs, Settings and the manager were mouse-only on a default Mac. Tab is
walked by hand: `cycleFocus(root, event)` (core/focus-cycle.ts) — use it in
any new dialog or window.
- **WebKit doesn't focus a clicked button — focus drops to `<body>`** (Windows
parks it on the button, where Space clicks it again). Every list key died
until the list was clicked. `App` `(mousedown)` keeps focus on chrome-button
clicks and forwards `<body>` keys to the active list; keep both.
- **Match modifiers exactly.** The old panel switch caught every Tab, so
Ctrl+Tab flipped the active panel AND switched tabs; `isMod = metaKey ||
ctrlKey` made ⌃F (Cocoa's forward-one-character) open the editor's find.
`matchesEvent` compares all four modifiers, platform-exact.
- **AltGr is Ctrl+Alt on Windows/Linux.** A Ctrl+Alt+letter binding steals
"@", "€", "ł"… — never a default there, never fired from a text field, and
an event with `getModifierState('AltGraph')` matches nothing.
- **Type-to-filter takes every printable key.** A plain-letter binding (vim
j/k) must resolve BEFORE it — and then that letter no longer starts a query
(Settings warns). While a query is being typed, printable keys (Space too)
always extend it.
- **A dialog's Esc must `stopPropagation`.** The connection manager closes on
a window-level Escape; the dialog cleared its own signal first, so the
window handler saw "no dialog open" and closed the whole window.
- **An unclaimed key behind a dialog reaches the macOS menu** — ⌘T opened a
tab behind the rename prompt. The main window swallows window commands and
the menu bar's panel commands while a dialog or menu is up.
- **WebView2 reloads the page on unclaimed F5 / Ctrl+R** (default browser
accelerators), dropping every session and the editor's unsaved text. Every
window root ends with `blockReloadKeys`; a blanket `stopPropagation` (the old
path bar) hides keys from it — don't add one.
- **Hold-to-repeat** fired ⌘W once per repeat — every tab closed. `claim()`
repeats only movement-like commands (`isRepeatable`).
- **Focus after a state change needs `afterNextRender({ injector })`.** Under
zoneless CD `queueMicrotask` runs before the render that creates an `@if`
element (the editor's find box and textarea), so `.focus()` hit nothing.
## Domain logic
- **sessionId ≠ filesystem identity.** Two panels on the same server are two
@@ -287,6 +332,10 @@ touching the adjacent code.
- Settings: the backend spread-merges (`{...DEFAULT_SETTINGS, ...data}`) so
new keys auto-default, but the UI SettingsService reads field-by-field —
a new setting silently stays at default until wired in all five spots.
- **Saves are whole-object: a window must not save before its first
`getSettings` landed.** A ⌘+ pressed while an editor opened wrote
`DEFAULT_SETTINGS` (no keyboard remaps) over the user's file.
`SettingsService.persist()` is a no-op until `applyAll` ran once.
- **Every window's RPC must serve `saveSettings`.** The scale shortcuts
shipped in editor and manager windows while only the main RPC served it:
the request went unanswered, the change applied locally, and main's next
+5 -1
View File
@@ -17,7 +17,11 @@ Every platform seam carries a `PORTABILITY:` comment at the branch site.
| Drive roots | `fs/local.ts listLocalDrives` | empty | `fsutil fsinfo drives` | empty |
| chmod/Permissions | context-menu.service.ts, file-panel, file-actions | full | hidden for LOCAL panels (only flips read-only); SFTP unaffected | full |
| Shell wording | `ui context-menu.service.ts` | Reveal in Finder / Move to Trash | Show in Explorer / Move to Recycle Bin | Show in File Manager |
| Shortcut labels | `ui platform.ts MOD_LABEL/ALT_LABEL` | ⌘ / ⌥ | Ctrl+ / Alt+ | Ctrl+ / Alt+ |
| Shortcut labels | `src/shared/keymap.ts formatCombo` (+ `keys.names.*`) | ⌘⇧⌥⌃ glyphs: ⇧⌘N | Ctrl+Shift+N, localized key names (Strg+Entf) | as Windows |
| Command modifier | `keymap.ts` `Mod` | ⌘ only (⌃ stays Cocoa's text keys) | Ctrl | Ctrl |
| Key equivalents | `shortcuts.service.ts claim` | page first, unclaimed → app menu | page only (no app menu) | page only |
| Tab focus | `core/focus-cycle.ts cycleFocus` | WKWebView skips buttons/checkboxes without Keyboard navigation → walked by hand | native order (same walk) | native order (same walk) |
| Reload keys | `platform.ts blockReloadKeys` | — | WebView2 reloads on F5 / Ctrl+R → swallowed when unclaimed | — |
| Tray | `src/bun/tray.ts` | 22 pt template PNG | 16 px colored PNG | colored (needs AppIndicator, see below) |
| App menu | `src/bun/menu.ts` | full menu incl. About | none (early return) — Settings opens from the tab-bar gear (Ctrl+,), About from its About section | none (unsupported upstream) |
| connections.json protection | `store/connections.ts` | chmod 0600 | `icacls` current-user ACL (0600 is meaningless) | 0600 |
+7
View File
@@ -467,6 +467,8 @@ export interface SettingsRpcHooks {
/** Every edit here is a settings save — rebroadcast it to the other windows. */
onSettingsSaved: (next: AppSettings) => void;
showAbout: () => void;
/** The window's own close-window key. */
close: () => void;
}
/** RPC for the single Settings window (per-window instance). */
@@ -483,6 +485,11 @@ export function createSettingsRPC(deps: { settings: SettingsStore }, hooks: Sett
hooks.showAbout();
return {};
}),
settingsClose: () =>
wrap(async () => {
hooks.close();
return {};
}),
},
},
});
+4 -3
View File
@@ -23,9 +23,9 @@ export interface SettingsWindowDeps {
/**
* The single Settings window. Unlike the connection manager it is NOT modal:
* every edit is an ordinary settings save, so the other windows follow live
* while it stays open. On macOS ⌘W reaches bun as the main window's close-tab
* menu action, so index.ts asks isFocused() first and closes this window
* instead of a main-window tab.
* while it stays open. Its page claims its own close-window key (settingsClose).
* A ⌘W it doesn't claim (remapped away) falls through to the app menu's Close
* Tab, which index.ts routes here while this window is focused.
*/
export class SettingsWindow {
private win: BrowserWindow | null = null;
@@ -49,6 +49,7 @@ export class SettingsWindow {
{
onSettingsSaved: (next) => this.deps.onSettingsSaved(next),
showAbout: () => this.deps.showAbout(),
close: () => this.close(),
},
);
+4
View File
@@ -1,5 +1,6 @@
import fs from "node:fs/promises";
import path from "node:path";
import { sanitizeKeybindings } from "../../shared/keymap";
import { clampUiScale, DEFAULT_SETTINGS, type AppSettings } from "../../shared/types";
import { appDataDir } from "./paths";
@@ -24,6 +25,9 @@ export class SettingsStore {
// into every window's root font-size, so a hand-edited settings.json
// (uiScale: 100, "2", NaN) must not be able to render the UI unusable
settings.uiScale = clampUiScale(Number(settings.uiScale));
// same reasoning: every window resolves keys through this map
settings.keybindings = sanitizeKeybindings(data.keybindings);
settings.openFilesOnEnter = data.openFilesOnEnter === true;
return settings;
} catch {
return { ...DEFAULT_SETTINGS };
+34 -14
View File
@@ -21,8 +21,8 @@ export const de = {
tabBar: {
connections: "Verbindungen",
manageConnections: "Verbindungen verwalten",
newTab: "Neuer Tab ({mod}T)",
closeTab: "Tab schließen ({mod}W)",
newTab: "Neuer Tab",
closeTab: "Tab schließen",
options: "Einstellungen",
update: "Update verfügbar",
updating: "Aktualisiere",
@@ -75,17 +75,16 @@ export const de = {
panel: {
choosePanel: "Wählen, was dieses Panel anzeigt",
copy: "Senden",
copyToRight: "An rechtes Panel senden (F5)",
copyToLeft: "An linkes Panel senden (F5)",
copyToRight: "An rechtes Panel senden",
copyToLeft: "An linkes Panel senden",
edit: "Bearbeiten",
editFile: "Datei bearbeiten (F4)",
rename: "Umbenennen (F2)",
newFolder: "Neuer Ordner (F7)",
editFile: "Datei bearbeiten",
rename: "Umbenennen",
newFolder: "Neuer Ordner",
newFile: "Neue Datei",
permissions: "Berechtigungen",
delete: "Löschen",
deleteHint: "Löschen (F8 / Entf)",
parentDir: "Übergeordneter Ordner (Rücktaste)",
parentDir: "Übergeordneter Ordner",
refresh: "Aktualisieren",
clearFilter: "Filter löschen (Esc)",
sshConfig: "~/.ssh/config",
@@ -144,16 +143,16 @@ export const de = {
noFileTitle: "Keine Datei zum Bearbeiten",
noFileBody: "Dieses Fenster wurde ohne Editor-Kontext geöffnet. Öffne Dateien aus der App.",
wrap: "Umbruch",
wrapHint: "Lange Zeilen umbrechen — blendet Zeilennummern aus ({alt}Z)",
findHint: "Suchen ({mod}F)",
wrapHint: "Lange Zeilen umbrechen — blendet Zeilennummern aus",
findHint: "Suchen",
findPlaceholder: "In Datei suchen",
prevMatch: "Vorheriger Treffer (⇧↵)",
nextMatch: "Nächster Treffer (↵)",
prevMatch: "Vorheriger Treffer",
nextMatch: "Nächster Treffer",
closeHint: "Schließen (Esc)",
disconnected: "Verbindung zu {name} getrennt — Speichern schlägt fehl, aber dein Text bleibt in diesem Fenster erhalten.",
cantOpen: "{name} kann nicht geöffnet werden",
closeWindow: "Fenster schließen",
shortcuts: "{mod}S speichern · {mod}F suchen · {mod}W schließen",
verbs: { save: "speichern", find: "suchen", close: "schließen" },
lines: { one: "{count} Zeile", other: "{count} Zeilen" },
close: "Schließen",
save: "Speichern",
@@ -209,6 +208,7 @@ export const de = {
},
toasts: {
movedToTrash: '„{name}" in den Papierkorb verschoben',
movedManyToTrash: { one: "{count} Objekt in den Papierkorb verschoben", other: "{count} Objekte in den Papierkorb verschoben" },
editingExternal: "Bearbeite {name} — Speichern lädt automatisch hoch",
nothingToCopy: "Nichts zu kopieren (symbolische Links werden übersprungen)",
nothingToCopyAllSkipped: "Nichts zu kopieren — alle Konflikte wurden übersprungen",
@@ -292,6 +292,26 @@ export const de = {
tabDisconnect: "Trennen",
trashTooltip: "Finders Wiederherstellen ist für von hier gelöschte Elemente nicht verfügbar",
},
keys: {
names: {
ctrl: "Strg",
alt: "Alt",
shift: "Umschalt",
enter: "Eingabe",
backspace: "Rücktaste",
del: "Entf",
esc: "Esc",
space: "Leertaste",
tab: "Tab",
pgup: "Bild↑",
pgdn: "Bild↓",
home: "Pos1",
end: "Ende",
ins: "Einfg",
menu: "Menü",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent nicht verfügbar (SSH_AUTH_SOCK ist nicht gesetzt)",
identityFileNotFound: "Identitätsdatei nicht gefunden: {path}",
+110 -14
View File
@@ -25,8 +25,8 @@ export const en = {
tabBar: {
connections: "Connections",
manageConnections: "Manage connections",
newTab: "New tab ({mod}T)",
closeTab: "Close tab ({mod}W)",
newTab: "New tab",
closeTab: "Close tab",
options: "Settings",
update: "Update available",
updating: "Updating",
@@ -79,17 +79,16 @@ export const en = {
panel: {
choosePanel: "Choose what this panel shows",
copy: "Send",
copyToRight: "Send to right panel (F5)",
copyToLeft: "Send to left panel (F5)",
copyToRight: "Send to right panel",
copyToLeft: "Send to left panel",
edit: "Edit",
editFile: "Edit file (F4)",
rename: "Rename (F2)",
newFolder: "New folder (F7)",
editFile: "Edit file",
rename: "Rename",
newFolder: "New folder",
newFile: "New file",
permissions: "Permissions",
delete: "Delete",
deleteHint: "Delete (F8 / Del)",
parentDir: "Parent directory (Backspace)",
parentDir: "Parent directory",
refresh: "Refresh",
clearFilter: "Clear filter (Esc)",
sshConfig: "~/.ssh/config",
@@ -148,16 +147,17 @@ export const en = {
noFileTitle: "No file to edit",
noFileBody: "This window was opened without an editor context. Launch files from the app.",
wrap: "Wrap",
wrapHint: "Wrap long lines — hides line numbers ({alt}Z)",
findHint: "Find ({mod}F)",
wrapHint: "Wrap long lines — hides line numbers",
findHint: "Find",
findPlaceholder: "Find in file",
prevMatch: "Previous match (⇧↵)",
nextMatch: "Next match (↵)",
prevMatch: "Previous match",
nextMatch: "Next match",
closeHint: "Close (Esc)",
disconnected: "Disconnected from {name} — saving will fail, but your text is preserved in this window.",
cantOpen: "Can't open {name}",
closeWindow: "Close Window",
shortcuts: "{mod}S save · {mod}F find · {mod}W close",
// footer hint: "⌘S save · ⌘F find · ⌘W close", keys from the keymap
verbs: { save: "save", find: "find", close: "close" },
lines: { one: "{count} line", other: "{count} lines" },
close: "Close",
save: "Save",
@@ -213,6 +213,7 @@ export const en = {
},
toasts: {
movedToTrash: 'Moved "{name}" to Trash',
movedManyToTrash: { one: "Moved {count} item to Trash", other: "Moved {count} items to Trash" },
editingExternal: "Editing {name} — saves upload automatically",
nothingToCopy: "Nothing to copy (symlinks are skipped)",
nothingToCopyAllSkipped: "Nothing to copy — all conflicting items were skipped",
@@ -296,6 +297,101 @@ export const en = {
tabDisconnect: "Disconnect",
trashTooltip: "Finder's Restore is not available for items trashed from here",
},
// Keyboard commands — one label per src/shared/keymap.ts BINDINGS id
keys: {
"cursor-up": "Move up",
"cursor-down": "Move down",
"page-up": "Page up",
"page-down": "Page down",
"cursor-first": "First item",
"cursor-last": "Last item",
"toggle-select": "Select / deselect",
"select-all": "Select all",
open: "Open",
parent: "Parent folder",
"switch-panel": "Switch panel",
"row-menu": "Show the item's menu",
send: "Send to the other panel",
edit: "Edit",
rename: "Rename",
"new-folder": "New folder",
"new-file": "New file",
chmod: "Permissions",
delete: "Delete",
trash: "Move to Trash",
"copy-path": "Copy path",
reveal: "Reveal in file manager",
"open-default": "Open in default app",
refresh: "Refresh",
"focus-path": "Go to path",
"source-picker": "Choose what the panel shows",
"sort-name": "Sort by name",
"sort-size": "Sort by size",
"sort-mtime": "Sort by modified",
"sort-kind": "Sort by kind",
"sort-rights": "Sort by rights",
"sort-owner": "Sort by owner",
"sort-group": "Sort by group",
"new-tab": "New tab",
"close-tab": "Close tab",
"close-other-tabs": "Close other tabs",
"close-tabs-right": "Close tabs to the right",
"next-tab": "Next tab",
"prev-tab": "Previous tab",
"go-to-tab": "Go to tab {n}",
"go-to-last-tab": "Go to last tab",
"move-tab-left": "Move tab left",
"move-tab-right": "Move tab right",
"disconnect-tab": "Disconnect tab",
"open-settings": "Settings",
"connection-manager": "Connection manager",
"toggle-transfers": "Show / hide transfers",
"install-update": "Install update",
"scale-up": "Bigger interface",
"scale-down": "Smaller interface",
"scale-reset": "Interface at 100%",
"close-window": "Close window",
save: "Save",
find: "Find",
"find-next": "Find next",
"find-prev": "Find previous",
"toggle-wrap": "Wrap lines",
"conn-new": "New connection",
"conn-new-stack": "New stack",
"conn-save": "Save connection",
"conn-connect": "Connect / open stack",
"conn-delete": "Delete connection or stack",
"conn-rename-stack": "Rename stack",
"conn-import": "Import from WinSCP",
groups: {
panels: "File list",
files: "Files",
sort: "Sorting",
tabs: "Tabs",
window: "Window",
editor: "Editor",
connections: "Connection manager",
},
// key names for "Ctrl+Shift+Del"-style hints (not used on macOS, which shows ⌘⇧⌫)
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Shift",
enter: "Enter",
backspace: "Backspace",
del: "Del",
esc: "Esc",
space: "Space",
tab: "Tab",
pgup: "PgUp",
pgdn: "PgDn",
home: "Home",
end: "End",
ins: "Ins",
menu: "Menu",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent not available (SSH_AUTH_SOCK is not set)",
identityFileNotFound: "identity file not found: {path}",
+34 -14
View File
@@ -21,8 +21,8 @@ export const es = {
tabBar: {
connections: "Conexiones",
manageConnections: "Gestionar conexiones",
newTab: "Nueva pestaña ({mod}T)",
closeTab: "Cerrar pestaña ({mod}W)",
newTab: "Nueva pestaña",
closeTab: "Cerrar pestaña",
options: "Ajustes",
update: "Actualización disponible",
updating: "Actualizando",
@@ -75,17 +75,16 @@ export const es = {
panel: {
choosePanel: "Elige qué muestra este panel",
copy: "Enviar",
copyToRight: "Enviar al panel derecho (F5)",
copyToLeft: "Enviar al panel izquierdo (F5)",
copyToRight: "Enviar al panel derecho",
copyToLeft: "Enviar al panel izquierdo",
edit: "Editar",
editFile: "Editar archivo (F4)",
rename: "Renombrar (F2)",
newFolder: "Nueva carpeta (F7)",
editFile: "Editar archivo",
rename: "Renombrar",
newFolder: "Nueva carpeta",
newFile: "Nuevo archivo",
permissions: "Permisos",
delete: "Eliminar",
deleteHint: "Eliminar (F8 / Supr)",
parentDir: "Carpeta superior (Retroceso)",
parentDir: "Carpeta superior",
refresh: "Actualizar",
clearFilter: "Borrar filtro (Esc)",
sshConfig: "~/.ssh/config",
@@ -144,16 +143,16 @@ export const es = {
noFileTitle: "Ningún archivo que editar",
noFileBody: "Esta ventana se abrió sin contexto de editor. Abre archivos desde la aplicación.",
wrap: "Ajustar",
wrapHint: "Ajustar líneas largas — oculta los números de línea ({alt}Z)",
findHint: "Buscar ({mod}F)",
wrapHint: "Ajustar líneas largas — oculta los números de línea",
findHint: "Buscar",
findPlaceholder: "Buscar en el archivo",
prevMatch: "Coincidencia anterior (⇧↵)",
nextMatch: "Coincidencia siguiente (↵)",
prevMatch: "Coincidencia anterior",
nextMatch: "Coincidencia siguiente",
closeHint: "Cerrar (Esc)",
disconnected: "Desconectado de {name} — no se podrá guardar, pero tu texto se conserva en esta ventana.",
cantOpen: "No se puede abrir {name}",
closeWindow: "Cerrar ventana",
shortcuts: "{mod}S guardar · {mod}F buscar · {mod}W cerrar",
verbs: { save: "guardar", find: "buscar", close: "cerrar" },
lines: { one: "{count} línea", other: "{count} líneas" },
close: "Cerrar",
save: "Guardar",
@@ -209,6 +208,7 @@ export const es = {
},
toasts: {
movedToTrash: 'Se movió "{name}" a la papelera',
movedManyToTrash: { one: "Se movió {count} elemento a la papelera", other: "Se movieron {count} elementos a la papelera" },
editingExternal: "Editando {name} — los cambios se suben automáticamente",
nothingToCopy: "Nada que copiar (los enlaces simbólicos se omiten)",
nothingToCopyAllSkipped: "Nada que copiar — se omitieron todos los elementos en conflicto",
@@ -292,6 +292,26 @@ export const es = {
tabDisconnect: "Desconectar",
trashTooltip: "La opción Restaurar de Finder no está disponible para elementos enviados a la papelera desde aquí",
},
keys: {
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Mayús",
enter: "Intro",
backspace: "Retroceso",
del: "Supr",
esc: "Esc",
space: "Espacio",
tab: "Tab",
pgup: "RePág",
pgdn: "AvPág",
home: "Inicio",
end: "Fin",
ins: "Insert",
menu: "Menú",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent no disponible (SSH_AUTH_SOCK no está definido)",
identityFileNotFound: "archivo de identidad no encontrado: {path}",
+34 -14
View File
@@ -23,8 +23,8 @@ export const eu = {
tabBar: {
connections: "Konexioak",
manageConnections: "Kudeatu konexioak",
newTab: "Fitxa berria ({mod}T)",
closeTab: "Itxi fitxa ({mod}W)",
newTab: "Fitxa berria",
closeTab: "Itxi fitxa",
options: "Ezarpenak",
update: "Eguneratzea eskuragarri",
updating: "Eguneratzen",
@@ -77,17 +77,16 @@ export const eu = {
panel: {
choosePanel: "Aukeratu panel honek zer erakusten duen",
copy: "Bidali",
copyToRight: "Bidali eskuineko panelera (F5)",
copyToLeft: "Bidali ezkerreko panelera (F5)",
copyToRight: "Bidali eskuineko panelera",
copyToLeft: "Bidali ezkerreko panelera",
edit: "Editatu",
editFile: "Editatu fitxategia (F4)",
rename: "Berrizendatu (F2)",
newFolder: "Karpeta berria (F7)",
editFile: "Editatu fitxategia",
rename: "Berrizendatu",
newFolder: "Karpeta berria",
newFile: "Fitxategi berria",
permissions: "Baimenak",
delete: "Ezabatu",
deleteHint: "Ezabatu (F8 / Del)",
parentDir: "Karpeta gurasoa (Atzera-tekla)",
parentDir: "Karpeta gurasoa",
refresh: "Freskatu",
clearFilter: "Garbitu iragazkia (Esc)",
sshConfig: "~/.ssh/config",
@@ -146,16 +145,16 @@ export const eu = {
noFileTitle: "Ez dago editatzeko fitxategirik",
noFileBody: "Leiho hau editore-testuingururik gabe ireki da. Ireki fitxategiak aplikaziotik.",
wrap: "Doitu",
wrapHint: "Doitu lerro luzeak — lerro-zenbakiak ezkutatzen ditu ({alt}Z)",
findHint: "Bilatu ({mod}F)",
wrapHint: "Doitu lerro luzeak — lerro-zenbakiak ezkutatzen ditu",
findHint: "Bilatu",
findPlaceholder: "Bilatu fitxategian",
prevMatch: "Aurreko bat-etortzea (⇧↵)",
nextMatch: "Hurrengo bat-etortzea (↵)",
prevMatch: "Aurreko bat-etortzea",
nextMatch: "Hurrengo bat-etortzea",
closeHint: "Itxi (Esc)",
disconnected: "{name}(e)tik deskonektatuta — gordetzeak huts egingo du, baina zure testua leiho honetan gordeta dago.",
cantOpen: "Ezin da {name} ireki",
closeWindow: "Itxi leihoa",
shortcuts: "{mod}S gorde · {mod}F bilatu · {mod}W itxi",
verbs: { save: "gorde", find: "bilatu", close: "itxi" },
lines: { one: "lerro {count}", other: "{count} lerro" },
close: "Itxi",
save: "Gorde",
@@ -211,6 +210,7 @@ export const eu = {
},
toasts: {
movedToTrash: '"{name}" zakarrontzira eraman da',
movedManyToTrash: { one: "{count} elementu zakarrontzira eraman da", other: "{count} elementu zakarrontzira eraman dira" },
editingExternal: "{name} editatzen — gordetzean automatikoki igotzen da",
nothingToCopy: "Ez dago kopiatzeko ezer (esteka sinbolikoak saltatu egiten dira)",
nothingToCopyAllSkipped: "Ez dago kopiatzeko ezer — gatazkan zeuden elementu guztiak saltatu dira",
@@ -294,6 +294,26 @@ export const eu = {
tabDisconnect: "Deskonektatu",
trashTooltip: "Finder-en «Jarri berriro» ez dago erabilgarri hemendik zakarrontzira botatako elementuentzat",
},
keys: {
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Maius",
enter: "Intro",
backspace: "Atzera",
del: "Supr",
esc: "Esc",
space: "Zuriunea",
tab: "Tab",
pgup: "RePág",
pgdn: "AvPág",
home: "Inicio",
end: "Fin",
ins: "Insert",
menu: "Menua",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent ez dago erabilgarri (SSH_AUTH_SOCK ez dago ezarrita)",
identityFileNotFound: "identitate-fitxategia ez da aurkitu: {path}",
+34 -14
View File
@@ -21,8 +21,8 @@ export const fr = {
tabBar: {
connections: "Connexions",
manageConnections: "Gérer les connexions",
newTab: "Nouvel onglet ({mod}T)",
closeTab: "Fermer l'onglet ({mod}W)",
newTab: "Nouvel onglet",
closeTab: "Fermer l'onglet",
options: "Réglages",
update: "Mise à jour disponible",
updating: "Mise à jour",
@@ -75,17 +75,16 @@ export const fr = {
panel: {
choosePanel: "Choisir ce qu'affiche ce panneau",
copy: "Envoyer",
copyToRight: "Envoyer vers le panneau droit (F5)",
copyToLeft: "Envoyer vers le panneau gauche (F5)",
copyToRight: "Envoyer vers le panneau droit",
copyToLeft: "Envoyer vers le panneau gauche",
edit: "Éditer",
editFile: "Éditer le fichier (F4)",
rename: "Renommer (F2)",
newFolder: "Nouveau dossier (F7)",
editFile: "Éditer le fichier",
rename: "Renommer",
newFolder: "Nouveau dossier",
newFile: "Nouveau fichier",
permissions: "Autorisations",
delete: "Supprimer",
deleteHint: "Supprimer (F8 / Suppr)",
parentDir: "Dossier parent (Retour arrière)",
parentDir: "Dossier parent",
refresh: "Actualiser",
clearFilter: "Effacer le filtre (Échap)",
sshConfig: "~/.ssh/config",
@@ -144,16 +143,16 @@ export const fr = {
noFileTitle: "Aucun fichier à éditer",
noFileBody: "Cette fenêtre a été ouverte sans contexte d'éditeur. Ouvrez des fichiers depuis l'application.",
wrap: "Retour",
wrapHint: "Retour à la ligne — masque les numéros de ligne ({alt}Z)",
findHint: "Rechercher ({mod}F)",
wrapHint: "Retour à la ligne — masque les numéros de ligne",
findHint: "Rechercher",
findPlaceholder: "Rechercher dans le fichier",
prevMatch: "Résultat précédent (⇧↵)",
nextMatch: "Résultat suivant (↵)",
prevMatch: "Résultat précédent",
nextMatch: "Résultat suivant",
closeHint: "Fermer (Échap)",
disconnected: "Déconnecté de {name} — l'enregistrement échouera, mais votre texte est conservé dans cette fenêtre.",
cantOpen: "Impossible d'ouvrir {name}",
closeWindow: "Fermer la fenêtre",
shortcuts: "{mod}S enregistrer · {mod}F rechercher · {mod}W fermer",
verbs: { save: "enregistrer", find: "rechercher", close: "fermer" },
lines: { one: "{count} ligne", other: "{count} lignes" },
close: "Fermer",
save: "Enregistrer",
@@ -209,6 +208,7 @@ export const fr = {
},
toasts: {
movedToTrash: '« {name} » mis à la corbeille',
movedManyToTrash: { one: "{count} élément mis à la corbeille", other: "{count} éléments mis à la corbeille" },
editingExternal: "Édition de {name} — les enregistrements sont envoyés automatiquement",
nothingToCopy: "Rien à copier (les liens symboliques sont ignorés)",
nothingToCopyAllSkipped: "Rien à copier — tous les éléments en conflit ont été ignorés",
@@ -292,6 +292,26 @@ export const fr = {
tabDisconnect: "Déconnecter",
trashTooltip: "La restauration du Finder n'est pas disponible pour les éléments mis à la corbeille d'ici",
},
keys: {
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Maj",
enter: "Entrée",
backspace: "Retour arrière",
del: "Suppr",
esc: "Échap",
space: "Espace",
tab: "Tab",
pgup: "Pg préc",
pgdn: "Pg suiv",
home: "Début",
end: "Fin",
ins: "Inser",
menu: "Menu",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent indisponible (SSH_AUTH_SOCK non défini)",
identityFileNotFound: "fichier d'identité introuvable : {path}",
+34 -14
View File
@@ -22,8 +22,8 @@ export const ja = {
tabBar: {
connections: "接続",
manageConnections: "接続を管理",
newTab: "新しいタブ ({mod}T)",
closeTab: "タブを閉じる ({mod}W)",
newTab: "新しいタブ",
closeTab: "タブを閉じる",
options: "設定",
update: "アップデートあり",
updating: "更新中",
@@ -76,17 +76,16 @@ export const ja = {
panel: {
choosePanel: "このパネルに表示する内容を選択",
copy: "送信",
copyToRight: "右のパネルへ送信 (F5)",
copyToLeft: "左のパネルへ送信 (F5)",
copyToRight: "右のパネルへ送信",
copyToLeft: "左のパネルへ送信",
edit: "編集",
editFile: "ファイルを編集 (F4)",
rename: "名前を変更 (F2)",
newFolder: "新規フォルダ (F7)",
editFile: "ファイルを編集",
rename: "名前を変更",
newFolder: "新規フォルダ",
newFile: "新規ファイル",
permissions: "アクセス権",
delete: "削除",
deleteHint: "削除 (F8 / Del)",
parentDir: "親フォルダ (Backspace)",
parentDir: "親フォルダ",
refresh: "更新",
clearFilter: "フィルターをクリア (Esc)",
sshConfig: "~/.ssh/config",
@@ -145,16 +144,16 @@ export const ja = {
noFileTitle: "編集するファイルがありません",
noFileBody: "このウィンドウはエディタコンテキストなしで開かれました。アプリからファイルを開いてください。",
wrap: "折り返し",
wrapHint: "長い行を折り返す — 行番号を非表示 ({alt}Z)",
findHint: "検索 ({mod}F)",
wrapHint: "長い行を折り返す — 行番号を非表示",
findHint: "検索",
findPlaceholder: "ファイル内を検索",
prevMatch: "前の一致 (⇧↵)",
nextMatch: "次の一致 (↵)",
prevMatch: "前の一致",
nextMatch: "次の一致",
closeHint: "閉じる (Esc)",
disconnected: "{name} から切断されました — 保存は失敗しますが、テキストはこのウィンドウに保持されます。",
cantOpen: "{name} を開けません",
closeWindow: "ウィンドウを閉じる",
shortcuts: "{mod}S 保存 · {mod}F 検索 · {mod}W 閉じる",
verbs: { save: "保存", find: "検索", close: "閉じる" },
lines: { other: "{count} 行" },
close: "閉じる",
save: "保存",
@@ -210,6 +209,7 @@ export const ja = {
},
toasts: {
movedToTrash: '"{name}" をゴミ箱に移動しました',
movedManyToTrash: { other: "{count} 個の項目をゴミ箱に移動しました" },
editingExternal: "{name} を編集中 — 保存すると自動でアップロードされます",
nothingToCopy: "コピーする項目がありません(シンボリックリンクはスキップされます)",
nothingToCopyAllSkipped: "コピーする項目がありません — 競合する項目はすべてスキップされました",
@@ -292,6 +292,26 @@ export const ja = {
tabDisconnect: "切断",
trashTooltip: "ここからゴミ箱に入れた項目は Finder の「戻す」を利用できません",
},
keys: {
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Shift",
enter: "Enter",
backspace: "Backspace",
del: "Del",
esc: "Esc",
space: "スペース",
tab: "Tab",
pgup: "PgUp",
pgdn: "PgDn",
home: "Home",
end: "End",
ins: "Ins",
menu: "メニュー",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent が利用できません(SSH_AUTH_SOCK が未設定)",
identityFileNotFound: "認証鍵ファイルが見つかりません: {path}",
+34 -14
View File
@@ -22,8 +22,8 @@ export const zh = {
tabBar: {
connections: "连接",
manageConnections: "管理连接",
newTab: "新建标签页 ({mod}T)",
closeTab: "关闭标签页 ({mod}W)",
newTab: "新建标签页",
closeTab: "关闭标签页",
options: "设置",
update: "有可用更新",
updating: "正在更新",
@@ -76,17 +76,16 @@ export const zh = {
panel: {
choosePanel: "选择此面板显示的内容",
copy: "发送",
copyToRight: "发送到右侧面板 (F5)",
copyToLeft: "发送到左侧面板 (F5)",
copyToRight: "发送到右侧面板",
copyToLeft: "发送到左侧面板",
edit: "编辑",
editFile: "编辑文件 (F4)",
rename: "重命名 (F2)",
newFolder: "新建文件夹 (F7)",
editFile: "编辑文件",
rename: "重命名",
newFolder: "新建文件夹",
newFile: "新建文件",
permissions: "权限",
delete: "删除",
deleteHint: "删除 (F8 / Del)",
parentDir: "上级目录 (退格)",
parentDir: "上级目录",
refresh: "刷新",
clearFilter: "清除筛选 (Esc)",
sshConfig: "~/.ssh/config",
@@ -145,16 +144,16 @@ export const zh = {
noFileTitle: "没有要编辑的文件",
noFileBody: "此窗口在没有编辑器上下文的情况下打开。请从应用中打开文件。",
wrap: "换行",
wrapHint: "长行自动换行 — 隐藏行号 ({alt}Z)",
findHint: "查找 ({mod}F)",
wrapHint: "长行自动换行 — 隐藏行号",
findHint: "查找",
findPlaceholder: "在文件中查找",
prevMatch: "上一个匹配 (⇧↵)",
nextMatch: "下一个匹配 (↵)",
prevMatch: "上一个匹配",
nextMatch: "下一个匹配",
closeHint: "关闭 (Esc)",
disconnected: "已从 {name} 断开 — 保存将失败,但你的文本会保留在此窗口中。",
cantOpen: "无法打开 {name}",
closeWindow: "关闭窗口",
shortcuts: "{mod}S 保存 · {mod}F 查找 · {mod}W 关闭",
verbs: { save: "保存", find: "查找", close: "关闭" },
lines: { other: "{count} 行" },
close: "关闭",
save: "保存",
@@ -210,6 +209,7 @@ export const zh = {
},
toasts: {
movedToTrash: '已将 "{name}" 移到废纸篓',
movedManyToTrash: { other: "已将 {count} 个项目移到废纸篓" },
editingExternal: "正在编辑 {name} — 保存后会自动上传",
nothingToCopy: "没有可复制的内容(符号链接将被跳过)",
nothingToCopyAllSkipped: "没有可复制的内容 — 所有冲突项都被跳过",
@@ -292,6 +292,26 @@ export const zh = {
tabDisconnect: "断开连接",
trashTooltip: "从此处移入废纸篓的项目无法使用访达的放回原处功能",
},
keys: {
names: {
ctrl: "Ctrl",
alt: "Alt",
shift: "Shift",
enter: "Enter",
backspace: "退格",
del: "Del",
esc: "Esc",
space: "空格",
tab: "Tab",
pgup: "PgUp",
pgdn: "PgDn",
home: "Home",
end: "End",
ins: "Ins",
menu: "菜单",
num: "Num",
},
},
errors: {
sshAgentUnavailable: "ssh-agent 不可用(未设置 SSH_AUTH_SOCK)",
identityFileNotFound: "找不到身份文件:{path}",
+215
View File
@@ -0,0 +1,215 @@
import { expect, test } from "bun:test";
import { en } from "./i18n/en";
import {
BINDINGS,
type Combo,
comboFromEvent,
conflicts,
EN_KEY_NAMES,
effectiveKeymap,
firesInTextField,
formatCombo,
GROUPS,
isReserved,
type KeyEventLike,
matchesEvent,
NATIVE_MENU_IDS,
parseCombo,
serializeCombo,
scopesOverlap,
toAccelerator,
} from "./keymap";
const US_CHARS: Record<string, string> = {
Comma: ",",
Period: ".",
Slash: "/",
Semicolon: ";",
Quote: "'",
BracketLeft: "[",
BracketRight: "]",
Backslash: "\\",
Backquote: "`",
Equal: "=",
Minus: "-",
NumpadAdd: "+",
};
/** The keydown a US keyboard produces for `c`. */
function eventFor(c: Combo, isMac: boolean): KeyEventLike {
let key = c.key;
let code = c.key;
if (/^[A-Z]$/.test(c.key)) {
key = c.shift ? c.key : c.key.toLowerCase();
code = `Key${c.key}`;
} else if (/^[0-9]$/.test(c.key)) {
code = `Digit${c.key}`;
} else if (c.key in US_CHARS) {
key = US_CHARS[c.key];
} else if (c.key === "Space") {
key = " ";
}
return {
key,
code,
metaKey: isMac && c.mod,
ctrlKey: isMac ? c.ctrl : c.mod,
altKey: c.alt,
shiftKey: c.shift,
};
}
const ev = (over: Partial<KeyEventLike>): KeyEventLike => ({
key: "",
code: "",
metaKey: false,
ctrlKey: false,
altKey: false,
shiftKey: false,
...over,
});
const combo = (text: string, isMac: boolean) => {
const c = parseCombo(text, isMac);
if (!c) throw new Error(`unparsable ${text}`);
return c;
};
for (const isMac of [true, false]) {
const os = isMac ? "macOS" : "Windows/Linux";
const keymap = effectiveKeymap({}, isMac);
test(`${os}: the defaults have no conflicts`, () => {
expect([...conflicts(keymap).entries()]).toEqual([]);
});
test(`${os}: every default round-trips and resolves to its own command`, () => {
for (const binding of keymap) {
for (const c of binding.combos) {
expect(parseCombo(serializeCombo(c), isMac)).toEqual(c);
const event = eventFor(c, isMac);
// table order is resolution order: nothing earlier may shadow it
const hit = keymap.find(
(other) => scopesOverlap(other.scopes, binding.scopes) && other.combos.some((oc) => matchesEvent(oc, event, isMac)),
);
expect(`${serializeCombo(c)} → ${hit?.id}`).toBe(`${serializeCombo(c)} → ${binding.id}`);
expect(comboFromEvent(event, isMac)).toEqual(c);
}
}
});
test(`${os}: no default is a reserved combo`, () => {
for (const binding of keymap) for (const c of binding.combos) expect(isReserved(c, isMac)).toBe(false);
});
test(`${os}: every macOS menu command has an expressible accelerator`, () => {
if (!isMac) return;
for (const id of NATIVE_MENU_IDS) {
const binding = keymap.find((b) => b.id === id)!;
expect(binding.combos.some((c) => toAccelerator(c) !== null)).toBe(true);
}
});
}
test("every command and group has an English label", () => {
const keys = en.keys as Record<string, unknown>;
for (const b of BINDINGS) expect(typeof keys["n" in b ? "go-to-tab" : b.id]).toBe("string");
for (const g of GROUPS) expect(typeof en.keys.groups[g]).toBe("string");
});
test("matching is exact about modifiers", () => {
// ⌃F is Cocoa's forward-one-character, not ⌘F
expect(matchesEvent(combo("Mod+F", true), ev({ key: "f", code: "KeyF", ctrlKey: true }), true)).toBe(false);
expect(matchesEvent(combo("Mod+F", true), ev({ key: "f", code: "KeyF", metaKey: true }), true)).toBe(true);
// Ctrl+Tab is not Tab (the old panel switch caught both)
expect(matchesEvent(combo("Tab", false), ev({ key: "Tab", code: "Tab", ctrlKey: true }), false)).toBe(false);
// the Windows key is never part of a binding
expect(matchesEvent(combo("Mod+T", false), ev({ key: "t", code: "KeyT", ctrlKey: true, metaKey: true }), false)).toBe(false);
});
test("letters follow the layout, Alt chords and other scripts use the physical key", () => {
// AZERTY: the comma sits on the M key, the A on the Q key
expect(comboFromEvent(ev({ key: ",", code: "KeyM", metaKey: true }), true)).toEqual(combo("Mod+Comma", true));
expect(comboFromEvent(ev({ key: "a", code: "KeyQ", ctrlKey: true }), false)).toEqual(combo("Mod+A", false));
// macOS Option turns ⌥Z into Ω
expect(comboFromEvent(ev({ key: "Ω", code: "KeyZ", altKey: true }), true)).toEqual(combo("Alt+Z", true));
// Cyrillic ⌘T arrives as "е" on the T key
expect(matchesEvent(combo("Mod+T", true), ev({ key: "е", code: "KeyT", metaKey: true }), true)).toBe(true);
// US ⌘+ is ⇧⌘= — matched by the physical key
expect(matchesEvent(combo("Mod+Shift+Equal", true), ev({ key: "+", code: "Equal", metaKey: true, shiftKey: true }), true)).toBe(true);
// AZERTY ⌘1 types "&" on the 1 key
expect(comboFromEvent(ev({ key: "&", code: "Digit1", metaKey: true }), true)).toEqual(combo("Mod+1", true));
// a bare modifier press is not a combo
expect(comboFromEvent(ev({ key: "Shift", code: "ShiftLeft", shiftKey: true }), true)).toBeNull();
});
test("formatting per platform, with localized key names off macOS", () => {
expect(formatCombo(combo("Mod+Shift+N", true), true)).toBe("⇧⌘N");
expect(formatCombo(combo("Ctrl+Tab", true), true)).toBe("⌃⇥");
expect(formatCombo(combo("Mod+Alt+C", true), true)).toBe("⌥⌘C");
expect(formatCombo(combo("Mod+Comma", true), true)).toBe("⌘,");
expect(formatCombo(combo("Shift+F10", true), true)).toBe("⇧F10");
expect(formatCombo(combo("Mod+Backspace", true), true)).toBe("⌘⌫");
expect(formatCombo(combo("Mod+Shift+N", false), false)).toBe("Ctrl+Shift+N");
expect(formatCombo(combo("Alt+Shift+R", false), false)).toBe("Alt+Shift+R");
expect(formatCombo(combo("Delete", false), false)).toBe("Del");
const de = { ...EN_KEY_NAMES, ctrl: "Strg", del: "Entf" };
expect(formatCombo(combo("Mod+Delete", false), false, de)).toBe("Strg+Entf");
});
test("overrides replace a row; garbage is dropped", () => {
const keymap = effectiveKeymap(
{ rename: ["Mod+Shift+R", "nonsense", 5, "Mod+Shift+R"], save: "F9", bogus: ["F1"], delete: [] },
true,
);
const by = (id: string) => keymap.find((b) => b.id === id)!;
expect(by("rename").combos.map(serializeCombo)).toEqual(["Mod+Shift+R"]);
expect(by("rename").custom).toBe(true);
// not an array: ignored, the defaults stand
expect(by("save").custom).toBe(false);
expect(by("save").combos.map(serializeCombo)).toEqual(["Mod+S"]);
// [] unbinds
expect(by("delete").combos).toEqual([]);
expect(keymap.some((b) => (b.id as string) === "bogus")).toBe(false);
// not an object at all
expect(effectiveKeymap("junk", true).every((b) => !b.custom)).toBe(true);
});
test("off macOS a stored literal Ctrl folds into Mod", () => {
expect(parseCombo("Ctrl+Tab", false)).toEqual(parseCombo("Mod+Tab", false));
expect(parseCombo("Ctrl+Tab", true)).not.toEqual(parseCombo("Mod+Tab", true));
});
test("native menu accelerators", () => {
expect(toAccelerator(combo("Mod+Shift+N", true))).toBe("Command+Shift+n");
expect(toAccelerator(combo("Mod+Comma", true))).toBe("Command+,");
expect(toAccelerator(combo("Mod+Minus", true))).toBe("Command+minus");
expect(toAccelerator(combo("Ctrl+Shift+PageUp", true))).toBe("Control+Shift+pageup");
// a bare key would mean ⌘+key to the native parser
expect(toAccelerator(combo("F5", true))).toBeNull();
// ⌫ / ⌦, Shift+punctuation and modifier-less combos have no faithful form
expect(toAccelerator(combo("Mod+Delete", true))).toBeNull();
expect(toAccelerator(combo("Mod+Backspace", true))).toBeNull();
expect(toAccelerator(combo("Mod+Shift+BracketRight", true))).toBeNull();
expect(toAccelerator(combo("Shift+F4", true))).toBeNull();
});
test("text fields keep their own keys", () => {
// plain keys and text-editing chords type / edit
expect(firesInTextField(combo("Delete", true), true)).toBe(false);
expect(firesInTextField(combo("Mod+Backspace", true), true)).toBe(false);
expect(firesInTextField(combo("Mod+A", true), true)).toBe(false);
expect(firesInTextField(combo("Alt+ArrowLeft", true), true)).toBe(false);
// app chords and F-keys still fire (⌘S in the editor, ⌘↩ in the manager form)
expect(firesInTextField(combo("Mod+S", true), true)).toBe(true);
expect(firesInTextField(combo("Mod+Enter", false), false)).toBe(true);
expect(firesInTextField(combo("F3", false), false)).toBe(true);
// Ctrl+Alt off macOS is AltGr typing a character
expect(firesInTextField(combo("Mod+Alt+Q", false), false)).toBe(false);
});
test("AltGr is never a shortcut off macOS", () => {
const altGrQ = ev({ key: "@", code: "KeyQ", ctrlKey: true, altKey: true, getModifierState: (k) => k === "AltGraph" });
expect(matchesEvent(combo("Mod+Alt+Q", false), altGrQ, false)).toBe(false);
expect(comboFromEvent(altGrQ, false)).toBeNull();
});
+547
View File
@@ -0,0 +1,547 @@
// The app's one keymap: every keyboard command, where it fires and its default
// keys per platform, plus the pure helpers that parse, match, format and check
// key combos. Shared on purpose: the webviews resolve keys, show hints and edit
// remaps against this table, and bun builds the macOS menu-bar accelerators
// from it, so the two can never disagree. User remaps are stored as overrides
// in AppSettings.keybindings and applied by effectiveKeymap().
/** Where a binding fires. `panel` = the focused file list, `main` = anywhere
* in the main window, `any` = every window. `panel` sits inside `main`, so
* the two overlap for conflict purposes. */
export type Scope = "panel" | "main" | "editor" | "manager" | "settings" | "any";
/** Settings → Keyboard sections, in display order. */
export const GROUPS = ["panels", "files", "sort", "tabs", "window", "editor", "connections"] as const;
export type Group = (typeof GROUPS)[number];
interface BindingDef {
readonly id: string;
readonly group: Group;
readonly scopes: readonly Scope[];
/** Default combos, best first: the first is the one menus and tooltips show. */
readonly mac: readonly string[];
readonly other: readonly string[];
/** go-to-tab-N: the N its label interpolates. */
readonly n?: number;
}
const both = (...combos: string[]) => ({ mac: combos, other: combos });
/**
* Every command, in Settings display order within its group. Combo strings are
* platform-neutral (see parseCombo): `Mod` is ⌘ on macOS and Ctrl elsewhere,
* `Ctrl` a literal ⌃ that only macOS tells apart.
*/
export const BINDINGS = [
// ---- panels: the focused file list ----
{ id: "cursor-up", group: "panels", scopes: ["panel"], ...both("ArrowUp") },
{ id: "cursor-down", group: "panels", scopes: ["panel"], ...both("ArrowDown") },
{ id: "page-up", group: "panels", scopes: ["panel"], ...both("PageUp") },
{ id: "page-down", group: "panels", scopes: ["panel"], ...both("PageDown") },
{ id: "cursor-first", group: "panels", scopes: ["panel"], ...both("Home") },
{ id: "cursor-last", group: "panels", scopes: ["panel"], ...both("End") },
{ id: "toggle-select", group: "panels", scopes: ["panel"], mac: ["Space"], other: ["Space", "Insert"] },
{ id: "select-all", group: "panels", scopes: ["panel"], ...both("Mod+A") },
{ id: "open", group: "panels", scopes: ["panel"], mac: ["Enter", "Mod+ArrowDown"], other: ["Enter"] },
{ id: "parent", group: "panels", scopes: ["panel"], mac: ["Backspace", "Mod+ArrowUp"], other: ["Backspace", "Alt+ArrowUp"] },
{ id: "switch-panel", group: "panels", scopes: ["panel"], ...both("Tab", "Shift+Tab") },
{ id: "row-menu", group: "panels", scopes: ["panel"], mac: ["Shift+F10", "Ctrl+Enter"], other: ["Shift+F10", "ContextMenu"] },
// ---- files: act on the focused panel's selection, else its cursor row ----
{ id: "send", group: "files", scopes: ["panel"], ...both("F5") },
{ id: "edit", group: "files", scopes: ["panel"], mac: ["Mod+E", "F4"], other: ["F4", "Mod+E"] },
{ id: "rename", group: "files", scopes: ["panel"], ...both("F2") },
{ id: "new-folder", group: "files", scopes: ["panel"], mac: ["Mod+Shift+N", "F7"], other: ["F7", "Mod+Shift+N"] },
{ id: "new-file", group: "files", scopes: ["panel"], mac: ["Mod+N", "Shift+F4"], other: ["Shift+F4", "Mod+N"] },
{ id: "chmod", group: "files", scopes: ["panel"], ...both("Mod+I") },
{ id: "delete", group: "files", scopes: ["panel"], ...both("F8", "Delete") },
{ id: "trash", group: "files", scopes: ["panel"], mac: ["Mod+Backspace"], other: ["Mod+Delete"] },
{ id: "copy-path", group: "files", scopes: ["panel"], mac: ["Mod+Alt+C"], other: ["Mod+Shift+C"] },
{ id: "reveal", group: "files", scopes: ["panel"], mac: ["Mod+Alt+R"], other: ["Alt+Shift+R"] },
{ id: "open-default", group: "files", scopes: ["panel"], ...both("Mod+O") },
{ id: "refresh", group: "files", scopes: ["panel"], ...both("Mod+R") },
{ id: "focus-path", group: "files", scopes: ["panel"], ...both("Mod+L") },
{ id: "source-picker", group: "files", scopes: ["panel"], ...both("Mod+K") },
// ---- sort the focused panel (again = reverse) ----
{ id: "sort-name", group: "sort", scopes: ["panel"], ...both("Alt+1") },
{ id: "sort-size", group: "sort", scopes: ["panel"], ...both("Alt+2") },
{ id: "sort-mtime", group: "sort", scopes: ["panel"], ...both("Alt+3") },
{ id: "sort-kind", group: "sort", scopes: ["panel"], ...both("Alt+4") },
{ id: "sort-rights", group: "sort", scopes: ["panel"], ...both("Alt+5") },
{ id: "sort-owner", group: "sort", scopes: ["panel"], ...both("Alt+6") },
{ id: "sort-group", group: "sort", scopes: ["panel"], ...both("Alt+7") },
// ---- tabs (Ctrl+Tab is a literal ⌃ on macOS: ⌘Tab is the app switcher) ----
{ id: "new-tab", group: "tabs", scopes: ["main"], ...both("Mod+T") },
{ id: "close-tab", group: "tabs", scopes: ["main"], ...both("Mod+W") },
// Ctrl+Alt+letter is AltGr typing on many non-mac layouts — never a default there
{ id: "close-other-tabs", group: "tabs", scopes: ["main"], mac: ["Mod+Alt+W"], other: ["Mod+Shift+W"] },
{ id: "close-tabs-right", group: "tabs", scopes: ["main"], ...both() },
{ id: "next-tab", group: "tabs", scopes: ["main"], mac: ["Ctrl+Tab", "Mod+Shift+BracketRight"], other: ["Ctrl+Tab", "Mod+PageDown"] },
{ id: "prev-tab", group: "tabs", scopes: ["main"], mac: ["Ctrl+Shift+Tab", "Mod+Shift+BracketLeft"], other: ["Ctrl+Shift+Tab", "Mod+PageUp"] },
{ id: "go-to-tab-1", group: "tabs", scopes: ["main"], n: 1, ...both("Mod+1") },
{ id: "go-to-tab-2", group: "tabs", scopes: ["main"], n: 2, ...both("Mod+2") },
{ id: "go-to-tab-3", group: "tabs", scopes: ["main"], n: 3, ...both("Mod+3") },
{ id: "go-to-tab-4", group: "tabs", scopes: ["main"], n: 4, ...both("Mod+4") },
{ id: "go-to-tab-5", group: "tabs", scopes: ["main"], n: 5, ...both("Mod+5") },
{ id: "go-to-tab-6", group: "tabs", scopes: ["main"], n: 6, ...both("Mod+6") },
{ id: "go-to-tab-7", group: "tabs", scopes: ["main"], n: 7, ...both("Mod+7") },
{ id: "go-to-tab-8", group: "tabs", scopes: ["main"], n: 8, ...both("Mod+8") },
{ id: "go-to-last-tab", group: "tabs", scopes: ["main"], ...both("Mod+9") },
{ id: "move-tab-left", group: "tabs", scopes: ["main"], mac: ["Ctrl+Shift+PageUp"], other: ["Mod+Shift+PageUp"] },
{ id: "move-tab-right", group: "tabs", scopes: ["main"], mac: ["Ctrl+Shift+PageDown"], other: ["Mod+Shift+PageDown"] },
{ id: "disconnect-tab", group: "tabs", scopes: ["main"], ...both("Mod+D") },
// ---- window ----
{ id: "open-settings", group: "window", scopes: ["main"], ...both("Mod+Comma") },
{ id: "connection-manager", group: "window", scopes: ["main"], ...both("Mod+Shift+K") },
{ id: "toggle-transfers", group: "window", scopes: ["main"], ...both("Mod+J") },
{ id: "install-update", group: "window", scopes: ["main"], ...both() },
// ⌘+ is ⇧⌘= on US layouts — both spellings, plus the keypad
{ id: "scale-up", group: "window", scopes: ["any"], ...both("Mod+Equal", "Mod+Shift+Equal", "Mod+NumpadAdd") },
{ id: "scale-down", group: "window", scopes: ["any"], ...both("Mod+Minus") },
{ id: "scale-reset", group: "window", scopes: ["any"], ...both("Mod+0") },
{ id: "close-window", group: "window", scopes: ["editor", "manager", "settings"], ...both("Mod+W") },
// ---- editor window ----
{ id: "save", group: "editor", scopes: ["editor"], ...both("Mod+S") },
{ id: "find", group: "editor", scopes: ["editor"], ...both("Mod+F") },
{ id: "find-next", group: "editor", scopes: ["editor"], mac: ["Mod+G"], other: ["F3"] },
{ id: "find-prev", group: "editor", scopes: ["editor"], mac: ["Mod+Shift+G"], other: ["Shift+F3"] },
{ id: "toggle-wrap", group: "editor", scopes: ["editor"], ...both("Alt+Z") },
// ---- connection manager ----
{ id: "conn-new", group: "connections", scopes: ["manager"], ...both("Mod+N") },
{ id: "conn-new-stack", group: "connections", scopes: ["manager"], ...both("Mod+Shift+N") },
{ id: "conn-save", group: "connections", scopes: ["manager"], ...both("Mod+S") },
{ id: "conn-connect", group: "connections", scopes: ["manager"], ...both("Mod+Enter") },
{ id: "conn-delete", group: "connections", scopes: ["manager"], mac: ["Mod+Backspace"], other: ["Delete"] },
{ id: "conn-rename-stack", group: "connections", scopes: ["manager"], ...both("F2") },
{ id: "conn-import", group: "connections", scopes: ["manager"], ...both("Mod+O") },
] as const satisfies readonly BindingDef[];
export type ShortcutId = (typeof BINDINGS)[number]["id"];
/** Commands the macOS menu bar carries; their accelerators follow the keymap. */
export const NATIVE_MENU_IDS: readonly ShortcutId[] = [
"open-settings",
"new-tab",
"close-tab",
"new-folder",
"new-file",
"edit",
"connection-manager",
"refresh",
];
export interface Combo {
/** A–Z, 0–9, a punctuation event.code (Comma, Equal…) or a key name (Enter, F2…). */
key: string;
/** ⌘ on macOS, Ctrl elsewhere. */
mod: boolean;
/** A literal ⌃, macOS only — elsewhere Ctrl IS Mod. */
ctrl: boolean;
alt: boolean;
shift: boolean;
}
/** The KeyboardEvent fields matching needs (tests build these by hand). */
export interface KeyEventLike {
key: string;
code: string;
metaKey: boolean;
ctrlKey: boolean;
altKey: boolean;
shiftKey: boolean;
getModifierState?(key: string): boolean;
}
export interface ResolvedBinding {
id: ShortcutId;
group: Group;
scopes: readonly Scope[];
n?: number;
/** What fires: the user's override when there is one, else the defaults. */
combos: Combo[];
defaults: Combo[];
/** The user replaced this row's defaults (possibly with nothing). */
custom: boolean;
}
const LETTER = /^[A-Z]$/;
const DIGIT = /^[0-9]$/;
const FKEY = /^F([1-9]|1[0-2])$/;
/** Punctuation tokens and the character each stands for. Matched by character
* first (AZERTY's comma is on the M key) and by physical key second (⇧] makes
* "}", the US ⌘+ is ⇧⌘=). */
const CHAR_OF: Record<string, string> = {
Comma: ",",
Period: ".",
Slash: "/",
Semicolon: ";",
Quote: "'",
BracketLeft: "[",
BracketRight: "]",
Backslash: "\\",
Backquote: "`",
Equal: "=",
Minus: "-",
};
const TOKEN_OF_CHAR: Record<string, string> = Object.fromEntries(
Object.entries(CHAR_OF).map(([token, char]) => [char, token]),
);
/** Physical-only keys: the keypad's + (its − already types "-", which is Minus). */
const KEYPAD = new Set(["NumpadAdd"]);
/** KeyboardEvent.key names, the same on every layout. */
const NAMED = new Set([
"Enter",
"Escape",
"Backspace",
"Delete",
"Tab",
"Space",
"ArrowUp",
"ArrowDown",
"ArrowLeft",
"ArrowRight",
"Home",
"End",
"PageUp",
"PageDown",
"Insert",
"ContextMenu",
]);
function isToken(key: string): boolean {
return (
LETTER.test(key) || DIGIT.test(key) || FKEY.test(key) || Object.hasOwn(CHAR_OF, key) || KEYPAD.has(key) || NAMED.has(key)
);
}
/**
* An event's key token, or null for modifier-only presses and keys the keymap
* doesn't cover. Letters follow the layout (AZERTY's A is A); under Alt
* (macOS Option turns ⌥Z into Ω) and on non-Latin layouts they fall back to the
* physical key. Digits are physical too: AZERTY types "&" on the 1 key.
*/
export function keyToken(e: Pick<KeyEventLike, "key" | "code" | "altKey">): string | null {
const { key, code } = e;
const upper = key.length === 1 ? key.toUpperCase() : "";
if (!e.altKey && LETTER.test(upper)) return upper;
if (/^Key[A-Z]$/.test(code) && (e.altKey || /\p{L}/u.test(key))) return code.slice(3);
if (/^Digit[0-9]$/.test(code)) return code.slice(5);
if (/^Numpad[0-9]$/.test(code)) return DIGIT.test(key) ? key : NAMED.has(key) ? key : null;
if (Object.hasOwn(TOKEN_OF_CHAR, key)) return TOKEN_OF_CHAR[key];
if (Object.hasOwn(CHAR_OF, code) || KEYPAD.has(code)) return code;
if (key === " " || code === "Space") return "Space";
if (FKEY.test(key) || NAMED.has(key)) return key;
return null;
}
function eventMods(e: KeyEventLike, isMac: boolean) {
return isMac
? { mod: e.metaKey, ctrl: e.ctrlKey, alt: e.altKey, shift: e.shiftKey, other: false }
: // never part of a binding: the Windows / Super key, and AltGr — which
// arrives as Ctrl+Alt while it types "@", "€", "{"…
{
mod: e.ctrlKey,
ctrl: false,
alt: e.altKey,
shift: e.shiftKey,
other: e.metaKey || !!e.getModifierState?.("AltGraph"),
};
}
/** Exact match: the same key AND exactly the same modifiers. ⌃ is not ⌘ on
* macOS (⌃F is Cocoa's forward-one-character), and Ctrl+Tab is not Tab. */
export function matchesEvent(combo: Combo, e: KeyEventLike, isMac: boolean): boolean {
const m = eventMods(e, isMac);
if (m.other || m.mod !== combo.mod || m.ctrl !== combo.ctrl || m.alt !== combo.alt || m.shift !== combo.shift) {
return false;
}
return keyToken(e) === combo.key || ((Object.hasOwn(CHAR_OF, combo.key) || KEYPAD.has(combo.key)) && e.code === combo.key);
}
/** The combo a keydown spells (Settings → Keyboard recording), or null. */
export function comboFromEvent(e: KeyEventLike, isMac: boolean): Combo | null {
const key = keyToken(e);
const m = eventMods(e, isMac);
if (!key || m.other) return null;
return { key, mod: m.mod, ctrl: m.ctrl, alt: m.alt, shift: m.shift };
}
/** "Mod+Shift+N" → Combo; null for anything malformed. Off macOS a stored
* literal Ctrl folds into Mod — on those keyboards they are the same key. */
export function parseCombo(text: unknown, isMac: boolean): Combo | null {
if (typeof text !== "string" || !text) return null;
const parts = text.split("+");
let key = parts.pop() ?? "";
if (key.length === 1) key = key.toUpperCase();
if (!isToken(key)) return null;
const combo: Combo = { key, mod: false, ctrl: false, alt: false, shift: false };
for (const part of parts) {
const name = part.toLowerCase();
if (name === "mod") combo.mod = true;
else if (name === "ctrl") combo.ctrl = true;
else if (name === "alt") combo.alt = true;
else if (name === "shift") combo.shift = true;
else return null;
}
if (!isMac && combo.ctrl) {
combo.ctrl = false;
combo.mod = true;
}
return combo;
}
export function serializeCombo(c: Combo): string {
return [c.mod && "Mod", c.ctrl && "Ctrl", c.alt && "Alt", c.shift && "Shift", c.key].filter(Boolean).join("+");
}
export function sameCombo(a: Combo, b: Combo): boolean {
return serializeCombo(a) === serializeCombo(b);
}
function parseList(list: readonly unknown[], isMac: boolean): Combo[] {
const out: Combo[] = [];
for (const text of list) {
const combo = parseCombo(text, isMac);
if (combo && !out.some((c) => sameCombo(c, combo))) out.push(combo);
}
return out;
}
/**
* The table with the user's overrides applied — the single place a hand-edited
* settings.json is sanitized: unknown ids, non-arrays and malformed combos are
* dropped. An override replaces a row's whole list; [] unbinds it.
*/
export function effectiveKeymap(overrides: unknown, isMac: boolean): ResolvedBinding[] {
const table: Record<string, unknown> =
overrides && typeof overrides === "object" && !Array.isArray(overrides)
? (overrides as Record<string, unknown>)
: {};
return BINDINGS.map((b): ResolvedBinding => {
const defaults = parseList(isMac ? b.mac : b.other, isMac);
const raw = Object.hasOwn(table, b.id) ? table[b.id] : undefined;
const custom = Array.isArray(raw);
return {
id: b.id,
group: b.group,
scopes: b.scopes,
n: "n" in b ? b.n : undefined,
defaults,
custom,
combos: custom ? parseList(raw, isMac) : defaults,
};
});
}
/** The stored shape, coerced to arrays of combo strings, for
* SettingsStore.load: a hand-edited settings.json can't break boot. Unknown
* ids are kept (a newer build's commands survive a downgrade round trip);
* effectiveKeymap ignores them. */
export function sanitizeKeybindings(raw: unknown): Record<string, string[]> {
const out: Record<string, string[]> = {};
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return out;
for (const [id, list] of Object.entries(raw)) {
if (Array.isArray(list)) out[id] = list.filter((t): t is string => parseCombo(t, true) !== null);
}
return out;
}
/** True when a binding in `a` and one in `b` can fire on the same keystroke. */
export function scopesOverlap(a: readonly Scope[], b: readonly Scope[]): boolean {
return a.some((x) =>
b.some(
(y) =>
x === y ||
x === "any" ||
y === "any" ||
(x === "panel" && y === "main") ||
(x === "main" && y === "panel"),
),
);
}
/** The binding that already owns `combo` where `scopes` fire, if any. */
export function ownerOf(
keymap: readonly ResolvedBinding[],
combo: Combo,
scopes: readonly Scope[],
except?: ShortcutId,
): ResolvedBinding | undefined {
return keymap.find(
(b) => b.id !== except && scopesOverlap(b.scopes, scopes) && b.combos.some((c) => sameCombo(c, combo)),
);
}
/** Every binding that shares a combo with another one it can collide with. */
export function conflicts(keymap: readonly ResolvedBinding[]): Map<ShortcutId, ShortcutId[]> {
const out = new Map<ShortcutId, ShortcutId[]>();
const link = (from: ShortcutId, to: ShortcutId) => out.set(from, [...(out.get(from) ?? []), to]);
for (let i = 0; i < keymap.length; i++) {
for (let j = i + 1; j < keymap.length; j++) {
const a = keymap[i];
const b = keymap[j];
if (!scopesOverlap(a.scopes, b.scopes)) continue;
if (a.combos.some((ca) => b.combos.some((cb) => sameCombo(ca, cb)))) {
link(a.id, b.id);
link(b.id, a.id);
}
}
}
return out;
}
/** Keys whose modified forms edit text: ⌘⌫ deletes to line start, ⌥← jumps a word… */
const TEXT_EDITING = new Set(["Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"]);
/** Whether a combo may fire while focus is in a text field. Plain and
* Shift-only keys type there, and so do the text-editing chords (⌘⌫, ⌥←, ⌘A);
* other ⌘/Ctrl and Alt chords and F-keys fire — except Ctrl+Alt off macOS,
* which is AltGr. */
export function firesInTextField(c: Combo, isMac: boolean): boolean {
if (FKEY.test(c.key)) return true;
if (TEXT_EDITING.has(c.key) || (c.mod && c.key === "A")) return false;
if (!isMac && c.mod && c.alt) return false;
return c.mod || c.alt;
}
/** Commands a held key may repeat; any other held shortcut fires once
* (holding ⌘W must not close every tab). */
const REPEATABLE = new Set<ShortcutId>([
"cursor-up",
"cursor-down",
"page-up",
"page-down",
"toggle-select",
"next-tab",
"prev-tab",
"move-tab-left",
"move-tab-right",
"scale-up",
"scale-down",
"find-next",
"find-prev",
]);
export function isRepeatable(id: ShortcutId): boolean {
return REPEATABLE.has(id);
}
const RESERVED = {
mac: ["Mod+Q", "Mod+X", "Mod+C", "Mod+V", "Mod+Z", "Mod+Shift+Z", "Mod+H", "Mod+Alt+H", "Mod+M", "Mod+Backquote"],
other: ["Mod+X", "Mod+C", "Mod+V", "Mod+Z", "Mod+Y"],
};
/** Quit, the clipboard / undo keys and macOS's window keys (⌘H ⌘M ⌘`) can't be rebound. */
export function isReserved(c: Combo, isMac: boolean): boolean {
return parseList(isMac ? RESERVED.mac : RESERVED.other, isMac).some((r) => sameCombo(r, c));
}
/** Key names for the non-macOS spelling ("Ctrl+Shift+Del"); i18n supplies
* localized ones (German keyboards say Strg and Entf). */
export interface KeyNames {
ctrl: string;
alt: string;
shift: string;
enter: string;
backspace: string;
del: string;
esc: string;
space: string;
tab: string;
pgup: string;
pgdn: string;
home: string;
end: string;
ins: string;
menu: string;
num: string;
}
export const EN_KEY_NAMES: KeyNames = {
ctrl: "Ctrl",
alt: "Alt",
shift: "Shift",
enter: "Enter",
backspace: "Backspace",
del: "Del",
esc: "Esc",
space: "Space",
tab: "Tab",
pgup: "PgUp",
pgdn: "PgDn",
home: "Home",
end: "End",
ins: "Ins",
menu: "Menu",
num: "Num",
};
const ARROWS: Record<string, string> = { ArrowUp: "↑", ArrowDown: "↓", ArrowLeft: "←", ArrowRight: "→" };
const MAC_GLYPHS: Record<string, string> = { Enter: "↩", Escape: "⎋", Backspace: "⌫", Delete: "⌦", Tab: "⇥" };
function keyLabel(key: string, isMac: boolean, names: KeyNames): string {
if (Object.hasOwn(CHAR_OF, key)) return CHAR_OF[key];
if (Object.hasOwn(ARROWS, key)) return ARROWS[key];
if (isMac && Object.hasOwn(MAC_GLYPHS, key)) return MAC_GLYPHS[key];
const named: Record<string, string> = {
Enter: names.enter,
Escape: names.esc,
Backspace: names.backspace,
Delete: names.del,
Tab: names.tab,
Space: names.space,
Home: names.home,
End: names.end,
PageUp: names.pgup,
PageDown: names.pgdn,
Insert: names.ins,
ContextMenu: names.menu,
NumpadAdd: `${names.num} +`,
};
return Object.hasOwn(named, key) ? named[key] : key;
}
/** "⇧⌘N" on macOS (Apple's ⌃⌥⇧⌘ order), "Ctrl+Shift+N" elsewhere. */
export function formatCombo(c: Combo, isMac: boolean, names: KeyNames = EN_KEY_NAMES): string {
const key = keyLabel(c.key, isMac, names);
if (isMac) return `${c.ctrl ? "⌃" : ""}${c.alt ? "⌥" : ""}${c.shift ? "⇧" : ""}${c.mod ? "⌘" : ""}${key}`;
return [c.mod && names.ctrl, c.alt && names.alt, c.shift && names.shift, key].filter(Boolean).join("+");
}
const ACCELERATOR_KEYS: Record<string, string> = {
Enter: "return",
Escape: "escape",
Tab: "tab",
Space: "space",
ArrowUp: "up",
ArrowDown: "down",
ArrowLeft: "left",
ArrowRight: "right",
Home: "home",
End: "end",
PageUp: "pageup",
PageDown: "pagedown",
};
/**
* Electrobun's native menu accelerator ("Command+Shift+n"), or null when the
* menu can't express the combo faithfully:
* - only ⌘ / ⌃ chords — the native parser turns any combo without a modifier
* token into ⌘+key;
* - no ⌫ / ⌦ (its "backspace" and "delete" tokens map to characters AppKit
* matches unreliably), Insert, the Menu key or the keypad;
* - no Shift+punctuation — AppKit matches the shifted character ("}"), not "]".
*/
export function toAccelerator(c: Combo): string | null {
if (!c.mod && !c.ctrl) return null;
if (c.shift && Object.hasOwn(CHAR_OF, c.key)) return null;
let key: string | undefined;
if (LETTER.test(c.key)) key = c.key.toLowerCase();
else if (DIGIT.test(c.key)) key = c.key;
else if (FKEY.test(c.key)) key = c.key.toLowerCase();
else if (Object.hasOwn(CHAR_OF, c.key)) key = c.key === "Minus" ? "minus" : CHAR_OF[c.key];
else if (Object.hasOwn(ACCELERATOR_KEYS, c.key)) key = ACCELERATOR_KEYS[c.key];
if (!key) return null;
return [c.mod && "Command", c.ctrl && "Control", c.alt && "Alt", c.shift && "Shift", key]
.filter(Boolean)
.join("+");
}
+2
View File
@@ -157,6 +157,8 @@ export type AppRPC = {
// settings window
/** Main window: open (or focus) the single Settings window. */
openSettings: { params: Record<string, never>; response: Result };
/** Settings window only: its close-window key (Ctrl+W off macOS, ⌘W). */
settingsClose: { params: Record<string, never>; response: Result };
// auto-updater (electrobun Updater)
/** Main window: re-run the update check on demand (menu item). */
checkForUpdate: {
+10
View File
@@ -91,6 +91,14 @@ export interface AppSettings {
editor: "builtin" | "custom";
/** Full path to the external editor .app; empty = OS default application. */
editorApp: string;
/**
* Keyboard remaps from Settings → Keyboard: command id → combo strings, only
* for rows that differ from the defaults ([] unbinds). Format and sanitizing
* live in keymap.ts — a hand-edited entry it can't parse is simply ignored.
*/
keybindings: Record<string, string[]>;
/** Enter / double-click on a LOCAL file opens it in its default app. */
openFilesOnEnter: boolean;
// Auto-refresh the active tab's panels (local watched, remote polled). Always
// on for now; uncomment (+ the settings.service and tab-bar breadcrumbs, and
// gate the poll/watch in panels.service) to expose a toggle later.
@@ -109,6 +117,8 @@ export const DEFAULT_SETTINGS: AppSettings = {
autoClearCompleted: true,
editor: "builtin",
editorApp: "",
keybindings: {},
openFilesOnEnter: false,
// autoRefresh: true,
};
+83 -38
View File
@@ -1,30 +1,50 @@
import { Injectable, inject, signal } from '@angular/core';
import type { ColumnKey, EntryType } from '@shared/types';
import type { FileCommand } from './file-actions.service';
import { I18nService } from './i18n.service';
import { IS_MAC, IS_WINDOWS, MOD_LABEL } from './platform';
import { stepIndex } from './menu-nav';
import type { Side } from './panels.service';
import { IS_MAC, IS_WINDOWS } from './platform';
import { RpcService } from './rpc.service';
import type { ShortcutId } from './shortcuts.service';
/** Optional list columns, in display order (Name is fixed). */
export const COLUMN_KEYS: ColumnKey[] = ['size', 'mtime', 'kind', 'rights', 'owner', 'group'];
export interface MenuItem {
type?: 'separator';
/** separator: a rule; header: a non-pickable section title (the source picker). */
type?: 'separator' | 'header';
label?: string;
/** Emitted verbatim to the action dispatcher (`ctx-*` / `col:*` / `tab:*`). */
/** Handed to the request's onPick, else emitted to the action dispatcher
* (`col:*` / `tab:*`). */
action?: string;
checked?: boolean;
tooltip?: string;
/** Shortcut hint, rendered right-aligned. */
accelerator?: string;
/** The keymap command the item runs: its first key shows as the soft hint,
* and pressing that key while the menu is open picks the item. */
shortcut?: ShortcutId;
/** A registered icon (core/icons.ts), drawn in the check column. */
icon?: string;
/** Greyed and unclickable. Menus disable rather than hide, so the set of
* commands stays in the same place from one right-click to the next. */
disabled?: boolean;
}
/** Anything with a viewport point: a MouseEvent, or a row's rect for a
* keyboard-opened menu. */
export interface MenuPoint {
clientX: number;
clientY: number;
}
export interface MenuRequest {
x: number;
y: number;
items: MenuItem[];
/** Highlighted on open: the first item when the keyboard opened the menu. */
initialIndex: number;
/** Where a pick goes instead of the shared dispatcher (App.handleMenuAction). */
onPick?: (action: string) => void;
}
export interface TabMenuContext {
@@ -38,25 +58,27 @@ export interface TabMenuContext {
}
export interface RowMenuContext {
path: string;
side: Side;
name: string;
type: EntryType;
isLocal: boolean;
hasEntry: boolean; // false = right-click on empty panel space
}
/** Items the highlight can land on. */
export const isSelectable = (item: MenuItem): boolean => !item.type && !item.disabled;
// PORTABILITY: shell-integration wording per OS (resolved at build time for locale)
const revealKey = (): string =>
IS_MAC ? 'ctx.revealFinder' : IS_WINDOWS ? 'ctx.revealExplorer' : 'ctx.revealFileManager';
const trashKey = (): string => (IS_WINDOWS ? 'ctx.moveToRecycleBin' : 'ctx.moveToTrash');
/**
* Builds and opens the panel right-click menus. This used to be a native
* Builds and opens the HTML context menus. This used to be a native
* electrobun ContextMenu on the bun side, but `showContextMenu` is a documented
* no-op on Linux (electrobun's own .hutch/devkit/api/sdks/main/proc/linux.md),
* which left the whole right-click surface dead there. The menu is plain HTML
* now — one code path on every platform — and still emits the exact same
* action strings, so the dispatcher in app.ts is unchanged.
* now — one code path on every platform.
*/
@Injectable({ providedIn: 'root' })
export class ContextMenuService {
@@ -65,76 +87,91 @@ export class ContextMenuService {
readonly request = signal<MenuRequest | null>(null);
open(event: MouseEvent, items: MenuItem[]): void {
this.request.set({ x: event.clientX, y: event.clientY, items });
open(
point: MenuPoint,
items: MenuItem[],
opts: { keyboard?: boolean; onPick?: (action: string) => void } = {},
): void {
const initialIndex = opts.keyboard ? stepIndex(items.map(isSelectable), -1, 1) : -1;
this.request.set({ x: point.clientX, y: point.clientY, items, initialIndex, onPick: opts.onPick });
}
close(): void {
this.request.set(null);
}
/** A picked item goes through the same dispatcher the app menubar uses. */
onPick(action: string): void {
/** A pick without its own handler goes through the dispatcher the app
* menubar uses. */
emit(action: string): void {
this.rpc.emitMenuAction(action);
}
/** Row / empty-space menu for a file panel. */
/**
* Row / empty-space menu for a file panel. Actions are FileCommand ids,
* picked through FileActionsService.run. Icons only on the everyday verbs —
* the same glyphs as their toolbar buttons.
*/
rowItems(ctx: RowMenuContext): MenuItem[] {
const t = (key: string) => this.i18n.t(key);
const cmd = (id: FileCommand, label: string, extra: Partial<MenuItem> = {}): MenuItem => ({
label,
action: id,
shortcut: id,
...extra,
});
const items: MenuItem[] = [];
if (!ctx.hasEntry || ctx.name === '..') {
// empty space (or the parent row): folder-level actions
items.push({ label: t('ctx.newFolder'), action: 'ctx-new-folder' });
items.push({ label: t('ctx.newFile'), action: 'ctx-new-file' });
items.push(cmd('new-folder', t('ctx.newFolder'), { icon: 'tdesignFolderAdd' }));
items.push(cmd('new-file', t('ctx.newFile')));
items.push({ type: 'separator' });
items.push({ label: t('ctx.refresh'), action: 'ctx-refresh' });
items.push(cmd('refresh', t('ctx.refresh')));
if (ctx.isLocal) {
items.push({ type: 'separator' });
items.push({ label: t(revealKey()), action: 'ctx-reveal' });
items.push(cmd('reveal', t(revealKey())));
}
return items;
}
items.push({ label: t('ctx.copyToOther'), action: 'ctx-copy' });
// the arrow points at the other panel, as on the toolbar's Send button
const sendIcon = ctx.side === 'left' ? 'tdesignArrowRight' : 'tdesignArrowLeft';
items.push(cmd('send', t('ctx.copyToOther'), { icon: sendIcon }));
if (ctx.type === 'dir') {
items.push({ label: t('ctx.open'), action: 'ctx-open' });
items.push(cmd('open', t('ctx.open')));
} else {
if (ctx.isLocal) {
items.push({ label: t('ctx.open'), action: 'ctx-open-default', tooltip: t('ctx.openDefault') });
items.push(cmd('open-default', t('ctx.open'), { tooltip: t('ctx.openDefault') }));
}
items.push({ label: t('ctx.edit'), action: 'ctx-edit', accelerator: 'F4' });
items.push(cmd('edit', t('ctx.edit'), { icon: 'tdesignFile1' }));
}
items.push({ label: t('ctx.rename'), action: 'ctx-rename' });
items.push(cmd('rename', t('ctx.rename'), { icon: 'tdesignEdit' }));
// chmod on Windows local files only flips the read-only bit — hide the lie
if (!(ctx.isLocal && IS_WINDOWS)) {
items.push({ label: t('ctx.permissions'), action: 'ctx-chmod' });
items.push(cmd('chmod', t('ctx.permissions')));
}
items.push({ type: 'separator' });
items.push({ label: t('ctx.copyPath'), action: 'ctx-copy-path' });
items.push(cmd('copy-path', t('ctx.copyPath')));
if (ctx.isLocal) {
items.push({ label: t(revealKey()), action: 'ctx-reveal' });
items.push(cmd('reveal', t(revealKey())));
}
items.push({ type: 'separator' });
if (ctx.isLocal) {
items.push({
label: t(trashKey()),
action: 'ctx-trash',
...(IS_MAC ? { tooltip: t('ctx.trashTooltip') } : {}),
});
items.push(cmd('trash', t(trashKey()), IS_MAC ? { tooltip: t('ctx.trashTooltip') } : {}));
}
items.push({ label: t('ctx.delete'), action: 'ctx-delete' });
items.push(cmd('delete', t('ctx.delete'), { icon: 'tdesignDelete' }));
return items;
}
/**
* The workspace-tab menu. Actions carry the target tab's id, because the
* right-clicked tab is not necessarily the active one — nothing here may
* assume `activeWorkspace`.
* assume `activeWorkspace`. (The hints name the keys, which act on the
* ACTIVE tab; picking by key while this menu is open acts on THIS one.)
*
* Everything illegal is DISABLED, not omitted: a menu whose items move
* between right-clicks is worse than a dead row, and "Close Tab" greyed out explains
* why the last tab cannot be closed better than its absence does.
* between right-clicks is worse than a dead row, and "Close Tab" greyed out
* explains why the last tab cannot be closed better than its absence does.
*
* Duplicate/Rename/Save-session are deliberately absent until tabs have an
* identity to duplicate (a stored connection id) — the sessions round.
@@ -143,24 +180,32 @@ export class ContextMenuService {
const t = (key: string) => this.i18n.t(key);
const last = ctx.tabCount <= 1;
return [
{ label: t('ctx.tabNew'), action: 'tab:new', accelerator: `${MOD_LABEL}T` },
{ label: t('ctx.tabNew'), action: 'tab:new', shortcut: 'new-tab', icon: 'tdesignAdd' },
{ type: 'separator' },
{
label: t('ctx.tabClose'),
action: `tab:close:${ctx.id}`,
accelerator: `${MOD_LABEL}W`,
shortcut: 'close-tab',
icon: 'tdesignClose',
disabled: last,
},
{
label: t('ctx.tabCloseOthers'),
action: `tab:close-others:${ctx.id}`,
shortcut: 'close-other-tabs',
disabled: last,
},
{ label: t('ctx.tabCloseOthers'), action: `tab:close-others:${ctx.id}`, disabled: last },
{
label: t('ctx.tabCloseRight'),
action: `tab:close-right:${ctx.id}`,
shortcut: 'close-tabs-right',
disabled: ctx.index >= ctx.tabCount - 1,
},
{ type: 'separator' },
{
label: t('ctx.tabDisconnect'),
action: `tab:disconnect:${ctx.id}`,
shortcut: 'disconnect-tab',
disabled: !ctx.isRemote,
},
];
+3 -1
View File
@@ -47,8 +47,10 @@ export class DialogsService {
});
}
/** Any dialog up — the overwrite question included. Reads signals, so an
* effect or computed that asks re-runs when a dialog opens or closes. */
get anyOpen(): boolean {
return !!(this.prompt() || this.confirm() || this.chmod());
return !!(this.prompt() || this.confirm() || this.chmod() || this.overwrite());
}
closeAll(): void {
+113 -16
View File
@@ -1,25 +1,50 @@
import { Injectable, inject } from '@angular/core';
import type { FileEntry } from '@shared/types';
import { ContextMenuService } from './context-menu.service';
import { ContextMenuService, type MenuPoint } from './context-menu.service';
import { DialogsService } from './dialogs.service';
import { joinPath } from './format';
import { type PanelState, type Side } from './panels.service';
import { type PanelState, type Side, type SortKey } from './panels.service';
import { IS_WINDOWS } from './platform';
import { RpcService } from './rpc.service';
import { SettingsService } from './settings.service';
import type { ShortcutId } from './shortcuts.service';
import { I18nService } from './i18n.service';
import { ToastService } from './toast.service';
import { TransfersService } from './transfers.service';
/** The row (or empty space) the user last right-clicked; ctx-* actions apply here. */
export interface MenuTarget {
/** What a file command acts on: a panel, and the row it was invoked on (the
* cursor row from the keyboard, the right-clicked row from a menu; null =
* the folder itself). */
export interface FileTarget {
side: Side;
panel: PanelState;
entry: FileEntry | null;
}
/** The keymap commands that act on files — everything the keyboard, the
* right-click menu, the macOS menu bar and the panel toolbar run, all through
* run() so the four entry points can't drift apart. */
export type FileCommand = Extract<
ShortcutId,
| 'open'
| 'open-default'
| 'send'
| 'edit'
| 'rename'
| 'new-folder'
| 'new-file'
| 'chmod'
| 'delete'
| 'trash'
| 'copy-path'
| 'reveal'
| 'refresh'
| `sort-${string}`
>;
/**
* File operations invoked from a panel's toolbar / keyboard. They act on the
* GIVEN panel: on the selection if there is one, else on the cursor row.
* File operations, always against an explicit panel: on its selection if there
* is one, else on the target row.
*/
@Injectable({ providedIn: 'root' })
export class FileActionsService {
@@ -29,29 +54,101 @@ export class FileActionsService {
private readonly dialogs = inject(DialogsService);
private readonly menu = inject(ContextMenuService);
private readonly settings = inject(SettingsService);
private readonly transfers = inject(TransfersService);
menuTarget: MenuTarget | null = null;
/** Run a file command. One switch for every entry point. */
run(id: FileCommand, target: FileTarget): void {
const { side, panel } = target;
const local = panel.sessionId() === 'local';
// the ".." row stands for the folder itself, as on the empty-space menu
const entry = target.entry && target.entry.name !== '..' ? target.entry : null;
switch (id) {
case 'open':
case 'open-default':
// folders, symlinks and ".." navigate; a LOCAL file opens in its default
// app — from the menu's Open always, from Enter / double-click only
// when Settings → File list says so
if (!target.entry) return;
if (target.entry.type !== 'file') panel.open(target.entry);
else if (local && (id === 'open-default' || this.settings.openFilesOnEnter())) {
this.shell('open', target.entry.path);
}
return;
case 'send':
void this.transfers.copyToOtherPanel(side);
return;
case 'edit':
void this.edit(panel);
return;
case 'rename':
this.rename(panel);
return;
case 'new-folder':
this.mkdir(panel);
return;
case 'new-file':
this.createFile(panel);
return;
case 'chmod':
this.chmod(panel);
return;
case 'delete':
this.delete(panel);
return;
case 'trash':
if (local) void this.trash(panel);
return;
case 'copy-path':
this.shell('copyPath', entry?.path ?? panel.cwd());
return;
case 'reveal':
if (local) this.shell('reveal', entry?.path ?? panel.cwd());
return;
case 'refresh':
void panel.refresh();
return;
default:
// sort-name, sort-size…: again = reverse
if (id.startsWith('sort-')) panel.toggleSort(id.slice('sort-'.length) as SortKey);
}
}
/** Right-click entry point: remember the target, then open the menu on it. */
openContextMenu(event: MouseEvent, target: MenuTarget): void {
this.menuTarget = target;
const { panel, entry } = target;
/** Open the row / empty-space menu on `target`; its picks run here. */
openContextMenu(point: MenuPoint, target: FileTarget, keyboard = false): void {
const { side, panel, entry } = target;
this.menu.open(
event,
point,
this.menu.rowItems({
path: entry?.path ?? panel.cwd(),
side,
name: entry?.name ?? '',
type: entry?.type ?? 'dir',
isLocal: panel.sessionId() === 'local',
hasEntry: !!entry,
}),
{ keyboard, onPick: (action) => this.run(action as FileCommand, target) },
);
}
async trash(panel: PanelState, entry: FileEntry): Promise<void> {
/** Local shell integration — only bun can reach the OS shell / clipboard. */
private shell(action: 'open' | 'reveal' | 'copyPath', path: string): void {
void this.rpc.request.shellItemAction({ action, path });
}
/** Move the selection (else the target row) to the Trash, one item at a time. */
async trash(panel: PanelState): Promise<void> {
const targets = this.targets(panel);
if (!targets.length) return;
let moved = 0;
for (const entry of targets) {
const res = await this.rpc.request.moveToTrash({ path: entry.path });
if (!res.ok) this.toast.error(res.error);
else this.toast.info(this.i18n.t('toasts.movedToTrash', { name: entry.name }));
if (!res.ok) {
this.toast.error(res.error);
break;
}
moved++;
}
if (moved === 1) this.toast.info(this.i18n.t('toasts.movedToTrash', { name: targets[0].name }));
else if (moved > 1) this.toast.info(this.i18n.t('toasts.movedManyToTrash', { count: moved }));
await panel.refresh();
}
+36
View File
@@ -0,0 +1,36 @@
/** What Tab can land on. Tab order is DOM order: the app sets no positive tabindex. */
const FOCUSABLE = 'button, input, select, textarea, [tabindex]';
/**
* Tab / Shift+Tab through the focusable controls under `root`, in DOM order,
* wrapping. Done by hand because WKWebView (macOS) skips buttons, checkboxes
* and radios on Tab unless the user turned on System Settings → Keyboard →
* Keyboard navigation, which left dialogs, Settings and the connection manager
* mouse-only there. It is also the focus trap the modal dialogs lacked. A radio
* group is one stop (its checked radio), as natively; arrows move inside it.
* Returns true when it took the key.
*/
export function cycleFocus(root: Element, event: KeyboardEvent): boolean {
if (event.key !== 'Tab' || event.metaKey || event.ctrlKey || event.altKey) return false;
const stops = [...root.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(isTabStop);
if (!stops.length) return false;
event.preventDefault();
const at = stops.indexOf(document.activeElement as HTMLElement);
const step = event.shiftKey ? -1 : 1;
const next = at < 0 ? (step > 0 ? 0 : stops.length - 1) : (at + step + stops.length) % stops.length;
stops[next].focus();
return true;
}
function isTabStop(el: HTMLElement): boolean {
if (el.tabIndex < 0 || el.matches(':disabled')) return false;
if (!el.getClientRects().length) return false; // display:none, or inside a hidden parent
if (el instanceof HTMLInputElement && el.type === 'radio' && el.name) {
const group = [
...document.querySelectorAll<HTMLInputElement>(`input[type=radio][name="${CSS.escape(el.name)}"]`),
];
const checked = group.find((radio) => radio.checked);
return el === (checked ?? group[0]);
}
return true;
}
+13
View File
@@ -352,6 +352,19 @@ export class PanelsService {
this.focus.bump();
}
/** Each file list's key handler. A key that lands on <body> — a mouse click
* dropped focus (WebKit doesn't focus clicked buttons) — still reaches the
* active list through forwardListKey instead of dying until the next click. */
private readonly listKeys = new Map<Side, (event: KeyboardEvent) => void>();
registerListKeys(side: Side, handler: (event: KeyboardEvent) => void): void {
this.listKeys.set(side, handler);
}
forwardListKey(event: KeyboardEvent): void {
this.listKeys.get(this.activeSide())?.(event);
}
// ---- workspace (tab) management ----
newWorkspace(): void {
+12 -4
View File
@@ -21,10 +21,6 @@ export const IS_WINDOWS = PLATFORM === 'win32';
export const IS_LINUX = PLATFORM === 'linux';
/** Shortcut-hint labels: "⌘W" on macOS, "Ctrl+W" elsewhere. */
export const MOD_LABEL = IS_MAC ? '⌘' : 'Ctrl+';
export const ALT_LABEL = IS_MAC ? '⌥' : 'Alt+';
export const APP_MODE: 'main' | 'editor' | 'manager' | 'settings' =
typeof window !== 'undefined' ? (window.__APP_MODE ?? 'main') : 'main';
@@ -35,6 +31,18 @@ export const EDITOR_CONTEXT =
* hiddenInset layout, see chromeOptions), which reserves `pl-24` for them. */
export const IS_MAC_CHROME = IS_MAC;
/**
* WebView2 (Windows) reloads the whole page on F5 / Ctrl+R / Ctrl+F5 /
* Ctrl+Shift+R unless the page claims the key — dropping every session and any
* unsaved editor text. Every window root calls this for keys none of its
* bindings took. Known ceiling: unverified whether Electrobun already turns
* WebView2's browser keys off; harmless if it does.
*/
export function blockReloadKeys(event: KeyboardEvent): void {
if (!IS_WINDOWS || event.defaultPrevented) return;
if (event.key === 'F5' || (event.ctrlKey && event.code === 'KeyR')) event.preventDefault();
}
/**
* Kill the webview's default right-click menu (Reload, Inspect Element…)
* everywhere the app doesn't show its own native menu. Text fields keep the
+23
View File
@@ -17,6 +17,9 @@ export class SettingsService {
readonly autoClearCompleted = signal(DEFAULT_SETTINGS.autoClearCompleted);
readonly editor = signal<AppSettings['editor']>(DEFAULT_SETTINGS.editor);
readonly editorApp = signal(DEFAULT_SETTINGS.editorApp);
/** Settings → Keyboard overrides; ShortcutsService applies them to the keymap. */
readonly keybindings = signal<AppSettings['keybindings']>(DEFAULT_SETTINGS.keybindings);
readonly openFilesOnEnter = signal(DEFAULT_SETTINGS.openFilesOnEnter);
// Auto-refresh is always on for now (see panels.service). To make it
// user-controllable: uncomment the field in types.ts, then here add
// readonly autoRefresh = signal(DEFAULT_SETTINGS.autoRefresh);
@@ -25,6 +28,10 @@ export class SettingsService {
private readonly rpc = inject(RpcService);
private readonly i18n = inject(I18nService);
/** Saves are whole-object: one sent before the first getSettings lands would
* write these defaults over the user's settings (a ⌘+ pressed as a window
* opens would wipe every keyboard remap), so nothing persists until then. */
private loaded = false;
/** Whether the app is actually rendering dark right now (drives the Tone row). */
readonly effectiveDark = computed(
@@ -45,6 +52,7 @@ export class SettingsService {
}
private applyAll(settings: AppSettings): void {
this.loaded = true;
this.locale.set(settings.locale);
this.theme.set(settings.theme);
this.darkTone.set(settings.darkTone);
@@ -56,6 +64,8 @@ export class SettingsService {
this.autoClearCompleted.set(settings.autoClearCompleted);
this.editor.set(settings.editor);
this.editorApp.set(settings.editorApp);
this.keybindings.set(settings.keybindings);
this.openFilesOnEnter.set(settings.openFilesOnEnter);
this.applyTheme();
this.applyDarkTone();
this.applyUiScale();
@@ -123,6 +133,16 @@ export class SettingsService {
void this.persist();
}
setKeybindings(keybindings: AppSettings['keybindings']): void {
this.keybindings.set(keybindings);
void this.persist();
}
setOpenFilesOnEnter(open: boolean): void {
this.openFilesOnEnter.set(open);
void this.persist();
}
private applyTheme(): void {
const theme = this.theme();
if (theme === 'system') {
@@ -172,10 +192,13 @@ export class SettingsService {
autoClearCompleted: this.autoClearCompleted(),
editor: this.editor(),
editorApp: this.editorApp(),
keybindings: this.keybindings(),
openFilesOnEnter: this.openFilesOnEnter(),
};
}
private async persist(): Promise<void> {
if (!this.loaded) return;
await this.rpc.request.saveSettings({ settings: this.settings() });
}
}
+144 -97
View File
@@ -1,114 +1,161 @@
import { Injectable } from '@angular/core';
import { Injectable, computed, inject } from '@angular/core';
import {
type Combo,
EN_KEY_NAMES,
effectiveKeymap,
firesInTextField,
formatCombo,
isRepeatable,
type KeyEventLike,
type KeyNames,
matchesEvent,
parseCombo,
type ResolvedBinding,
type Scope,
sameCombo,
serializeCombo,
type ShortcutId,
} from '@shared/keymap';
import { I18nService } from './i18n.service';
import { IS_MAC } from './platform';
import { SettingsService } from './settings.service';
export type { ShortcutId } from '@shared/keymap';
/** A keydown as resolve() reads it: the matching fields plus where it came from. */
type KeyInput = KeyEventLike & { target?: EventTarget | null; isComposing?: boolean; keyCode?: number };
/**
* Every window-level shortcut the app answers to, by name. Components switch
* on these ids instead of key-matching inline, so the whole keymap is ONE
* table — the precondition for the vim-style bindings planned next, which
* will need a mode/leader state machine wrapped around exactly this point.
*/
export type ShortcutId =
// main window (workspace/tab management)
| 'new-tab'
| 'close-tab'
| 'cycle-tab'
| 'cycle-tab-back'
| 'go-to-tab' // 1-9; the digit rides in ShortcutMatch.digit
| 'open-settings'
// editor window
| 'save'
| 'find'
| 'close-window'
| 'toggle-wrap'
// any window
| 'scale-up'
| 'scale-down'
| 'scale-reset';
export interface ShortcutMatch {
id: ShortcutId;
/** Only for go-to-tab: the digit pressed, 1–9. */
digit?: number;
}
/** Which keymap a window consults. 'manager' and 'settings' answer only to the
* any-window shortcuts (scale). Escape/Tab stay component-local: their meaning
* is contextual state (find bar open? close prompt up? which pane?), not a
* global binding. */
export type ShortcutScope = 'main' | 'editor' | 'manager' | 'settings';
/**
* The keyboard layer: modifier helpers + one declarative keymap.
* The keyboard layer over the shared keymap (src/shared/keymap.ts): resolves
* keydowns against the EFFECTIVE keymap — defaults plus the Settings → Keyboard
* remaps, live in every window — and formats the hints menus and tooltips show.
*
* House rules encoded here rather than re-derived per component (they were
* previously copy-pasted inline in six places, drifting apart):
* - `mod` is metaKey OR ctrlKey — ⌘ on macOS, Ctrl elsewhere. The keyboard
* does not change with the window chrome (platform.ts says the same about
* MOD_LABEL).
* - Layout-dependent keys match on `event.code`, not `event.key`: digits
* (AZERTY's digit row shifts), +/- (key varies wildly across layouts), and
* letter chords with Alt (macOS Option produces Ω for ⌥Z). Plain letter
* chords match on `key` so they follow the user's layout.
* - isTypingTarget guards shortcuts that would be hostile mid-typing. It is
* deliberately NOT applied inside resolve(): the existing bindings rely on
* the path bar's stopPropagation and the editor WANTS Mod+S while typing.
* Callers opt in per shortcut (the scale keys do).
* - Matching is exact: ⌃F is not ⌘F, Ctrl+Tab is not Tab. `Mod` is ⌘ on
* macOS and Ctrl elsewhere.
* - On macOS the PAGE sees ⌘-keys first: WKWebView hands key equivalents to the
* page before the app menu (WebKit's WebViewImpl::performKeyEquivalent), so a
* key a window claims here (claim() → preventDefault) never reaches the menu
* bar, whose accelerators bun builds from the same table. Keys nobody claims
* fall through to it.
* - From a text field only firesInTextField() combos count (⌘S yes, Delete no).
* - Escape, the arrows inside menus and dialog Enter stay component-local:
* they are fixed, so nobody can remap themselves out of a dialog.
*/
@Injectable({ providedIn: 'root' })
export class ShortcutsService {
/** The platform command modifier: ⌘ on macOS, Ctrl elsewhere. Mouse events
* qualify too — Mod+click toggle-select in the panels uses the same rule. */
isMod(event: KeyboardEvent | MouseEvent): boolean {
return event.metaKey || event.ctrlKey;
}
private readonly settings = inject(SettingsService);
private readonly i18n = inject(I18nService);
/** True when the event originates from something the user types into. */
isTypingTarget(event: KeyboardEvent): boolean {
const target = event.target as HTMLElement | null;
return !!target?.closest('input, textarea, select, [contenteditable="true"]');
readonly keymap = computed(() => effectiveKeymap(this.settings.keybindings(), IS_MAC));
private readonly byId = computed(() => new Map(this.keymap().map((b) => [b.id, b])));
/** Localized key names for the non-mac spelling ("Strg+Entf"); reading t()
* makes every hint follow a language switch. */
private readonly names = computed<KeyNames>(() => {
const names = { ...EN_KEY_NAMES };
for (const key of Object.keys(names) as (keyof KeyNames)[]) {
names[key] = this.i18n.t(`keys.names.${key}`);
}
return names;
});
/** The command a keydown triggers in `scope`, or null. Window scopes include
* `any`; `panel` doesn't (the window root runs those). */
resolve(event: KeyInput, scope: Scope): ShortcutId | null {
// an IME's Enter commits a candidate, it is never a shortcut
if (event.isComposing || event.keyCode === 229) return null;
const typing = this.isTypingTarget(event);
for (const binding of this.keymap()) {
if (!binding.scopes.includes(scope) && (scope === 'panel' || !binding.scopes.includes('any'))) {
continue;
}
for (const combo of binding.combos) {
if (typing && !firesInTextField(combo, IS_MAC)) continue;
if (matchesEvent(combo, event, IS_MAC)) return binding.id;
}
}
return null;
}
/**
* Match an event against the scope's keymap. Returns null for anything the
* table does not claim — callers must then leave the event alone.
* resolve() + take the key: a match is preventDefault-ed, so the macOS menu
* never runs it a second time. A held key repeats only movement-like
* commands; any other repeat is swallowed (holding ⌘W closes one tab).
*/
resolve(event: KeyboardEvent, scope: ShortcutScope): ShortcutMatch | null {
const mod = this.isMod(event);
const key = event.key.toLowerCase();
// ---- any window: interface scale ----
// event.code, not key: '+' needs Shift on many layouts and '-' moves
// around; the physical Equal/Minus keys (and the numpad pair) are stable.
if (mod && !event.altKey) {
if (event.code === 'Equal' || event.code === 'NumpadAdd') return { id: 'scale-up' };
if (event.code === 'Minus' || event.code === 'NumpadSubtract') return { id: 'scale-down' };
if (event.code === 'Digit0' || event.code === 'Numpad0') return { id: 'scale-reset' };
claim(event: KeyboardEvent, scope: Scope): ShortcutId | null {
const id = this.resolve(event, scope);
if (!id) return null;
event.preventDefault();
return event.repeat && !isRepeatable(id) ? null : id;
}
if (scope === 'manager' || scope === 'settings') return null; // any-window shortcuts only
if (scope === 'main') {
// on macOS the app menu's ⌘, intercepts first; this is the Windows/Linux path
if (mod && key === ',') return { id: 'open-settings' };
if (mod && key === 't') return { id: 'new-tab' };
if (mod && key === 'w') return { id: 'close-tab' };
// ctrlKey only, never meta: ⌘Tab is the macOS app switcher
if (event.ctrlKey && event.key === 'Tab') {
return { id: event.shiftKey ? 'cycle-tab-back' : 'cycle-tab' };
}
if (mod && !event.shiftKey && !event.altKey) {
const digit = /^(?:Digit|Numpad)([1-9])$/.exec(event.code)?.[1];
if (digit) return { id: 'go-to-tab', digit: Number(digit) };
}
return null;
/** Whether a keydown is one of `id`'s combos (an open menu matching its items). */
matches(id: ShortcutId, event: KeyEventLike): boolean {
return !!this.byId().get(id)?.combos.some((c) => matchesEvent(c, event, IS_MAC));
}
// scope === 'editor'
if (mod && key === 's') return { id: 'save' };
if (mod && key === 'f') return { id: 'find' };
// on macOS the app menu intercepts ⌘W before this ever fires; this arm is
// the Windows/Linux path
if (mod && key === 'w') return { id: 'close-window' };
if (event.altKey && event.code === 'KeyZ') return { id: 'toggle-wrap' };
return null;
binding(id: ShortcutId): ResolvedBinding | undefined {
return this.byId().get(id);
}
format(combo: Combo): string {
return formatCombo(combo, IS_MAC, this.names());
}
/** The hint menus show: the command's first key, or '' when unbound. */
label(id: ShortcutId): string {
const first = this.byId().get(id)?.combos[0];
return first ? this.format(first) : '';
}
labels(id: ShortcutId): string[] {
return (this.byId().get(id)?.combos ?? []).map((c) => this.format(c));
}
/** A tooltip with the command's keys: "Delete (F8 / Del)"; bare when unbound. */
tip(text: string, id: ShortcutId): string {
const keys = this.labels(id);
return keys.length ? `${text} (${keys.join(' / ')})` : text;
}
/** The same for a FIXED key — one no remap moves, such as Enter in the find
* box — so it reads in the platform's spelling too (⇧↩ / Shift+Enter). */
tipFixed(text: string, combo: string): string {
const parsed = parseCombo(combo, IS_MAC);
return parsed ? `${text} (${this.format(parsed)})` : text;
}
/**
* Store new combos for commands (Settings → Keyboard). Only rows that differ
* from their defaults are kept, so a reset — or a remap back to the
* default — leaves nothing behind.
*/
rebind(changes: Partial<Record<ShortcutId, Combo[]>>): void {
const next = { ...this.settings.keybindings() };
for (const [id, combos] of Object.entries(changes) as [ShortcutId, Combo[]][]) {
const defaults = this.byId().get(id)?.defaults ?? [];
const isDefault =
combos.length === defaults.length && combos.every((c, i) => sameCombo(c, defaults[i]));
if (isDefault) delete next[id];
else next[id] = combos.map(serializeCombo);
}
this.settings.setKeybindings(next);
}
resetAll(): void {
this.settings.setKeybindings({});
}
/** The platform command modifier: ⌘ on macOS, Ctrl elsewhere — exactly one.
* Mouse events too: Mod+click toggle-selects in the panels. */
isMod(event: KeyboardEvent | MouseEvent): boolean {
return IS_MAC ? event.metaKey : event.ctrlKey;
}
/** True when the event comes from something the user types into. */
isTypingTarget(event: { target?: EventTarget | null }): boolean {
const target = event.target as HTMLElement | null;
return !!target?.closest?.(
'textarea, select, [contenteditable="true"], input:not([type=checkbox]):not([type=radio]):not([type=button])',
);
}
}
+8
View File
@@ -45,6 +45,14 @@ export class UpdaterService {
void this.rpc.request.applyUpdate({}); // quits + relaunches
}
/** The pill's one action, also the "Install update" key: download when
* available, apply (relaunch) once ready; nothing otherwise. */
advance(): void {
const state = this.state();
if (state === 'available') void this.download();
else if (state === 'ready') this.apply();
}
/** Manual re-check (menu item). */
async check(): Promise<void> {
if (!this.rpc.available) return;
+1
View File
@@ -31,6 +31,7 @@
<ng-icon name="tdesignServer" size="1.25rem" class="text-muted-foreground" />
<p class="mt-1.5 text-xs text-muted-foreground">{{ i18n.t('app.managerOpen') }}</p>
<button
(click)="focusManager()"
class="mt-3 bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90"
>
{{ i18n.t('app.showConnections') }}
+135 -85
View File
@@ -1,22 +1,24 @@
import { Component, inject, signal } from '@angular/core';
import { Component, inject, signal, viewChild } from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import { I18nService } from '@core/i18n.service';
import { BRANDING } from '@shared/branding';
import { NATIVE_MENU_IDS } from '@shared/keymap';
import type { ColumnKey } from '@shared/types';
import { ConnectionsService } from '@core/connections.service';
import { ContextMenuService } from '@core/context-menu.service';
import { ContextMenu } from './context-menu';
import { ChmodDialog } from './dialogs/chmod-dialog';
import { ConfirmDialog } from './dialogs/confirm-dialog';
import { OverwriteDialog } from './dialogs/overwrite-dialog';
import { PromptDialog } from './dialogs/prompt-dialog';
import { DialogsService } from '@core/dialogs.service';
import { FileActionsService } from '@core/file-actions.service';
import { FileActionsService, type FileCommand } from '@core/file-actions.service';
import { FilePanel } from './file-panel/file-panel';
import { PanelsService } from '@core/panels.service';
import { blockNativeContextMenu } from '@core/platform';
import { blockNativeContextMenu, blockReloadKeys } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
import { ShortcutsService, type ShortcutId } from '@core/shortcuts.service';
import { StatusBar } from './status-bar/status-bar';
import { TabBar } from './tab-bar/tab-bar';
import { ToastService } from '@core/toast.service';
@@ -44,6 +46,7 @@ import { UpdaterService } from '@core/updater.service';
host: {
'(window:keydown)': 'onWindowKeydown($event)',
'(window:contextmenu)': 'blockContextMenu($event)',
'(mousedown)': 'keepListFocus($event)',
},
})
export class App {
@@ -58,6 +61,8 @@ export class App {
private readonly settings = inject(SettingsService);
private readonly shortcuts = inject(ShortcutsService);
private readonly updater = inject(UpdaterService);
private readonly menu = inject(ContextMenuService);
private readonly transferBar = viewChild(TransferBar);
/** The connection-manager window is open — this window is modal-blocked. */
readonly managerOpen = signal(false);
@@ -105,10 +110,6 @@ export class App {
/** Native application-menu / manager-window actions forwarded from bun. */
private async handleMenuAction(action: string): Promise<void> {
if (action.startsWith('ctx-')) {
this.handleContextAction(action);
return;
}
if (action.startsWith('connect:')) {
const connection = await this.findConnection(action.slice('connect:'.length));
if (connection) {
@@ -137,22 +138,19 @@ export class App {
}
switch (action) {
case 'new-tab':
this.panels.newWorkspace();
break;
case 'close-tab':
this.panels.closeWorkspace(this.panels.activeWorkspaceId());
this.runWindowCommand(action);
break;
// the macOS File / View items act on the active panel, exactly like their keys
case 'new-folder':
this.actions.mkdir(this.panels.active());
break;
case 'new-file':
this.actions.createFile(this.panels.active());
this.runFileCommand(action);
break;
case 'edit-file':
void this.actions.edit(this.panels.active());
this.runFileCommand('edit');
break;
case 'refresh-active':
void this.panels.active().refresh();
this.runFileCommand('refresh');
break;
case 'check-for-updates':
void this.updater.check();
@@ -160,37 +158,102 @@ export class App {
}
}
/** Window shortcuts — matching lives in ShortcutsService (one keymap for the
* app); this switch only maps ids onto actions. Panel-level keys stay on
* the panels themselves. */
private runFileCommand(id: FileCommand): void {
const panel = this.panels.active();
const entry = panel.sorted()[panel.cursor()] ?? null;
this.actions.run(id, { side: this.panels.activeSide(), panel, entry });
}
/**
* Window keys — the `main` scope of the shared keymap (ShortcutsService); the
* focused file list handles its own `panel` keys first. Whatever nobody
* claims ends at the WebView2 reload guard.
*/
onWindowKeydown(event: KeyboardEvent): void {
if (this.managerOpen()) return; // modal-blocked behind the manager
const match = this.shortcuts.resolve(event, 'main');
if (!match) return;
// scale keys are hostile mid-typing ('-' in a rename prompt must type '-');
// the tab shortcuts keep firing there, as they always did
if (match.id.startsWith('scale-') && this.shortcuts.isTypingTarget(event)) return;
event.preventDefault();
switch (match.id) {
this.handleWindowKey(event);
blockReloadKeys(event); // a no-op once something claimed the key
}
private handleWindowKey(event: KeyboardEvent): void {
// a component took it (the list, a menu, a dialog), or the connection
// manager holds this window modal
if (event.defaultPrevented || this.managerOpen()) return;
if (this.dialogs.anyOpen || this.menu.request()) {
this.swallowBehindOverlay(event);
return;
}
if (event.target === document.body) {
// a click dropped focus to <body>: the active list still gets its keys
this.panels.forwardListKey(event);
this.panels.refocus();
if (event.defaultPrevented) return;
}
const id = this.shortcuts.claim(event, 'main');
if (id) this.runWindowCommand(id);
}
/**
* A dialog or menu owns the keyboard. Window commands are swallowed — an
* unclaimed ⌘T would fall through to the macOS menu bar and open a tab
* behind the dialog — and so are the panel commands the menu bar carries
* (⌘N, ⌘E…). The interface-scale keys still work.
*/
private swallowBehindOverlay(event: KeyboardEvent): void {
const id = this.shortcuts.resolve(event, 'main');
if (id === 'scale-up' || id === 'scale-down' || id === 'scale-reset') {
const claimed = this.shortcuts.claim(event, 'main');
if (claimed) this.runWindowCommand(claimed);
return;
}
const panelId = id ? null : this.shortcuts.resolve(event, 'panel');
if (id || (panelId && NATIVE_MENU_IDS.includes(panelId))) event.preventDefault();
}
private runWindowCommand(id: ShortcutId): void {
const active = this.panels.activeWorkspaceId();
switch (id) {
case 'new-tab':
this.panels.newWorkspace();
break;
case 'close-tab':
this.panels.closeWorkspace(this.panels.activeWorkspaceId());
this.panels.closeWorkspace(active);
break;
case 'cycle-tab':
case 'close-other-tabs':
this.panels.closeOtherWorkspaces(active);
break;
case 'close-tabs-right':
this.panels.closeWorkspacesToRight(active);
break;
case 'next-tab':
this.panels.cycleWorkspace(1);
break;
case 'cycle-tab-back':
case 'prev-tab':
this.panels.cycleWorkspace(-1);
break;
case 'go-to-tab':
// ⌘1–⌘8 jump to that tab, ⌘9 to the last, like Firefox
this.panels.goToWorkspace(match.digit === 9 ? -1 : match.digit! - 1);
case 'go-to-last-tab':
this.panels.goToWorkspace(-1);
break;
case 'move-tab-left':
this.moveActiveTab(-1);
break;
case 'move-tab-right':
this.moveActiveTab(1);
break;
case 'disconnect-tab':
void this.panels.disconnectWorkspace(active);
break;
case 'open-settings':
void this.rpc.request.openSettings({});
break;
case 'connection-manager':
void this.rpc.request.openConnectionManager({});
break;
case 'toggle-transfers':
this.toggleTransfers();
break;
case 'install-update':
this.updater.advance();
break;
case 'scale-up':
this.settings.setUiScale(this.settings.uiScale() + 0.1);
break;
@@ -200,10 +263,48 @@ export class App {
case 'scale-reset':
this.settings.setUiScale(1);
break;
default: {
// go-to-tab-1…8: that tab (go-to-last-tab is ⌘9, like Firefox)
const n = this.shortcuts.binding(id)?.n;
if (n) this.panels.goToWorkspace(n - 1);
}
}
}
/** Move-tab keys: the keyboard's tab drag. */
private moveActiveTab(delta: 1 | -1): void {
const list = this.panels.workspaces();
const index = list.findIndex((w) => w.id === this.panels.activeWorkspaceId());
if (index >= 0) this.panels.moveWorkspace(list[index].id, index + delta);
}
/** ⌘J: open the transfer list with focus in it (Esc goes back to the files),
* or close it. It only renders with jobs, so with none there is nothing to show. */
private toggleTransfers(): void {
if (!this.transfers.hasJobs()) return;
const open = !this.transfers.expanded();
this.transfers.expanded.set(open);
if (open) this.transferBar()?.focusFirst();
else this.panels.refocus();
}
/**
* A click on a chrome button keeps keyboard focus where it was — normally the
* file list. WebKit drops focus to <body> on a button click (every list key
* then died until the list was clicked), Windows parks it on the button,
* where Space would click it again. The click itself still fires. Text
* fields, menus, dialogs and the draggable tabs keep their default.
*/
keepListFocus(event: MouseEvent): void {
const target = event.target as Element;
if (
target.closest('button') &&
!target.closest('input, select, textarea, [role=menu], [role=dialog], [draggable=true]')
) {
event.preventDefault();
}
}
/** Context-menu actions apply to the row/panel remembered at right-click time. */
/**
* Workspace-tab menu actions. The target id travels INSIDE the action string
* because the right-clicked tab is not necessarily the active one — nothing
@@ -232,55 +333,4 @@ export class App {
break;
}
}
private handleContextAction(action: string): void {
const target = this.actions.menuTarget;
if (!target) return;
const { panel, side, entry } = target;
// the empty-space menu acts on the directory itself
const path = entry?.path ?? panel.cwd();
switch (action) {
case 'ctx-open':
if (entry) panel.open(entry);
break;
// local shell integration — only bun can reach the OS shell/clipboard
case 'ctx-reveal':
void this.rpc.request.shellItemAction({ action: 'reveal', path });
break;
case 'ctx-open-default':
void this.rpc.request.shellItemAction({ action: 'open', path });
break;
case 'ctx-copy-path':
void this.rpc.request.shellItemAction({ action: 'copyPath', path });
break;
case 'ctx-edit':
void this.actions.edit(panel);
break;
case 'ctx-copy':
void this.transfers.copyToOtherPanel(side);
break;
case 'ctx-rename':
this.actions.rename(panel);
break;
case 'ctx-chmod':
this.actions.chmod(panel);
break;
case 'ctx-delete':
this.actions.delete(panel);
break;
case 'ctx-trash':
if (entry) void this.actions.trash(panel, entry);
break;
case 'ctx-new-folder':
this.actions.mkdir(panel);
break;
case 'ctx-new-file':
this.actions.createFile(panel);
break;
case 'ctx-refresh':
void panel.refresh();
break;
}
}
}
@@ -6,7 +6,7 @@ import { ConnectionsService } from '@core/connections.service';
import { ConfirmDialog } from '../dialogs/confirm-dialog';
import { PromptDialog } from '../dialogs/prompt-dialog';
import { DialogsService } from '@core/dialogs.service';
import { blockNativeContextMenu, IS_MAC_CHROME } from '@core/platform';
import { blockNativeContextMenu, blockReloadKeys, IS_MAC_CHROME } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
@@ -148,12 +148,12 @@ export class ConnectionManager {
/** Any-window shortcuts (interface scale). Escape has its own binding above. */
onWindowKeydown(event: KeyboardEvent): void {
const match = this.shortcuts.resolve(event, 'manager');
if (!match || this.shortcuts.isTypingTarget(event)) return;
event.preventDefault();
if (match.id === 'scale-up') this.settings.setUiScale(this.settings.uiScale() + 0.1);
else if (match.id === 'scale-down') this.settings.setUiScale(this.settings.uiScale() - 0.1);
else if (match.id === 'scale-reset') this.settings.setUiScale(1);
const id = this.shortcuts.claim(event, 'manager');
if (id === 'close-window') this.close();
else if (id === 'scale-up') this.settings.setUiScale(this.settings.uiScale() + 0.1);
else if (id === 'scale-down') this.settings.setUiScale(this.settings.uiScale() - 0.1);
else if (id === 'scale-reset') this.settings.setUiScale(1);
blockReloadKeys(event);
}
blockContextMenu(event: Event): void {
+79 -33
View File
@@ -8,10 +8,11 @@ import {
viewChild,
} from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import { ContextMenuService, type MenuItem } from '@core/context-menu.service';
import { ContextMenuService, isSelectable, type MenuItem } from '@core/context-menu.service';
import { FocusService } from '@core/focus.service';
import { stepIndex } from '@core/menu-nav';
import { remPx } from '@core/metrics';
import { ShortcutsService } from '@core/shortcuts.service';
/** Rough per-item metrics in REM, used only to decide whether the menu must
* flip. Converted through remPx() at open time so the math tracks the same
@@ -20,13 +21,19 @@ import { remPx } from '@core/metrics';
* scale while the flip math still believed 224 and fired at the wrong edge. */
const ITEM_H_REM = 1.625; // px-3 py-1 row + --path-font line ≈ 26px @16
const SEPARATOR_H_REM = 0.4375; // my-1 + 1px border ≈ 7px @16
const MENU_W_REM = 14; // w-56
const HEADER_H_REM = 1.25; // pt-1.5 pb-0.5 + the 0.625rem caps line
const MENU_W_REM = 15; // w-60
const EDGE_GAP = 6; // px on purpose: a viewport-edge margin, not a UI size
/**
* The panel right-click menu. Replaces electrobun's native ContextMenu, which
* is a no-op on Linux — see ContextMenuService for the why. Emits the same
* `ctx-*` / `col:*` action strings the native menu did.
* The HTML context menu (rows, tabs, column headers, the panel source picker).
* Replaces electrobun's native ContextMenu, which is a no-op on Linux — see
* ContextMenuService for the why.
*
* Keyboard: ↑↓ Home End move one highlight shared with the mouse, Enter/Space
* pick, Esc closes, and an item's own shortcut picks it while the menu is open
* (F2 renames from an open row menu). Every key it handles stops here, so the
* window's shortcut handler never runs it a second time.
*/
@Component({
selector: 'app-context-menu',
@@ -43,15 +50,21 @@ const EDGE_GAP = 6; // px on purpose: a viewport-edge margin, not a UI size
(keydown)="onKeydown($event)"
[style.left.px]="position().x"
[style.top.px]="position().y"
class="fixed z-50 w-56 border border-border/60 bg-chrome py-1 text-foreground shadow-xl outline-none"
[style.max-height.px]="position().maxHeight"
class="fixed z-50 w-60 overflow-y-auto border border-border/60 bg-chrome py-1 text-foreground shadow-xl outline-none"
>
@for (item of req.items; track $index) {
@if (item.type === 'separator') {
<div class="my-1 border-t border-border/60"></div>
} @else if (item.type === 'header') {
<div class="truncate px-3 pt-1.5 pb-0.5 text-[0.625rem] font-medium tracking-wide text-muted-foreground uppercase">
{{ item.label }}
</div>
} @else {
<button
type="button"
role="menuitem"
tabindex="-1"
[attr.id]="'ctx-item-' + $index"
[title]="item.tooltip ?? ''"
[disabled]="!!item.disabled"
@@ -61,14 +74,22 @@ const EDGE_GAP = 6; // px on purpose: a viewport-edge margin, not a UI size
(click)="pick(item)"
class="flex w-full items-center gap-2 px-3 py-1 text-left text-(length:--path-font) disabled:pointer-events-none disabled:opacity-50"
>
<span class="w-3.5 shrink-0">
<!-- the check column: a checkmark, else the item's icon -->
<span class="grid w-4 shrink-0 place-items-center">
@if (item.checked) {
<ng-icon name="tdesignCheck" size="0.85rem" class="text-primary" />
} @else if (item.icon) {
<ng-icon
[name]="item.icon"
size="0.9rem"
[class.text-muted-foreground]="$index !== activeIndex() || !!item.disabled"
/>
}
</span>
<span class="flex-1 truncate">{{ item.label }}</span>
@if (item.accelerator) {
<span class="shrink-0 text-muted-foreground">{{ item.accelerator }}</span>
@if (item.shortcut && shortcuts.label(item.shortcut); as hint) {
<!-- soft: the row's own colour at 60%, so it turns soft green with the highlight -->
<span class="ml-4 shrink-0 opacity-60">{{ hint }}</span>
}
</button>
}
@@ -86,30 +107,37 @@ const EDGE_GAP = 6; // px on purpose: a viewport-edge margin, not a UI size
})
export class ContextMenu {
readonly menu = inject(ContextMenuService);
readonly shortcuts = inject(ShortcutsService);
private readonly focus = inject(FocusService);
private readonly menuEl = viewChild<ElementRef<HTMLDivElement>>('menuEl');
readonly activeIndex = signal(-1);
/** Click point, flipped/clamped so the menu never overflows the viewport.
* All UI metrics convert through the live root font-size; window.inner* is
* viewport CSS px, so both sides of every comparison share units. */
* A menu taller than the viewport (a long source picker) scrolls inside a
* clamped box. All UI metrics convert through the live root font-size;
* window.inner* is viewport CSS px, so both sides of every comparison share
* units. */
readonly position = computed(() => {
const req = this.menu.request();
if (!req) return { x: 0, y: 0 };
const itemH = remPx(ITEM_H_REM);
const separatorH = remPx(SEPARATOR_H_REM);
if (!req) return { x: 0, y: 0, maxHeight: 0 };
const heights = {
separator: remPx(SEPARATOR_H_REM),
header: remPx(HEADER_H_REM),
item: remPx(ITEM_H_REM),
};
const content =
req.items.reduce((sum, i) => sum + heights[i.type ?? 'item'], 0) + remPx(0.5); // py-1 ×2
const maxHeight = window.innerHeight - 2 * EDGE_GAP;
const height = Math.min(content, maxHeight);
const menuW = remPx(MENU_W_REM);
const height =
req.items.reduce((sum, i) => sum + (i.type === 'separator' ? separatorH : itemH), 0) +
remPx(0.5); // the menu's py-1 (0.25rem x2)
const x =
req.x + menuW > window.innerWidth - EDGE_GAP ? Math.max(EDGE_GAP, req.x - menuW) : req.x;
const y =
req.y + height > window.innerHeight - EDGE_GAP
? Math.max(EDGE_GAP, req.y - height)
: req.y;
return { x, y };
return { x, y, maxHeight };
});
constructor() {
@@ -117,22 +145,25 @@ export class ContextMenu {
// the viewChild signal, NOT on request(): under zoneless CD an effect can
// run before the @if has rendered the element.
effect(() => this.menuEl()?.nativeElement.focus());
// a fresh menu starts with nothing highlighted — or, opened from the
// keyboard, with its first item
effect(() => this.activeIndex.set(this.menu.request()?.initialIndex ?? -1));
}
close(): void {
if (!this.menu.request()) return;
this.menu.close();
this.activeIndex.set(-1); // a fresh menu starts with nothing highlighted
this.focus.bump();
}
pick(item: MenuItem): void {
// the keyboard path never consults the disabled attribute — guard here
if (item.disabled) return;
if (!item.action) return;
if (item.disabled || !item.action) return;
const action = item.action;
const onPick = this.menu.request()?.onPick;
this.close();
this.menu.onPick(action);
if (onPick) onPick(action);
else this.menu.emit(action);
}
/** Right-clicking the backdrop closes rather than stacking a second menu. */
@@ -143,33 +174,48 @@ export class ContextMenu {
onKeydown(event: KeyboardEvent): void {
const items = this.menu.request()?.items ?? [];
const selectable = items.map(isSelectable);
switch (event.key) {
case 'Escape':
event.preventDefault();
event.stopPropagation();
this.close();
break;
case 'ArrowDown':
event.preventDefault();
this.step(items, 1);
this.highlight(stepIndex(selectable, this.activeIndex(), 1));
break;
case 'ArrowUp':
event.preventDefault();
this.step(items, -1);
this.highlight(stepIndex(selectable, this.activeIndex(), -1));
break;
case 'Home':
this.highlight(stepIndex(selectable, -1, 1));
break;
case 'End':
this.highlight(stepIndex(selectable, -1, -1));
break;
case 'Enter':
case ' ': {
event.preventDefault();
const item = items[this.activeIndex()];
if (item) this.pick(item);
break;
}
case 'Tab':
// focus stays on the menu: the items are not Tab stops
break;
default: {
// an item's own shortcut picks it, as in a native menu
const hit = items.find(
(i) => isSelectable(i) && i.shortcut && this.shortcuts.matches(i.shortcut, event),
);
if (!hit) return; // not ours: let it bubble
this.pick(hit);
}
}
event.preventDefault();
event.stopPropagation();
}
/** Move the highlight by one selectable item (see stepIndex). */
private step(items: MenuItem[], delta: 1 | -1): void {
const selectable = items.map((i) => i.type !== 'separator' && !i.disabled);
this.activeIndex.set(stepIndex(selectable, this.activeIndex(), delta));
/** Move the highlight and keep it in view (the menu may scroll). */
private highlight(index: number): void {
this.activeIndex.set(index);
document.getElementById(`ctx-item-${index}`)?.scrollIntoView({ block: 'nearest' });
}
}
@@ -1,6 +1,16 @@
import { Component, computed, inject, input, signal } from '@angular/core';
import {
Component,
ElementRef,
afterNextRender,
computed,
inject,
input,
signal,
viewChild,
} from '@angular/core';
import { I18nService } from '@core/i18n.service';
import { DialogsService, type ChmodRequest } from '@core/dialogs.service';
import { cycleFocus } from '@core/focus-cycle';
import { FocusService } from '@core/focus.service';
const ROLES = ['roleOwner', 'roleGroup', 'roleOthers'] as const;
@@ -11,9 +21,12 @@ const PERMS = ['r', 'w', 'x'] as const;
template: `
<div class="fixed inset-0 z-40 grid place-items-center bg-black/40" (mousedown)="cancel()">
<div
role="dialog"
aria-modal="true"
[attr.aria-label]="i18n.t('dialogs.chmodTitle')"
class="w-80 border border-border bg-card p-4 text-card-foreground shadow-xl"
(mousedown)="$event.stopPropagation()"
(keydown.escape)="cancel()"
(keydown)="onKeydown($event)"
>
<h2 class="text-sm font-semibold">{{ i18n.t('dialogs.chmodTitle') }}</h2>
<p class="mt-1 truncate text-xs text-muted-foreground">{{ targetLabel() }}</p>
@@ -49,6 +62,7 @@ const PERMS = ['r', 'w', 'x'] as const;
<div class="mt-3 flex items-center gap-2">
<label class="text-xs text-muted-foreground">{{ i18n.t('dialogs.octal') }}</label>
<input
#octalBox
[value]="octal()"
(input)="setOctal($any($event.target).value)"
maxlength="4"
@@ -84,6 +98,32 @@ export class ChmodDialog {
private readonly dialogs = inject(DialogsService);
private readonly focus = inject(FocusService);
private readonly octalBox = viewChild.required<ElementRef<HTMLInputElement>>('octalBox');
constructor() {
// typing the octal is the fast path; the checkboxes are a Tab away
afterNextRender(() => {
const el = this.octalBox().nativeElement;
el.focus();
el.select();
});
}
/** Esc cancels (and stops here); Tab stays inside; Enter applies — except on
* a button, which Enter clicks natively, and mid IME composition. */
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.cancel();
} else if (event.key === 'Enter') {
if (event.isComposing || (event.target as HTMLElement).closest('button')) return;
event.preventDefault();
this.submit();
} else {
cycleFocus(event.currentTarget as Element, event);
}
}
// mode is initialized lazily from the request on first read
private readonly modeOverride = signal<number | null>(null);
@@ -1,6 +1,7 @@
import { Component, ElementRef, afterNextRender, inject, input, viewChild } from '@angular/core';
import { I18nService } from '@core/i18n.service';
import { DialogsService, type ConfirmRequest } from '@core/dialogs.service';
import { cycleFocus } from '@core/focus-cycle';
import { FocusService } from '@core/focus.service';
@Component({
@@ -8,9 +9,12 @@ import { FocusService } from '@core/focus.service';
template: `
<div class="fixed inset-0 z-40 grid place-items-center bg-black/40" (mousedown)="cancel()">
<div
role="dialog"
aria-modal="true"
[attr.aria-label]="request().title"
class="w-96 border border-border bg-card p-4 text-card-foreground shadow-xl"
(mousedown)="$event.stopPropagation()"
(keydown.escape)="cancel()"
(keydown)="onKeydown($event)"
>
<h2 class="text-sm font-semibold">{{ request().title }}</h2>
<p class="mt-2 text-xs text-muted-foreground">{{ request().body }}</p>
@@ -49,6 +53,17 @@ export class ConfirmDialog {
afterNextRender(() => this.confirmBtn().nativeElement.focus());
}
/** Esc cancels (and stops here — see PromptDialog); Tab stays inside. */
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.cancel();
} else {
cycleFocus(event.currentTarget as Element, event);
}
}
submit(): void {
const req = this.request();
this.close();
@@ -1,7 +1,7 @@
import {
Component,
ElementRef,
afterNextRender,
afterRenderEffect,
computed,
inject,
input,
@@ -10,6 +10,7 @@ import {
import { NgIcon } from '@ng-icons/core';
import { I18nService } from '@core/i18n.service';
import { DialogsService, type OverwriteChoice, type OverwriteRequest } from '@core/dialogs.service';
import { cycleFocus } from '@core/focus-cycle';
import { FocusService } from '@core/focus.service';
@Component({
@@ -18,9 +19,11 @@ import { FocusService } from '@core/focus.service';
template: `
<div
class="fixed inset-0 z-40 grid place-items-center bg-black/40"
(keydown.escape)="pick('cancel')"
(keydown)="onKeydown($event)"
>
<div
role="dialog"
aria-modal="true"
class="w-[26rem] border border-border bg-card p-4 text-card-foreground shadow-xl"
>
<div class="flex items-start justify-between gap-2">
@@ -127,7 +130,23 @@ export class OverwriteDialog {
private readonly primaryBtn = viewChild.required<ElementRef<HTMLButtonElement>>('primaryBtn');
constructor() {
afterNextRender(() => this.primaryBtn().nativeElement.focus());
// per QUESTION, not per component: a run of collisions reuses this one
// instance (the signal goes null → next inside one change detection)
afterRenderEffect(() => {
this.request();
this.primaryBtn().nativeElement.focus();
});
}
/** Esc cancels the whole run (and stops here); Tab stays inside. */
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.pick('cancel');
} else {
cycleFocus(event.currentTarget as Element, event);
}
}
readonly isDir = computed(() => this.request().srcEntry.type === 'dir');
@@ -9,6 +9,7 @@ import {
} from '@angular/core';
import { I18nService } from '@core/i18n.service';
import { DialogsService, type PromptRequest } from '@core/dialogs.service';
import { cycleFocus } from '@core/focus-cycle';
import { FocusService } from '@core/focus.service';
@Component({
@@ -16,16 +17,19 @@ import { FocusService } from '@core/focus.service';
template: `
<div class="fixed inset-0 z-40 grid place-items-center bg-black/40" (mousedown)="cancel()">
<div
role="dialog"
aria-modal="true"
[attr.aria-label]="request().title"
class="w-96 border border-border bg-card p-4 text-card-foreground shadow-xl"
(mousedown)="$event.stopPropagation()"
(keydown)="onKeydown($event)"
>
<h2 class="text-sm font-semibold">{{ request().title }}</h2>
<input
#box
[value]="value()"
(input)="value.set($any($event.target).value)"
(keydown.enter)="submit()"
(keydown.escape)="cancel()"
(keydown.enter)="onEnter($event)"
[placeholder]="request().placeholder ?? ''"
spellcheck="false"
class="mt-3 h-8 w-full border border-input bg-transparent px-2 text-sm outline-none focus:ring-2 focus:ring-ring"
@@ -67,6 +71,25 @@ export class PromptDialog {
});
}
/** Esc anywhere in the dialog cancels; Tab stays inside it. Esc stops here:
* a window-level Escape (the connection manager closes on it) must not see
* the same key. */
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.cancel();
} else {
cycleFocus(event.currentTarget as Element, event);
}
}
/** Enter submits — but not the Enter that commits an IME candidate. */
onEnter(event: Event): void {
if ((event as KeyboardEvent).isComposing) return;
this.submit();
}
submit(): void {
const value = this.value().trim();
if (!value) return;
@@ -28,7 +28,7 @@
<div class="flex-1"></div>
<button
(click)="toggleWrap()"
[title]="i18n.t('editor.wrapHint', { alt: altLabel })"
[title]="shortcuts.tip(i18n.t('editor.wrapHint'), 'toggle-wrap')"
class="px-2 py-1 text-[0.6875rem] electrobun-webkit-app-region-no-drag hover:bg-accent"
[class.bg-accent]="wrap()"
[class.text-foreground]="wrap()"
@@ -38,7 +38,7 @@
</button>
<button
(click)="openFind()"
[title]="i18n.t('editor.findHint', { mod: modLabel })"
[title]="shortcuts.tip(i18n.t('editor.findHint'), 'find')"
class="grid size-6 place-items-center text-muted-foreground electrobun-webkit-app-region-no-drag hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignSearch" size="0.85rem" />
@@ -66,14 +66,14 @@
</span>
<button
(click)="findStep(-1)"
[title]="i18n.t('editor.prevMatch')"
[title]="shortcuts.tipFixed(i18n.t('editor.prevMatch'), 'Shift+Enter')"
class="grid size-5 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignChevronUp" size="0.8rem" />
</button>
<button
(click)="findStep(1)"
[title]="i18n.t('editor.nextMatch')"
[title]="shortcuts.tipFixed(i18n.t('editor.nextMatch'), 'Enter')"
class="grid size-5 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignChevronDown" size="0.8rem" />
@@ -141,7 +141,7 @@
</div>
<footer class="flex shrink-0 items-center gap-2 border-t border-border bg-chrome px-4 py-2">
<span class="text-[0.6875rem] text-muted-foreground">{{ i18n.t('editor.shortcuts', { mod: modLabel }) }}</span>
<span class="text-[0.6875rem] text-muted-foreground">{{ footerHint() }}</span>
<span class="text-[0.6875rem] text-muted-foreground">·</span>
<span class="text-[0.6875rem] tabular-nums text-muted-foreground">
{{ i18n.t('editor.lines', { count: lineCount() }) }}
@@ -171,6 +171,10 @@
@if (closePrompt()) {
<div class="fixed inset-0 z-40 grid place-items-center bg-black/40" (mousedown)="cancelClose()">
<div
#prompt
role="dialog"
aria-modal="true"
[attr.aria-label]="i18n.t('editor.saveChangesTitle', { name: ctx.name })"
class="w-96 border border-border bg-card p-4 text-card-foreground shadow-xl"
(mousedown)="$event.stopPropagation()"
>
@@ -193,6 +197,7 @@
{{ i18n.t('common.cancel') }}
</button>
<button
#promptSave
(click)="saveAndClose()"
[disabled]="saving()"
class="bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50"
@@ -2,7 +2,9 @@ import {
Component,
DOCUMENT,
ElementRef,
Injector,
afterNextRender,
afterRenderEffect,
computed,
effect,
inject,
@@ -11,7 +13,8 @@ import {
} from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import { I18nService } from '@core/i18n.service';
import { ALT_LABEL, blockNativeContextMenu, EDITOR_CONTEXT, IS_MAC_CHROME, MOD_LABEL } from '@core/platform';
import { cycleFocus } from '@core/focus-cycle';
import { blockNativeContextMenu, blockReloadKeys, EDITOR_CONTEXT, IS_MAC_CHROME } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
@@ -43,8 +46,6 @@ export class EditorWindow {
readonly i18n = inject(I18nService);
readonly ctx = EDITOR_CONTEXT;
readonly isMacChrome = IS_MAC_CHROME;
readonly modLabel = MOD_LABEL;
readonly altLabel = ALT_LABEL;
readonly loading = signal(true);
readonly loadError = signal<string | null>(null);
@@ -92,6 +93,9 @@ export class EditorWindow {
);
private readonly box = viewChild<ElementRef<HTMLTextAreaElement>>('box');
private readonly prompt = viewChild<ElementRef<HTMLElement>>('prompt');
private readonly promptSave = viewChild<ElementRef<HTMLButtonElement>>('promptSave');
private readonly injector = inject(Injector);
private readonly gutter = viewChild<ElementRef<HTMLElement>>('gutter');
private readonly findBox = viewChild<ElementRef<HTMLInputElement>>('findBox');
private cachedCharWidth = 0;
@@ -102,7 +106,22 @@ export class EditorWindow {
// injected for its side effects: fetches settings and applies theme/accent/
// text-size data attributes to this window's document root
private readonly settings = inject(SettingsService);
private readonly shortcuts = inject(ShortcutsService);
readonly shortcuts = inject(ShortcutsService);
/** "⌘S save · ⌘F find · ⌘W close" — the keys from the live keymap, so a remap
* shows here too; an unbound command drops out. */
readonly footerHint = computed(() =>
(
[
['save', 'editor.verbs.save'],
['find', 'editor.verbs.find'],
['close-window', 'editor.verbs.close'],
] as const
)
.filter(([id]) => this.shortcuts.label(id))
.map(([id, verb]) => `${this.shortcuts.label(id)} ${this.i18n.t(verb)}`)
.join(' · '),
);
private draftTimer: ReturnType<typeof setTimeout> | null = null;
private lastSentDirty = false;
@@ -122,6 +141,11 @@ export class EditorWindow {
});
afterNextRender(() => void this.load(ctx.sessionId, ctx.path));
// the unsaved-changes prompt takes the keyboard, so keys can't edit the
// hidden text behind it: focus its Save button whenever it shows
afterRenderEffect(() => {
if (this.closePrompt()) this.promptSave()?.nativeElement.focus();
});
}
private async load(sessionId: string, path: string): Promise<void> {
@@ -134,7 +158,8 @@ export class EditorWindow {
this.savedContent.set(res.content);
this.text.set(res.content);
this.loading.set(false);
queueMicrotask(() => this.box()?.nativeElement.focus());
// after the render that creates the textarea — a microtask runs before it
afterNextRender(() => this.box()?.nativeElement.focus(), { injector: this.injector });
}
blockContextMenu(event: Event): void {
@@ -168,11 +193,14 @@ export class EditorWindow {
}
this.findOpen.set(true);
this.activeMatch.set(0);
queueMicrotask(() => {
afterNextRender(
() => {
const input = this.findBox()?.nativeElement;
input?.focus();
input?.select();
});
},
{ injector: this.injector },
);
}
closeFind(): void {
@@ -197,6 +225,29 @@ export class EditorWindow {
this.goTo((this.activeMatch() + delta + count) % count);
}
/** ⌘G / ⇧⌘G (F3 / ⇧F3): the next / previous match from the caret, find bar
* open or not — the query survives closing it. With no query yet, open the bar. */
findNext(delta: 1 | -1): void {
if (!this.findQuery()) {
this.openFind();
return;
}
const list = this.matches();
if (!list.length) return;
const el = this.box()?.nativeElement;
let index = -1;
if (delta > 0) {
const caret = el?.selectionEnd ?? 0;
index = list.findIndex((start) => start >= caret);
if (index < 0) index = 0;
} else {
const caret = el?.selectionStart ?? 0;
for (let i = list.length - 1; i >= 0 && index < 0; i--) if (list[i] < caret) index = i;
if (index < 0) index = list.length - 1;
}
this.goTo(index);
}
onFindKeydown(event: KeyboardEvent): void {
if (event.key === 'Enter') {
event.preventDefault();
@@ -319,55 +370,78 @@ export class EditorWindow {
// ---- keyboard ----
onKeydown(event: KeyboardEvent): void {
// Chord shortcuts resolve through the shared keymap (ShortcutsService);
// Escape and Tab stay below because their meaning is THIS window's state
// (close prompt up? find bar open? caret in the textarea?), not a binding.
const match = this.shortcuts.resolve(event, 'editor');
if (match) {
// scale keys must not fire while typing — but the editor's own chords
// (save/find/wrap) are WANTED mid-typing, so the guard is per-shortcut
if (match.id.startsWith('scale-') && this.shortcuts.isTypingTarget(event)) return;
this.handleKey(event);
blockReloadKeys(event); // F5 / Ctrl+R must not reload over unsaved text
}
/**
* The editor's keys come from the shared keymap (`editor` scope); they fire
* mid-typing because they are all chords or F-keys. Escape and Tab stay here:
* their meaning is this window's state (prompt up? find bar open?).
*/
private handleKey(event: KeyboardEvent): void {
if (event.defaultPrevented) return;
const id = this.shortcuts.claim(event, 'editor');
if (this.closePrompt()) {
// the unsaved-changes prompt owns the keyboard: ⌘S is its Save, Esc its
// Cancel, Tab walks its buttons; other commands wait
if (id === 'save') void this.saveAndClose();
else if (id === 'scale-up' || id === 'scale-down' || id === 'scale-reset') this.scale(id);
else if (!id && event.key === 'Escape') {
event.preventDefault();
switch (match.id) {
case 'save':
void this.save();
break;
case 'find':
this.openFind();
break;
case 'close-window':
// reaches us on Windows/Linux; on macOS the app menu intercepts ⌘W
// and bun routes it back as editorCloseRequest
this.requestClose();
break;
case 'toggle-wrap':
this.toggleWrap();
break;
case 'scale-up':
this.settings.setUiScale(this.settings.uiScale() + 0.1);
break;
case 'scale-down':
this.settings.setUiScale(this.settings.uiScale() - 0.1);
break;
case 'scale-reset':
this.settings.setUiScale(1);
break;
this.cancelClose();
} else if (!id) {
const prompt = this.prompt()?.nativeElement;
if (prompt) cycleFocus(prompt, event);
}
return;
}
if (event.key === 'Escape' && this.closePrompt()) {
event.preventDefault();
this.cancelClose();
} else if (event.key === 'Escape' && this.findOpen()) {
switch (id) {
case 'save':
void this.save();
return;
case 'find':
this.openFind();
return;
case 'find-next':
this.findNext(1);
return;
case 'find-prev':
this.findNext(-1);
return;
case 'close-window':
this.requestClose();
return;
case 'toggle-wrap':
this.toggleWrap();
return;
case 'scale-up':
case 'scale-down':
case 'scale-reset':
this.scale(id);
return;
}
if (event.key === 'Escape' && this.findOpen()) {
event.preventDefault();
this.closeFind();
} else if (event.key === 'Tab' && event.target === this.box()?.nativeElement) {
} else if (
event.key === 'Tab' &&
!event.metaKey &&
!event.ctrlKey &&
!event.altKey &&
event.target === this.box()?.nativeElement
) {
// keep Tab as an input character inside the editor
event.preventDefault();
this.insertTab();
}
}
private scale(id: 'scale-up' | 'scale-down' | 'scale-reset'): void {
if (id === 'scale-reset') this.settings.setUiScale(1);
else this.settings.setUiScale(this.settings.uiScale() + (id === 'scale-up' ? 0.1 : -0.1));
}
private insertTab(): void {
const el = this.box()!.nativeElement;
// execCommand keeps the native undo stack intact where supported
@@ -4,9 +4,10 @@
[style.box-shadow]="activeMarker()"
>
<button
(click)="toggleMenu()"
#sourceBtn
(click)="openSourcePicker(false)"
class="flex min-w-0 items-center gap-1.5 px-2 py-1 text-(length:--path-font) font-medium hover:bg-accent"
[title]="i18n.t('panel.choosePanel')"
[title]="shortcuts.tip(i18n.t('panel.choosePanel'), 'source-picker')"
>
@if (panel().connecting()) {
<ng-icon name="tdesignLoading" class="shrink-0 animate-spin text-primary" size="var(--action-icon)" />
@@ -29,8 +30,8 @@
<!-- panel actions: act on THIS panel. Frequent/destructive verbs grow text
labels when the panel is wide enough (container query). -->
<button
(click)="copyToOther()"
[title]="side() === 'left' ? i18n.t('panel.copyToRight') : i18n.t('panel.copyToLeft')"
(click)="run('send')"
[title]="shortcuts.tip(side() === 'left' ? i18n.t('panel.copyToRight') : i18n.t('panel.copyToLeft'), 'send')"
class="flex h-(--action-h) shrink-0 items-center px-1 text-muted-foreground hover:bg-accent hover:text-primary"
>
<ng-icon [name]="copyIcon()" size="var(--action-icon)" />
@@ -38,7 +39,7 @@
</button>
<button
(click)="run('edit')"
[title]="i18n.t('panel.editFile')"
[title]="shortcuts.tip(i18n.t('panel.editFile'), 'edit')"
class="flex h-(--action-h) shrink-0 items-center px-1 text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignFile1" size="var(--action-icon)" />
@@ -46,22 +47,22 @@
</button>
<button
(click)="run('rename')"
[title]="i18n.t('panel.rename')"
[title]="shortcuts.tip(i18n.t('panel.rename'), 'rename')"
class="flex h-(--action-h) shrink-0 items-center px-1 text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignEdit" size="var(--action-icon)" />
<span class="ml-1 hidden text-(length:--action-font) @[30rem]:inline">{{ i18n.t('common.rename') }}</span>
</button>
<button
(click)="run('mkdir')"
[title]="i18n.t('panel.newFolder')"
(click)="run('new-folder')"
[title]="shortcuts.tip(i18n.t('panel.newFolder'), 'new-folder')"
class="grid size-(--action-h) shrink-0 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignFolderAdd" size="var(--action-icon)" />
</button>
<button
(click)="run('createFile')"
[title]="i18n.t('panel.newFile')"
(click)="run('new-file')"
[title]="shortcuts.tip(i18n.t('panel.newFile'), 'new-file')"
class="grid size-(--action-h) shrink-0 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignFileAdd" size="var(--action-icon)" />
@@ -69,7 +70,7 @@
@if (chmodAvailable()) {
<button
(click)="run('chmod')"
[title]="i18n.t('panel.permissions')"
[title]="shortcuts.tip(i18n.t('panel.permissions'), 'chmod')"
class="grid size-(--action-h) shrink-0 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignLockOn" size="var(--action-icon)" />
@@ -77,87 +78,13 @@
}
<button
(click)="run('delete')"
[title]="i18n.t('panel.deleteHint')"
[title]="shortcuts.tip(i18n.t('common.delete'), 'delete')"
class="flex h-(--action-h) shrink-0 items-center px-1 text-muted-foreground hover:bg-accent hover:text-destructive"
>
<ng-icon name="tdesignDelete" size="var(--action-icon)" />
<span class="ml-1 hidden text-(length:--action-font) @[30rem]:inline">{{ i18n.t('common.delete') }}</span>
</button>
@if (menuOpen()) {
<div class="fixed inset-0 z-20" (click)="menuOpen.set(false)"></div>
<div
class="absolute top-full left-2 z-30 mt-1 max-h-80 w-64 overflow-y-auto border border-border bg-card py-1 text-card-foreground shadow-xl"
>
<button
(click)="pickLocal()"
class="flex w-full items-center gap-2 px-3 py-1.5 text-left text-(length:--path-font) hover:bg-accent"
>
<ng-icon name="tdesignHardDrive" size="var(--action-icon)" class="shrink-0 text-muted-foreground" />
<span class="flex-1">{{ i18n.t('common.local') }}</span>
@if (!isRemote()) {
<ng-icon name="tdesignCheck" size="0.85rem" class="shrink-0 text-primary" />
}
</button>
<!-- Windows drive roots (empty list elsewhere) -->
@for (drive of drives(); track drive) {
<button
(click)="pickDrive(drive)"
class="flex w-full items-center gap-2 py-1.5 pr-3 pl-6 text-left text-(length:--path-font) hover:bg-accent"
>
<ng-icon name="tdesignHardDrive" size="var(--action-icon)" class="shrink-0 text-muted-foreground" />
<span class="flex-1 font-mono">{{ drive }}</span>
</button>
}
@if (connections.grouped().loose.length || connections.grouped().stacks.length) {
<div class="my-1 border-t border-border"></div>
}
@for (connection of connections.grouped().loose; track connection.id) {
<button
(click)="pickConnection(connection)"
class="flex w-full items-center gap-2 px-3 py-1.5 text-left text-(length:--path-font) hover:bg-accent"
>
<ng-icon name="tdesignServer" size="var(--action-icon)" class="shrink-0 text-muted-foreground" />
<span class="flex-1 truncate">{{ connection.name }}</span>
</button>
}
@for (group of connections.grouped().stacks; track group.stack.id) {
<div class="px-3 pt-1.5 pb-0.5 text-[0.625rem] font-medium tracking-wide text-muted-foreground uppercase">
{{ group.stack.name }}
</div>
@for (connection of group.connections; track connection.id) {
<button
(click)="pickConnection(connection)"
class="flex w-full items-center gap-2 py-1.5 pr-3 pl-5 text-left text-(length:--path-font) hover:bg-accent"
>
<ng-icon name="tdesignServer" size="var(--action-icon)" class="shrink-0 text-muted-foreground" />
<span class="flex-1 truncate">{{ connection.name }}</span>
</button>
}
}
@if (connections.sshHosts().length) {
<div class="my-1 border-t border-border"></div>
<div class="px-3 pt-1.5 pb-0.5 text-[0.625rem] font-medium tracking-wide text-muted-foreground uppercase">
~/.ssh/config
</div>
@for (host of connections.sshHosts(); track host.name) {
<button
(click)="pickSshHost(host)"
[disabled]="host.unsupported"
[title]="sshHostTitle(host)"
class="flex w-full items-center gap-2 py-1.5 pr-3 pl-5 text-left text-(length:--path-font) hover:bg-accent disabled:opacity-60 disabled:hover:bg-transparent"
>
<ng-icon name="tdesignServer" size="var(--action-icon)" class="shrink-0 text-muted-foreground" />
<span class="flex-1 truncate">{{ host.name }}</span>
</button>
}
}
</div>
}
</div>
<!-- path bar -->
@@ -165,25 +92,28 @@
<button
(click)="panel().up()"
[disabled]="blocked()"
[title]="i18n.t('panel.parentDir')"
[title]="shortcuts.tip(i18n.t('panel.parentDir'), 'parent')"
class="grid size-(--path-ctl-h) shrink-0 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent"
>
<ng-icon name="tdesignArrowUp" size="1rem" />
</button>
<!-- no blanket stopPropagation: the window handler lets only ⌘/Ctrl chords
through from a text field, and its WebView2 reload guard must see F5 -->
<input
#pathBox
[value]="pathDraft()"
(input)="pathDraft.set($any($event.target).value)"
(keydown.enter)="commitPath()"
(keydown.escape)="resetPath()"
(keydown)="$event.stopPropagation()"
[disabled]="blocked()"
[title]="shortcuts.tip(i18n.t('keys.focus-path'), 'focus-path')"
spellcheck="false"
class="h-(--path-ctl-h) min-w-0 flex-1 border border-input bg-transparent px-2 font-mono text-(length:--path-font) outline-none focus:ring-2 focus:ring-ring disabled:opacity-50"
/>
<button
(click)="panel().refresh()"
(click)="run('refresh')"
[disabled]="blocked()"
[title]="i18n.t('panel.refresh')"
[title]="shortcuts.tip(i18n.t('panel.refresh'), 'refresh')"
class="grid size-(--path-ctl-h) shrink-0 place-items-center text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent"
>
@if (panel().loading()) {
@@ -200,7 +130,11 @@
[style.grid-template-columns]="gridTemplate()"
class="grid border-b border-border bg-toolbar-3 text-[0.6875rem] font-medium text-muted-foreground"
>
<button class="px-2 py-1 text-left hover:text-foreground" (click)="panel().toggleSort('name')">
<button
class="px-2 py-1 text-left hover:text-foreground"
[title]="sortTip('name')"
(click)="panel().toggleSort('name')"
>
{{ i18n.t('columns.name') }} {{ sortIndicator('name') }}
</button>
@for (col of visibleColumns(); track col.key) {
@@ -208,6 +142,7 @@
class="px-2 py-1 hover:text-foreground"
[class.text-right]="col.key === 'size'"
[class.text-left]="col.key !== 'size'"
[title]="sortTip(col.key)"
(click)="panel().toggleSort(col.key)"
>
{{ i18n.t('columns.' + col.key) }} {{ sortIndicator(col.key) }}
+250 -112
View File
@@ -9,20 +9,21 @@ import {
viewChild,
} from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import { isRepeatable } from '@shared/keymap';
import { I18nService } from '@core/i18n.service';
import type { ColumnKey, FileEntry, SavedConnection, SshConfigHost } from '@shared/types';
import type { ColumnKey, FileEntry, SshConfigHost } from '@shared/types';
import { ConnectionsService } from '@core/connections.service';
import { ContextMenuService } from '@core/context-menu.service';
import { ContextMenuService, type MenuItem } from '@core/context-menu.service';
import { DialogsService } from '@core/dialogs.service';
import { FileActionsService } from '@core/file-actions.service';
import { FileActionsService, type FileCommand, type FileTarget } from '@core/file-actions.service';
import { fileGlyph, fileIconClass, fileKindKey } from '@core/file-icons';
import { formatMode } from '@core/format';
import { remPx } from '@core/metrics';
import { PanelsService, type Side, type SortKey } from '@core/panels.service';
import { IS_WINDOWS } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
import { TransfersService } from '@core/transfers.service';
import { ShortcutsService, type ShortcutId } from '@core/shortcuts.service';
/** Optional columns in fixed display order, with their track widths. */
const COLUMN_DEFS: { key: ColumnKey; label: string; width: string }[] = [
@@ -34,6 +35,33 @@ const COLUMN_DEFS: { key: ColumnKey; label: string; width: string }[] = [
{ key: 'group', label: 'Group', width: '6rem' },
];
/** Rows a PageUp / PageDown jumps. */
const PAGE = 20;
/** Cursor movements: with Shift they extend the selection instead. */
const MOVES = new Set<ShortcutId>([
'cursor-up',
'cursor-down',
'page-up',
'page-down',
'cursor-first',
'cursor-last',
]);
/** The same keydown with Shift lifted — what a Shift+movement spells underneath. */
function withoutShift(event: KeyboardEvent) {
return {
key: event.key,
code: event.code,
metaKey: event.metaKey,
ctrlKey: event.ctrlKey,
altKey: event.altKey,
shiftKey: false,
target: event.target,
getModifierState: (key: string) => event.getModifierState(key),
};
}
@Component({
selector: 'app-file-panel',
imports: [NgIcon],
@@ -46,12 +74,11 @@ export class FilePanel {
readonly panels = inject(PanelsService);
readonly actions = inject(FileActionsService);
readonly transfers = inject(TransfersService);
readonly connections = inject(ConnectionsService);
readonly dialogs = inject(DialogsService);
readonly shortcuts = inject(ShortcutsService);
private readonly menu = inject(ContextMenuService);
private readonly settings = inject(SettingsService);
private readonly shortcuts = inject(ShortcutsService);
private readonly rpc = inject(RpcService);
readonly panel = computed(() => this.panels.get(this.side()));
readonly isActive = computed(() => this.panels.activeSide() === this.side());
@@ -67,13 +94,14 @@ export class FilePanel {
readonly copyIcon = computed(() => (this.side() === 'left' ? 'tdesignArrowRight' : 'tdesignArrowLeft'));
readonly pathDraft = signal('');
readonly menuOpen = signal(false);
/** Windows drive roots for the source picker; always empty elsewhere. */
readonly drives = signal<string[]>([]);
/** chmod on Windows local files only flips the read-only bit — hide it. */
readonly chmodAvailable = computed(() => !(IS_WINDOWS && !this.isRemote()));
private readonly listEl = viewChild.required<ElementRef<HTMLDivElement>>('list');
private readonly sourceBtn = viewChild.required<ElementRef<HTMLButtonElement>>('sourceBtn');
private readonly pathBox = viewChild.required<ElementRef<HTMLInputElement>>('pathBox');
private lastClickedIndex = 0;
// locale-reactive wrappers: reading i18n.locale() inside makes the file-list
@@ -95,17 +123,6 @@ export class FilePanel {
['minmax(0,1fr)', ...this.visibleColumns().map((c) => c.width)].join(' '),
);
headerContextMenu(event: MouseEvent): void {
event.preventDefault();
this.menu.open(event, this.menu.columnItems(this.settings.columns()));
}
pickDrive(drive: string): void {
this.menuOpen.set(false);
this.activate();
void this.panel().load(drive);
}
constructor() {
if (IS_WINDOWS && this.rpc.available) {
void this.rpc.request.listDrives({}).then((res) => {
@@ -114,11 +131,23 @@ export class FilePanel {
}
// keep the editable path bar in sync with the actual cwd
effect(() => this.pathDraft.set(this.panel().cwd()));
// focus follows the active side (Tab switches panels, dialogs refocus on close)
// focus follows the active side (Tab switches panels, dialogs and menus
// refocus on close) — but never while a dialog or menu is up: a run of
// overwrite questions reuses one dialog, and stealing focus back to the
// list behind it would hand Enter and Delete to the panel
effect(() => {
this.panels.focusTick();
if (this.isActive()) this.listEl().nativeElement.focus();
if (this.isActive() && !this.dialogs.anyOpen && !this.menu.request()) {
this.listEl().nativeElement.focus();
}
});
// keys that land on <body> (a click dropped focus) still reach this list
effect(() => this.panels.registerListKeys(this.side(), (event) => this.onKeydown(event)));
}
headerContextMenu(event: MouseEvent): void {
event.preventDefault();
this.menu.open(event, this.menu.columnItems(this.settings.columns()));
}
activate(): void {
@@ -129,38 +158,95 @@ export class FilePanel {
this.panels.cancelConnect(this.side());
}
copyToOther(): void {
/** A toolbar button: the same command the keyboard and the menus run. */
run(id: FileCommand): void {
if (this.blocked()) return;
this.activate();
void this.transfers.copyToOtherPanel(this.side());
this.actions.run(id, this.cursorTarget());
}
run(action: 'edit' | 'rename' | 'mkdir' | 'createFile' | 'chmod' | 'delete'): void {
if (this.blocked()) return;
private cursorTarget(): FileTarget {
const panel = this.panel();
return { side: this.side(), panel, entry: panel.sorted()[panel.cursor()] ?? null };
}
// ---- source picker: what this panel shows ----
/** The session button's menu (also ⌘K): Local, drives, saved connections by
* stack, ~/.ssh/config hosts — through the shared context menu, so it gets
* the same keyboard handling and look. */
async openSourcePicker(keyboard: boolean): Promise<void> {
this.activate();
void this.actions[action](this.panel());
// re-read ~/.ssh/config on each open so external edits show up — BEFORE
// the items are built, the menu holds a snapshot
await this.connections.reloadSshHosts();
const rect = this.sourceBtn().nativeElement.getBoundingClientRect();
this.menu.open({ clientX: rect.left, clientY: rect.bottom + remPx(0.25) }, this.sourceItems(), {
keyboard,
onPick: (action) => this.pickSource(action),
});
}
pickLocal(): void {
this.menuOpen.set(false);
private sourceItems(): MenuItem[] {
const items: MenuItem[] = [
{
label: this.i18n.t('common.local'),
action: 'local',
icon: 'tdesignHardDrive',
checked: !this.isRemote(),
},
];
// Windows drive roots (empty list elsewhere)
for (const drive of this.drives()) {
items.push({ label: drive, action: `drive:${drive}`, icon: 'tdesignHardDrive' });
}
const { loose, stacks } = this.connections.grouped();
if (loose.length || stacks.length) items.push({ type: 'separator' });
const server = (connection: { id: string; name: string }): MenuItem => ({
label: connection.name,
action: `conn:${connection.id}`,
icon: 'tdesignServer',
});
items.push(...loose.map(server));
for (const group of stacks) {
items.push({ type: 'header', label: group.stack.name }, ...group.connections.map(server));
}
const hosts = this.connections.sshHosts();
if (hosts.length) {
items.push({ type: 'separator' }, { type: 'header', label: this.i18n.t('panel.sshConfig') });
for (const host of hosts) {
items.push({
label: host.name,
action: `ssh:${host.name}`,
icon: 'tdesignServer',
disabled: !!host.unsupported,
tooltip: this.sshHostTitle(host),
});
}
}
return items;
}
private pickSource(action: string): void {
const [kind, ...rest] = action.split(':');
const value = rest.join(':'); // a drive root ("C:\") has a colon of its own
this.activate();
if (kind === 'local') {
void this.panels.disconnectPanel(this.side());
}
pickConnection(connection: SavedConnection): void {
this.menuOpen.set(false);
this.activate();
} else if (kind === 'drive') {
void this.panel().load(value);
} else if (kind === 'conn') {
const connection = this.connections.connections().find((c) => c.id === value);
if (connection) {
void this.panels.connectPanel(this.side(), connection, connection.name, connection.localDir);
}
toggleMenu(): void {
this.menuOpen.set(!this.menuOpen());
// re-read ~/.ssh/config on each open so external edits show up
if (this.menuOpen()) void this.connections.reloadSshHosts();
} else if (kind === 'ssh') {
const host = this.connections.sshHosts().find((h) => h.name === value);
if (host) this.connectSshHost(host);
}
}
pickSshHost(host: SshConfigHost): void {
this.menuOpen.set(false);
this.activate();
private connectSshHost(host: SshConfigHost): void {
void this.panels.connectPanel(
this.side(),
{
@@ -209,6 +295,12 @@ export class FilePanel {
return this.panel().sortAsc() ? '↑' : '↓';
}
/** The sort header's tooltip: its keymap command and keys. */
sortTip(key: SortKey): string {
const id = `sort-${key}` as const;
return this.shortcuts.tip(this.i18n.t(`keys.${id}`), id);
}
commitPath(): void {
if (this.blocked()) return;
const value = this.pathDraft().trim();
@@ -221,6 +313,12 @@ export class FilePanel {
this.listEl().nativeElement.focus();
}
private focusPath(): void {
const el = this.pathBox().nativeElement;
el.focus();
el.select();
}
rowClick(event: MouseEvent, index: number): void {
if (this.blocked()) return;
this.activate();
@@ -257,105 +355,145 @@ export class FilePanel {
this.actions.openContextMenu(event, { side: this.side(), panel: this.panel(), entry: null });
}
/** ⇧F10 / Menu / ⌃↩: the cursor row's menu, under the row. The selection is
* kept — the menu's commands act on it, like the F-keys do. */
private openKeyboardMenu(): void {
const panel = this.panel();
const index = panel.cursor();
const entry = panel.sorted()[index] ?? null;
const row = this.listEl().nativeElement.querySelector<HTMLElement>(`[data-index="${index}"]`);
row?.scrollIntoView({ block: 'nearest' });
const rect = (row ?? this.listEl().nativeElement).getBoundingClientRect();
this.actions.openContextMenu(
{ clientX: rect.left + remPx(1.75), clientY: row ? rect.bottom : rect.top + remPx(0.5) },
{ side: this.side(), panel, entry },
true,
);
}
openAt(index: number): void {
if (this.blocked()) return;
const entry = this.panel().sorted()[index];
if (entry) this.panel().open(entry);
}
onKeydown(event: KeyboardEvent): void {
if (this.blocked()) return;
const panel = this.panel();
const key = event.key;
if (key === 'Tab') {
event.preventDefault();
this.panels.setActiveSide(this.panels.otherSide(this.side()));
return;
}
if (this.shortcuts.isMod(event) && key.toLowerCase() === 'a') {
event.preventDefault();
panel.selectAll();
return;
const entry = panel.sorted()[index];
if (entry) this.actions.run('open', { side: this.side(), panel, entry });
}
// type-to-filter: printable characters build the query (Space only once a
// query exists — an empty-filter Space keeps its toggle-select meaning)
if (
key.length === 1 &&
!event.metaKey &&
!event.ctrlKey &&
!event.altKey &&
(key !== ' ' || panel.filter() !== '')
) {
/**
* The list's keys, in order:
* 1. while a query is being typed, printable keys (Space too) extend it,
* Backspace trims and Esc clears it — fixed, ahead of every binding;
* 2. the `panel` keymap (Shift + a movement extends the selection);
* 3. a `main` binding (⌘T, Ctrl+Tab…) is left to bubble to App;
* 4. any other printable key starts a type-to-filter query;
* 5. Esc clears the selection.
*/
onKeydown(event: KeyboardEvent): void {
const panel = this.panel();
if (this.blocked()) {
// a busy panel takes no input — except Esc, which cancels a connect; its
// own keys are swallowed so Tab can't wander out of the list mid-load
if (event.key === 'Escape' && panel.connecting()) {
event.preventDefault();
panel.setFilter(panel.filter() + key);
this.cancelConnect();
} else if (this.shortcuts.resolve(event, 'panel')) {
event.preventDefault();
}
return;
}
const plain = !event.metaKey && !event.ctrlKey && !event.altKey;
const printable = plain && event.key.length === 1 && !event.isComposing;
if (panel.filter() !== '' && plain) {
if (printable) return this.setFilter(event, panel.filter() + event.key);
if (event.key === 'Backspace' && !event.shiftKey) return this.setFilter(event, panel.filter().slice(0, -1));
if (event.key === 'Escape') return this.setFilter(event, '');
}
const command = this.panelCommand(event);
if (command) {
event.preventDefault();
if (event.repeat && !isRepeatable(command.id)) return;
this.runKey(command.id, command.extend);
this.scrollCursorIntoView();
return;
}
if (key === 'Backspace' && panel.filter() !== '') {
if (this.shortcuts.resolve(event, 'main')) return;
if (printable && event.key !== ' ') return this.setFilter(event, event.key);
if (event.key === 'Escape' && plain && panel.selected().size) {
event.preventDefault();
panel.setFilter(panel.filter().slice(0, -1));
return;
panel.clearSelection();
}
if (key === 'Escape' && panel.filter() !== '') {
event.preventDefault();
panel.setFilter('');
return;
}
switch (key) {
case 'ArrowDown':
panel.moveCursor(1);
break;
case 'ArrowUp':
/** The panel command a keydown spells. Shift + a movement key is that
* movement extending the selection — a fixed rule, so it follows remaps. */
private panelCommand(event: KeyboardEvent): { id: ShortcutId; extend: boolean } | null {
const id = this.shortcuts.resolve(event, 'panel');
if (id) return { id, extend: false };
if (!event.shiftKey) return null;
const base = this.shortcuts.resolve(withoutShift(event), 'panel');
return base && MOVES.has(base) ? { id: base, extend: true } : null;
}
private runKey(id: ShortcutId, extend: boolean): void {
const panel = this.panel();
const from = panel.cursor();
switch (id) {
case 'cursor-up':
panel.moveCursor(-1);
break;
case 'PageDown':
panel.moveCursor(20);
case 'cursor-down':
panel.moveCursor(1);
break;
case 'PageUp':
panel.moveCursor(-20);
case 'page-up':
panel.moveCursor(-PAGE);
break;
case 'Home':
case 'page-down':
panel.moveCursor(PAGE);
break;
case 'cursor-first':
panel.cursor.set(0);
break;
case 'End':
case 'cursor-last':
panel.cursor.set(Math.max(0, panel.sorted().length - 1));
break;
case ' ':
{
const entry = panel.sorted()[panel.cursor()];
case 'toggle-select': {
const entry = panel.sorted()[from];
if (entry) panel.toggleSelect(entry.name);
panel.moveCursor(1);
return;
}
break;
case 'Enter':
this.openAt(panel.cursor());
return void event.preventDefault();
case 'Backspace':
case 'select-all':
panel.selectAll();
return;
case 'parent':
panel.up();
break;
case 'F2':
this.actions.rename(panel);
break;
case 'F4':
void this.actions.edit(panel);
break;
case 'F5':
void this.transfers.copyToOtherPanel(this.side());
break;
case 'F7':
this.actions.mkdir(panel);
break;
case 'F8':
case 'Delete':
this.actions.delete(panel);
break;
return;
case 'switch-panel':
this.panels.setActiveSide(this.panels.otherSide(this.side()));
return;
case 'row-menu':
this.openKeyboardMenu();
return;
case 'focus-path':
this.focusPath();
return;
case 'source-picker':
void this.openSourcePicker(true);
return;
default:
return; // let unhandled keys through
// every other panel-scope command acts on files (keymap.ts)
this.actions.run(id as FileCommand, this.cursorTarget());
return;
}
// Shift + movement: select every row the cursor passed over
if (extend) panel.selectRange(from, panel.cursor());
}
private setFilter(event: KeyboardEvent, query: string): void {
event.preventDefault();
this.panel().setFilter(query);
this.scrollCursorIntoView();
}
@@ -4,7 +4,7 @@ import { BRANDING } from '@shared/branding';
import { LOCALE_LABELS, SUPPORTED } from '@shared/i18n';
import { COLUMN_KEYS } from '@core/context-menu.service';
import { I18nService } from '@core/i18n.service';
import { blockNativeContextMenu, IS_MAC_CHROME } from '@core/platform';
import { blockNativeContextMenu, blockReloadKeys, IS_MAC_CHROME } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
@@ -74,14 +74,14 @@ export class SettingsWindow {
void this.rpc.request.showAbout({});
}
/** Any-window shortcuts (interface scale); ⌘W arrives as a menu action bun-side. */
/** This window's keys: close-window, and the any-window interface scale. */
onWindowKeydown(event: KeyboardEvent): void {
const match = this.shortcuts.resolve(event, 'settings');
if (!match || this.shortcuts.isTypingTarget(event)) return;
event.preventDefault();
if (match.id === 'scale-up') this.settings.setUiScale(this.settings.uiScale() + 0.1);
else if (match.id === 'scale-down') this.settings.setUiScale(this.settings.uiScale() - 0.1);
else if (match.id === 'scale-reset') this.settings.setUiScale(1);
const id = this.shortcuts.claim(event, 'settings');
if (id === 'close-window') void this.rpc.request.settingsClose({});
else if (id === 'scale-up') this.settings.setUiScale(this.settings.uiScale() + 0.1);
else if (id === 'scale-down') this.settings.setUiScale(this.settings.uiScale() - 0.1);
else if (id === 'scale-reset') this.settings.setUiScale(1);
blockReloadKeys(event);
}
blockContextMenu(event: Event): void {
@@ -5,6 +5,7 @@ import type { TransferSnapshot } from '@shared/types';
import { formatSpeed } from '@core/format';
import { PanelsService } from '@core/panels.service';
import { SettingsService } from '@core/settings.service';
import { ShortcutsService } from '@core/shortcuts.service';
import { TransfersService } from '@core/transfers.service';
@Component({
@@ -18,7 +19,7 @@ import { TransfersService } from '@core/transfers.service';
<button
(click)="transfers.expanded.set(!transfers.expanded())"
class="flex min-w-0 items-center gap-1.5 hover:text-foreground"
[title]="i18n.t('transfer.showDetails')"
[title]="shortcuts.tip(i18n.t('transfer.showDetails'), 'toggle-transfers')"
>
@if (transfers.currentJob(); as job) {
<ng-icon name="tdesignLoading" size="0.8rem" class="shrink-0 animate-spin text-primary" />
@@ -62,6 +63,7 @@ import { TransfersService } from '@core/transfers.service';
export class StatusBar {
readonly i18n = inject(I18nService);
readonly transfers = inject(TransfersService);
readonly shortcuts = inject(ShortcutsService);
readonly panels = inject(PanelsService);
readonly settings = inject(SettingsService);
readonly activePanel = computed(() => this.panels.get(this.panels.activeSide()));
+8 -9
View File
@@ -3,8 +3,9 @@ import { NgIcon } from '@ng-icons/core';
import { ContextMenuService } from '@core/context-menu.service';
import { I18nService } from '@core/i18n.service';
import { PanelsService, type Workspace } from '@core/panels.service';
import { IS_MAC_CHROME, MOD_LABEL } from '@core/platform';
import { IS_MAC_CHROME } from '@core/platform';
import { RpcService } from '@core/rpc.service';
import { ShortcutsService } from '@core/shortcuts.service';
import { UpdaterService } from '@core/updater.service';
@Component({
@@ -63,7 +64,7 @@ import { UpdaterService } from '@core/updater.service';
(click)="close($event, ws.id)"
tabindex="-1"
aria-hidden="true"
[title]="i18n.t('tabBar.closeTab', { mod: modLabel })"
[title]="i18n.t('tabBar.closeTab')"
class="mr-1 grid size-4 shrink-0 place-items-center text-muted-foreground opacity-0 group-hover:opacity-100 hover:bg-border hover:text-foreground"
>
<ng-icon name="tdesignClose" size="0.7rem" />
@@ -79,7 +80,7 @@ import { UpdaterService } from '@core/updater.service';
</div>
<button
(click)="panels.newWorkspace()"
[title]="i18n.t('tabBar.newTab', { mod: modLabel })"
[title]="shortcuts.tip(i18n.t('tabBar.newTab'), 'new-tab')"
class="ml-0.5 grid size-6 place-items-center text-muted-foreground electrobun-webkit-app-region-no-drag hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignAdd" size=".8rem" />
@@ -121,7 +122,7 @@ import { UpdaterService } from '@core/updater.service';
<!-- connection manager (own native window) -->
<button
(click)="openManager()"
[title]="i18n.t('tabBar.manageConnections')"
[title]="shortcuts.tip(i18n.t('tabBar.manageConnections'), 'connection-manager')"
class="grid h-6 px-2 py-1 place-items-center text-[0.6875rem] text-muted-foreground electrobun-webkit-app-region-no-drag hover:bg-accent hover:text-foreground"
>
<!-- <ng-icon name="tdesignSetting" size="0.9rem" /> -->
@@ -131,7 +132,7 @@ import { UpdaterService } from '@core/updater.service';
<!-- settings (own native window) -->
<button
(click)="openSettings()"
[title]="i18n.t('tabBar.options')"
[title]="shortcuts.tip(i18n.t('tabBar.options'), 'open-settings')"
class="grid size-6 place-items-center text-muted-foreground electrobun-webkit-app-region-no-drag hover:bg-accent hover:text-foreground"
>
<ng-icon name="tdesignSetting" size="0.9rem" />
@@ -145,8 +146,8 @@ export class TabBar {
readonly updater = inject(UpdaterService);
private readonly contextMenu = inject(ContextMenuService);
private readonly rpc = inject(RpcService);
readonly shortcuts = inject(ShortcutsService);
readonly isMacChrome = IS_MAC_CHROME;
readonly modLabel = MOD_LABEL;
// drag & drop reordering
readonly draggedId = signal<number | null>(null);
@@ -213,9 +214,7 @@ export class TabBar {
/** Update pill: first click downloads, second click (when ready) applies + relaunches. */
onUpdateClick(): void {
const state = this.updater.state();
if (state === 'available') void this.updater.download();
else if (state === 'ready') this.updater.apply();
this.updater.advance();
}
/** Insertion line at the drop position (inset shadow: no layout shift). */
+4 -1
View File
@@ -1,5 +1,6 @@
import { Component, inject } from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import { I18nService } from '@core/i18n.service';
import { ToastService } from '@core/toast.service';
/** Toast stack overlay; shared by the main window and editor windows. */
@@ -7,7 +8,7 @@ import { ToastService } from '@core/toast.service';
selector: 'app-toasts',
imports: [NgIcon],
template: `
<div class="pointer-events-none fixed right-3 bottom-8 z-50 flex w-80 flex-col gap-2">
<div aria-live="polite" class="pointer-events-none fixed right-3 bottom-8 z-50 flex w-80 flex-col gap-2">
@for (t of toast.toasts(); track t.id) {
<div
(mouseenter)="toast.pause(t.id)"
@@ -22,6 +23,7 @@ import { ToastService } from '@core/toast.service';
<span class="min-w-0 flex-1 wrap-break-word">{{ t.text }}</span>
<button
(click)="toast.dismiss(t.id)"
[attr.aria-label]="i18n.t('transfer.dismiss')"
class="shrink-0 text-muted-foreground hover:text-foreground"
>
<ng-icon name="tdesignClose" size="0.9rem" />
@@ -41,6 +43,7 @@ import { ToastService } from '@core/toast.service';
})
export class Toasts {
readonly toast = inject(ToastService);
readonly i18n = inject(I18nService);
toastIcon(kind: 'error' | 'info' | 'success'): string {
if (kind === 'error') return 'tdesignCloseCircle';
@@ -1,8 +1,10 @@
import { Component, inject } from '@angular/core';
import { Component, ElementRef, Injector, afterNextRender, inject } from '@angular/core';
import { NgIcon } from '@ng-icons/core';
import type { TransferSnapshot } from '@shared/types';
import { cycleFocus } from '@core/focus-cycle';
import { formatEta } from '@core/format';
import { I18nService } from '@core/i18n.service';
import { PanelsService } from '@core/panels.service';
import { SettingsService } from '@core/settings.service';
import { TransfersService } from '@core/transfers.service';
@@ -10,11 +12,35 @@ import { TransfersService } from '@core/transfers.service';
selector: 'app-transfer-bar',
imports: [NgIcon],
templateUrl: './transfer-bar.html',
host: { '(keydown)': 'onKeydown($event)' },
})
export class TransferBar {
readonly i18n = inject(I18nService);
readonly transfers = inject(TransfersService);
readonly settings = inject(SettingsService);
private readonly panels = inject(PanelsService);
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
private readonly injector = inject(Injector);
/** ⌘J opened the list: focus its first control once it has rendered. */
focusFirst(): void {
afterNextRender(
() => this.host.nativeElement.querySelector<HTMLElement>('button:not(:disabled)')?.focus(),
{ injector: this.injector },
);
}
/** Tab walks Clear finished and the jobs' Cancel / Dismiss; Esc goes back to
* the file list. */
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.panels.refocus();
} else {
cycleFocus(this.host.nativeElement, event);
}
}
readonly formatSize = (bytes: number): string => this.i18n.size(bytes);
/** "14.2 MB/s · 0:42 left" while a job is moving bytes. */
+8
View File
@@ -285,6 +285,14 @@ body {
opacity: 0.5;
}
/* Where the keyboard is: a Tab-walked button, tab or sidebar entry (see
focus-cycle.ts). :focus-visible only — a click never paints it. Inputs keep
their own focus:ring, the file list its cursor row (outline-none wins). */
:where(button, [role='tab'], [tabindex]:not([tabindex='-1'])):focus-visible {
outline: 2px solid var(--ring);
outline-offset: -2px;
}
/* No native arrow: a caret drawn from two currentColor triangles follows the
theme (a data-URI svg can't). The opened option list stays native — macOS
draws that popup itself. */