PM: merge M3.9 hamburger app menu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/architecture.md # docs/gaps.md
This commit is contained in:
commit
d4e1ba0981
14 changed files with 1004 additions and 25 deletions
|
|
@ -196,7 +196,7 @@ impl Command for Close {
|
||||||
&CommandSpec {
|
&CommandSpec {
|
||||||
id: "buffer.close",
|
id: "buffer.close",
|
||||||
label: "Close Buffer",
|
label: "Close Buffer",
|
||||||
menu_path: None,
|
menu_path: Some("File/Close Tab"),
|
||||||
default_shortcut: Some("Mod+W"),
|
default_shortcut: Some("Mod+W"),
|
||||||
params: "{ id: number, force?: bool (discard unsaved changes) }; returns null; fails with unsaved_changes if the buffer is dirty and force is not set",
|
params: "{ id: number, force?: bool (discard unsaved changes) }; returns null; fails with unsaved_changes if the buffer is dirty and force is not set",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Architecture
|
# Architecture
|
||||||
|
|
||||||
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download) · **Last updated:** 2026-10-18
|
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented; M2 highlighting and `editor.reveal`, plus the search backend, the Find tool window, the symbol index, the Structure tool window and the go-to popup; M3 CLI and single instance, LSP client library, toolchain (PHP detection, Phpactor download), the app menu · **Last updated:** 2026-10-19
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
|
@ -192,7 +192,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
||||||
- **Listing:** `listCommands` returns one list in id order: engine commands and UI commands. `CommandInfo` has `ui: bool`; UI commands also carry `labelKey`, use it as `label` (the engine has no English for them) and are always `enabled` as far as the engine knows.
|
- **Listing:** `listCommands` returns one list in id order: engine commands and UI commands. `CommandInfo` has `ui: bool`; UI commands also carry `labelKey`, use it as `label` (the engine has no English for them) and are always `enabled` as far as the engine knows.
|
||||||
- **Running from outside:** `Engine::execute` on a UI command id queues `uiCommand {id, params}` and returns `null` (params are passed on unchanged). The desktop publishes the event to the window and to control subscribers like any other. The frontend runs the command, so `engine.execute palette.open` over the control channel opens the palette. A `uiCommand` the frontend cannot run (no handler, or disabled) becomes a warning toast.
|
- **Running from outside:** `Engine::execute` on a UI command id queues `uiCommand {id, params}` and returns `null` (params are passed on unchanged). The desktop publishes the event to the window and to control subscribers like any other. The frontend runs the command, so `engine.execute palette.open` over the control channel opens the palette. A `uiCommand` the frontend cannot run (no handler, or disabled) becomes a warning toast.
|
||||||
- **Frontend:** `ui/src/commands/`:
|
- **Frontend:** `ui/src/commands/`:
|
||||||
- `uiCommands.ts` lists the UI commands: `editor.reveal` (no shortcut, M2.2), `find.open` `Mod+Alt+F` (M2.4), `palette.open` `Mod+Shift+P`, `settings.open` `Mod+,`, `view.toggleProjectTree` `Mod+1`.
|
- `uiCommands.ts` lists the UI commands: `editor.reveal` (no shortcut, M2.2), `find.open` `Mod+Alt+F` (M2.4), `menu.open` `Alt+M` (M3.9), `palette.open` `Mod+Shift+P`, `settings.open` `Mod+,`, `view.toggleProjectTree` `Mod+1`. Since M3.9 the user-facing ones carry a `menuPath`.
|
||||||
- `keymap.ts` parses Lutra notation and matches by key code (letters, digits and US punctuation by `code`, so Alt and Shift layout effects don't matter). It also formats shortcuts for display with catalog modifier names.
|
- `keymap.ts` parses Lutra notation and matches by key code (letters, digits and US punctuation by `code`, so Alt and Shift layout effects don't matter). It also formats shortcuts for display with catalog modifier names.
|
||||||
- `rank.ts` ranks for the palette.
|
- `rank.ts` ranks for the palette.
|
||||||
- `store.ts` (Pinia `commands`) holds the merged list, the keymap, the handlers and the recent commands.
|
- `store.ts` (Pinia `commands`) holds the merged list, the keymap, the handlers and the recent commands.
|
||||||
|
|
@ -213,6 +213,16 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
||||||
- **Rows:** disabled rows are dimmed with `aria-disabled`.
|
- **Rows:** disabled rows are dimmed with `aria-disabled`.
|
||||||
- **Accessibility:** combobox with listbox and `aria-activedescendant`.
|
- **Accessibility:** combobox with listbox and `aria-activedescendant`.
|
||||||
|
|
||||||
|
### App menu (M3.9)
|
||||||
|
|
||||||
|
- **Where:** `MainLayout.vue` has a slim header bar (28 px, `--lt-bg`, a `header` slot) whose default content is `ui/src/components/menu/AppMenu.vue`: a button with the Lucide `menu` icon top left.
|
||||||
|
- **Contents (`menu.ts`):** every command in the store's entries with a `menuPath` (engine and UI), grouped by the path's first segment. Groups in Lutra's order File, Edit, View, Go, Help (unknown groups before Help, empty ones hidden), group headings from the catalog (`menu.group.*`). Items follow a fixed id order, others sorted by label after them. A UI command shows its catalog label; an engine command shows the rest of its path (the engine has no catalog, and the path is written for menus), so `buffer.close` reads Close Tab. Deeper paths are flattened as `A › B`.
|
||||||
|
- **Paths:** File (`project.openDialog`, `file.save`, `file.saveAll`, `buffer.close` → `File/Close Tab`, `project.close`, `app.quit`), View (`palette.open`, `view.toggleProjectTree`, `view.toggleStructure`, `find.open`, `settings.open`), Go (`goto.fileOpen`, `goto.classOpen`, `goto.symbolOpen`), Help (`app.about`). Edit stays empty until there are edit commands; the terminal toggle gets `View/Terminal` when M3.6 lands (its id is already in the order list).
|
||||||
|
- **Opening:** the button (a second click closes) or `menu.open` (`Alt+M`, Lutra's own; also as `uiCommand`). It refreshes the enabled states and focuses the first item.
|
||||||
|
- **Keyboard:** WAI-ARIA menu with roving focus: arrows wrap, Home/End, Enter/Space runs, Escape or Tab closes, printable keys type ahead (500 ms buffer; one letter cycles through items with that initial). Disabled items are focusable, dimmed (`aria-disabled`) and do nothing.
|
||||||
|
- **Modal rule:** `menu` is an exclusive `ModalId`; the menu is a launcher like the palette: `commands/store.ts` › `execute` closes it for every command but `menu.open`, so a shortcut, a palette command or an agent's `uiCommand` never leaves it open. A chosen command runs after the menu closed and returned the focus.
|
||||||
|
- **Why a dropdown with headings instead of a menu bar:** one keyboard path (open, type, Enter) like the palette, no nested popups to manage, and it fits the slim header. A native macOS menu bar and a display-mode setting are follow-ups.
|
||||||
|
|
||||||
### Settings dialog (M1.9b)
|
### Settings dialog (M1.9b)
|
||||||
|
|
||||||
- **Store:** `ui/src/stores/settings.ts` (Pinia `settings`, started by `App.vue`) loads `settings.list` and `settings.get`, reads both defensively (unknown types and malformed entries dropped, values must be scalars), changes values through `settings.set`/`settings.reset` and keeps a refused change's message per key. `settingsChanged` reloads the named keys with `settings.get {keys}` and drops their errors, so changes from the control channel or an agent show at once.
|
- **Store:** `ui/src/stores/settings.ts` (Pinia `settings`, started by `App.vue`) loads `settings.list` and `settings.get`, reads both defensively (unknown types and malformed entries dropped, values must be scalars), changes values through `settings.set`/`settings.reset` and keeps a refused change's message per key. `settingsChanged` reloads the named keys with `settings.get {keys}` and drops their errors, so changes from the control channel or an agent show at once.
|
||||||
|
|
@ -333,6 +343,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
||||||
|
|
||||||
| Date | Change | Summary |
|
| Date | Change | Summary |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
| 2026-10-19 | minor | M3.9: app menu (header bar, `menu.open`, grouping by `menuPath`, launcher under the modal rule); menu paths for user commands |
|
||||||
| 2026-10-18 | minor | M3.1: toolchain (PHP detection, pinned Phpactor download with SHA-256 check, network access note, D15), `toolchain.status`/`toolchain.downloadPhpactor`, `toolchainChanged`, bool and string settings |
|
| 2026-10-18 | minor | M3.1: toolchain (PHP detection, pinned Phpactor download with SHA-256 check, network access note, D15), `toolchain.status`/`toolchain.downloadPhpactor`, `toolchainChanged`, bool and string settings |
|
||||||
| 2026-10-18 | minor | M3.2: LSP client library (`crates/lsp`: framing, supervision and restart, initialize, requests with timeout and cancel, server requests, document sync, fake server tests) |
|
| 2026-10-18 | minor | M3.2: LSP client library (`crates/lsp`: framing, supervision and restart, initialize, requests with timeout and cancel, server requests, document sync, fake server tests) |
|
||||||
| 2026-10-17 | minor | M3.7: `lutra` CLI, single instance, rendezvous file and token listener, `app.auth`/`app.focus`, CLI to L6 |
|
| 2026-10-17 | minor | M3.7: `lutra` CLI, single instance, rendezvous file and token listener, `app.auth`/`app.focus`, CLI to L6 |
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Gaps
|
# Gaps
|
||||||
|
|
||||||
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal); G3 M1 part done (project tree, palette, settings dialog, themes); G4 under way (tree-sitter outline and folding library, Lezer highlighting, Structure tool window); G5 under way (search backend, Find tool window, symbol index, go-to popup); G6 under way (LSP client library, PHP detection, Phpactor download); G7 under way (`lutra` CLI and single instance); G14 English UI catalog in place · **Last updated:** 2026-10-18
|
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal); G3 M1 part done (project tree, palette, settings dialog, themes) plus the app menu (M3.9); G4 under way (tree-sitter outline and folding library, Lezer highlighting, Structure tool window); G5 under way (search backend, Find tool window, symbol index, go-to popup); G6 under way (LSP client library, PHP detection, Phpactor download); G7 under way (`lutra` CLI and single instance); G14 English UI catalog in place · **Last updated:** 2026-10-19
|
||||||
|
|
||||||
Every known shortfall, ranked. This is the work list: unless the owner gives a task, take the highest open gap. Hours are agent wall-clock hours for one agent, all estimated.
|
Every known shortfall, ranked. This is the work list: unless the owner gives a task, take the highest open gap. Hours are agent wall-clock hours for one agent, all estimated.
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ Every known shortfall, ranked. This is the work list: unless the owner gives a t
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| G1 | ~~Foundation: workspace, quality gate, command registry, guard, control channel~~ closed 2026-10-14 | M0 | done (~2 h measured) |
|
| G1 | ~~Foundation: workspace, quality gate, command registry, guard, control channel~~ closed 2026-10-14 | M0 | done (~2 h measured) |
|
||||||
| G2 | Editor core: ~~engine buffers, save~~ (M1.3), ~~editor UI with tabs, undo, multi-caret~~ (M1.6, CodeMirror basics), ~~recovery journal~~ (M1.7), tab management (preview, pin, split, close others, reopen), conflict UI for files changed on disk, autosave option | M1 | ~16 h |
|
| G2 | Editor core: ~~engine buffers, save~~ (M1.3), ~~editor UI with tabs, undo, multi-caret~~ (M1.6, CodeMirror basics), ~~recovery journal~~ (M1.7), tab management (preview, pin, split, close others, reopen), conflict UI for files changed on disk, autosave option | M1 | ~16 h |
|
||||||
| G3 | Project model: ~~VFS~~ (M1.2: listing, ignore rules, native file watching with polling fallback, safe file IO), ~~project tree wiring~~ (M1.5 UI, M1.3 engine, M1.4 bridge: folder picker, live tree), tree toolbar and options, ~~showing truncated listings~~ (M1.13), ~~error notifications for the folder picker~~ (M1.12), ~~tabs~~ (M1.6), ~~command palette~~ (M1.8: commands only, global keymap, UI commands over the control channel); ~~settings~~ (backend: M1.9a; dialog with search: M1.9b), ~~theme switching~~ (M1.10: light/dark, live, system mode; picker in the dialog, M1.9b) | M1 | ~24 h |
|
| G3 | Project model: ~~VFS~~ (M1.2: listing, ignore rules, native file watching with polling fallback, safe file IO), ~~project tree wiring~~ (M1.5 UI, M1.3 engine, M1.4 bridge: folder picker, live tree), tree toolbar and options, ~~showing truncated listings~~ (M1.13), ~~error notifications for the folder picker~~ (M1.12), ~~tabs~~ (M1.6), ~~command palette~~ (M1.8: commands only, global keymap, UI commands over the control channel); ~~settings~~ (backend: M1.9a; dialog with search: M1.9b), ~~theme switching~~ (M1.10: light/dark, live, system mode; picker in the dialog, M1.9b), ~~main menu~~ (M3.9: hamburger dropdown from `menuPath`s; native macOS menu bar and display modes open) | M1 | ~24 h |
|
||||||
| G4 | Syntax and structure: tree-sitter PHP, ~~Lezer highlighting~~ (M2.2: PHP with embedded HTML plus HTML, CSS, JS/TS, JSON, YAML, Markdown; `--lt-syntax-*` tokens; `editor.reveal`), ~~file structure~~ (M2.7: Structure tool window, `syntax.outline`), semantic highlighting, folding in the editor | M2 | ~8 h |
|
| G4 | Syntax and structure: tree-sitter PHP, ~~Lezer highlighting~~ (M2.2: PHP with embedded HTML plus HTML, CSS, JS/TS, JSON, YAML, Markdown; `--lt-syntax-*` tokens; `editor.reveal`), ~~file structure~~ (M2.7: Structure tool window, `syntax.outline`), semantic highlighting, folding in the editor | M2 | ~8 h |
|
||||||
| G5 | Search and navigation: find in files, go to file/class/symbol, first index | M2 | ~35 h |
|
| G5 | Search and navigation: find in files, go to file/class/symbol, first index | M2 | ~35 h |
|
||||||
| G6 | Language server: completion, diagnostics, definition, hover, rename via Phpactor (~~PHP detection and Phpactor download~~, M3.1) | M3 | ~43 h |
|
| G6 | Language server: completion, diagnostics, definition, hover, rename via Phpactor (~~PHP detection and Phpactor download~~, M3.1) | M3 | ~43 h |
|
||||||
|
|
@ -50,6 +50,7 @@ G6 progress: M3.2 landed the LSP client library in `crates/lsp`: JSON-RPC framin
|
||||||
|
|
||||||
| Date | Change | Summary |
|
| Date | Change | Summary |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
| 2026-10-19 | minor | G3: app menu (M3.9) |
|
||||||
| 2026-10-18 | minor | G6: PHP detection and pinned Phpactor download (M3.1) |
|
| 2026-10-18 | minor | G6: PHP detection and pinned Phpactor download (M3.1) |
|
||||||
| 2026-10-18 | minor | G6: LSP client library (M3.2) |
|
| 2026-10-18 | minor | G6: LSP client library (M3.2) |
|
||||||
| 2026-10-18 | minor | G17–G21 from the full PhpStorm inventory (deployment, editor productivity, remote, AI, breadth) |
|
| 2026-10-18 | minor | G17–G21 from the full PhpStorm inventory (deployment, editor productivity, remote, AI, breadth) |
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
# UI parity checklist
|
# UI parity checklist
|
||||||
|
|
||||||
> **Status:** main window layout (M1.5), project tree running against the engine (M1.4), editor tabs with a CodeMirror editor (M1.6), light and dark themes (M1.10), restore dialog for unsaved changes (M1.7), notification toasts (M1.12), command palette and global keymap (M1.8), settings dialog with search (M1.9b), syntax highlighting and `editor.reveal` (M2.2), Find tool window in the bottom panel (M2.4), go-to popup (M2.6), left stripe and Structure tool window (M2.7) · **Last updated:** 2026-10-17
|
> **Status:** main window layout (M1.5), project tree running against the engine (M1.4), editor tabs with a CodeMirror editor (M1.6), light and dark themes (M1.10), restore dialog for unsaved changes (M1.7), notification toasts (M1.12), command palette and global keymap (M1.8), settings dialog with search (M1.9b), syntax highlighting and `editor.reveal` (M2.2), Find tool window in the bottom panel (M2.4), go-to popup (M2.6), left stripe and Structure tool window (M2.7), app menu (M3.9) · **Last updated:** 2026-10-19
|
||||||
|
|
||||||
- [ ] Main window: tool window stripes, editor area, status bar, navigation bar
|
- [ ] Main window: tool window stripes, editor area, status bar, navigation bar
|
||||||
- M2.7 (2026-10-17): a left stripe with one tab per left tool window (Project, Structure); the shown one is marked, clicking it again hides the window. Still missing: right docking, several bottom tool windows, drag to rearrange, navigation bar, layout persistence.
|
- M2.7 (2026-10-17): a left stripe with one tab per left tool window (Project, Structure); the shown one is marked, clicking it again hides the window. Still missing: right docking, several bottom tool windows, drag to rearrange, navigation bar, layout persistence.
|
||||||
- M1.5 (2026-10-14): left tool window with header, hide button, collapsed stripe with a show button, resizable by pointer and keyboard; editor area placeholder; status bar. Missing: stripes with several tool windows, bottom/right docking, navigation bar, layout persistence. Not checked in the running app yet (needs M1.4).
|
- M1.5 (2026-10-14): left tool window with header, hide button, collapsed stripe with a show button, resizable by pointer and keyboard; editor area placeholder; status bar. Missing: stripes with several tool windows, bottom/right docking, navigation bar, layout persistence. Not checked in the running app yet (needs M1.4).
|
||||||
|
- [ ] Main menu
|
||||||
|
- M3.9 (2026-10-19): a slim header bar with a menu button (Lucide `menu`) top left; its dropdown lists every command with a `menuPath` (engine and UI), grouped File, Edit, View, Go, Help in Lutra's own order, with shortcuts; disabled entries dimmed and not runnable. Keyboard: `Alt+M` (`menu.open`, also over `uiCommand`), arrows, Home/End, Enter/Space, Escape/Tab, type-ahead. An exclusive modal and launcher (one-modal rule). Vitest; live check on Windows 11 (port 7939). Missing: a display-mode option (always visible menu bar), native macOS menu bar, submenus and separators, an Edit group (no edit commands yet), an About window. Behaviour notes: `plan/phpstorm/14-main-menu.md`.
|
||||||
- [ ] Project tool window (tree, scroll from source, file operations)
|
- [ ] Project tool window (tree, scroll from source, file operations)
|
||||||
- M1.5 (2026-10-14): tree of the open folder with lazy `project.children` listings, folders and PHP files with Lucide icons, ignored/excluded entries dimmed, keyboard navigation (WAI-ARIA tree: arrows, Home/End, Enter), double-click opens, refresh on `TreeChanged`, listing errors shown in the tree, empty state with Open Folder…. Vitest only, against a mocked engine.
|
- M1.5 (2026-10-14): tree of the open folder with lazy `project.children` listings, folders and PHP files with Lucide icons, ignored/excluded entries dimmed, keyboard navigation (WAI-ARIA tree: arrows, Home/End, Enter), double-click opens, refresh on `TreeChanged`, listing errors shown in the tree, empty state with Open Folder…. Vitest only, against a mocked engine.
|
||||||
- M1.4 (2026-10-15): runs against the real engine in the app: projects open from the folder picker or the command line, the tree updates live when files change on disk; checked with `ui.screenshot` on Windows 11. M1.13 (2026-10-16): a partly listed folder ends with a "Listing truncated" note; opening a file that is already open (tree, control channel) switches to its tab (Vitest; live check pending (gaming mode)). Missing: scroll from source (Select Opened File), expand/collapse all, views list, sort options, speed search, file colours, file operations. Behaviour notes: `plan/phpstorm/02-project-view.md`.
|
- M1.4 (2026-10-15): runs against the real engine in the app: projects open from the folder picker or the command line, the tree updates live when files change on disk; checked with `ui.screenshot` on Windows 11. M1.13 (2026-10-16): a partly listed folder ends with a "Listing truncated" note; opening a file that is already open (tree, control channel) switches to its tab (Vitest; live check pending (gaming mode)). Missing: scroll from source (Select Opened File), expand/collapse all, views list, sort options, speed search, file colours, file operations. Behaviour notes: `plan/phpstorm/02-project-view.md`.
|
||||||
|
|
@ -38,6 +40,7 @@
|
||||||
|
|
||||||
| Date | Change | Summary |
|
| Date | Change | Summary |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
| 2026-10-19 | minor | Main menu partial (M3.9) |
|
||||||
| 2026-10-17 | minor | Go-to popup partial (M2.6) |
|
| 2026-10-17 | minor | Go-to popup partial (M2.6) |
|
||||||
| 2026-10-17 | minor | Structure tool window partial, left stripe (M2.7) |
|
| 2026-10-17 | minor | Structure tool window partial, left stripe (M2.7) |
|
||||||
| 2026-10-17 | minor | Find tool window partial, bottom panel (M2.4) |
|
| 2026-10-17 | minor | Find tool window partial, bottom panel (M2.4) |
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* The modal rule (M1.15): at most one modal is open at a time.
|
* The modal rule (M1.15): at most one modal is open at a time.
|
||||||
*
|
*
|
||||||
* - **Exclusive modals:** the command palette, the go-to popup (M2.6), the
|
* - **Exclusive modals:** the command palette, the go-to popup (M2.6), the
|
||||||
* settings dialog and the close question of a dirty tab. Opening one closes the one that is open
|
* app menu (M3.9), the settings dialog and the close question of a dirty tab. Opening one closes the one that is open
|
||||||
* (the close question closes as Cancel). Each reports itself with
|
* (the close question closes as Cancel). Each reports itself with
|
||||||
* {@link useModalsStore}'s `opened` and `closed`; the close question is
|
* {@link useModalsStore}'s `opened` and `closed`; the close question is
|
||||||
* followed from the editor store, so the editor needs no code for it.
|
* followed from the editor store, so the editor needs no code for it.
|
||||||
|
|
@ -15,14 +15,15 @@
|
||||||
* `palette.open` closes it first (see `store.ts` › `execute`), so a
|
* `palette.open` closes it first (see `store.ts` › `execute`), so a
|
||||||
* `uiCommand` from the control channel never leaves it open behind
|
* `uiCommand` from the control channel never leaves it open behind
|
||||||
* what the command shows. The go-to popup is a launcher too: any command
|
* what the command shows. The go-to popup is a launcher too: any command
|
||||||
* but the go-to open commands closes it.
|
* but the go-to open commands closes it. So is the app menu (M3.9): any
|
||||||
|
* command but `menu.open` closes it.
|
||||||
*/
|
*/
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useEditorStore } from "../stores/editor";
|
import { useEditorStore } from "../stores/editor";
|
||||||
|
|
||||||
/** The exclusive modals. */
|
/** The exclusive modals. */
|
||||||
export type ModalId = "palette" | "goto" | "settings" | "closePrompt";
|
export type ModalId = "palette" | "goto" | "menu" | "settings" | "closePrompt";
|
||||||
|
|
||||||
/** Store of the open exclusive modal. */
|
/** Store of the open exclusive modal. */
|
||||||
export const useModalsStore = defineStore("modals", () => {
|
export const useModalsStore = defineStore("modals", () => {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
* commands run with empty params.
|
* commands run with empty params.
|
||||||
* - **Errors:** a failed command raises an error toast (M1.12).
|
* - **Errors:** a failed command raises an error toast (M1.12).
|
||||||
* - **Palette:** running any command but `palette.open` closes the palette
|
* - **Palette:** running any command but `palette.open` closes the palette
|
||||||
* first (the modal rule, `modals.ts`).
|
* first (the modal rule, `modals.ts`); likewise any command but
|
||||||
|
* `menu.open` closes the app menu (M3.9).
|
||||||
*/
|
*/
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref, shallowReactive } from "vue";
|
import { computed, ref, shallowReactive } from "vue";
|
||||||
|
|
@ -49,11 +50,18 @@ export interface PaletteEntry {
|
||||||
shortcut: string | null;
|
shortcut: string | null;
|
||||||
/** Whether it can run now. */
|
/** Whether it can run now. */
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
/** Menu path with `/` separators, or null if the command is in no menu (M3.9). */
|
||||||
|
menuPath: string | null;
|
||||||
|
/** Whether the frontend runs it (a UI command, label from the catalog). */
|
||||||
|
ui: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Most recently run commands remembered. */
|
/** Most recently run commands remembered. */
|
||||||
export const MAX_RECENT = 20;
|
export const MAX_RECENT = 20;
|
||||||
|
|
||||||
|
/** The UI command that opens the app menu, which therefore keeps it open. */
|
||||||
|
const MENU_OPEN = "menu.open";
|
||||||
|
|
||||||
/** The UI commands that open the go-to popup, which therefore keep it open. */
|
/** The UI commands that open the go-to popup, which therefore keep it open. */
|
||||||
const GOTO_OPEN = new Set(["goto.fileOpen", "goto.classOpen", "goto.symbolOpen"]);
|
const GOTO_OPEN = new Set(["goto.fileOpen", "goto.classOpen", "goto.symbolOpen"]);
|
||||||
|
|
||||||
|
|
@ -151,6 +159,8 @@ export const useCommandsStore = defineStore("commands", () => {
|
||||||
label: labelOf(info),
|
label: labelOf(info),
|
||||||
shortcut: typeof info.defaultShortcut === "string" ? formatShortcut(info.defaultShortcut, mac) : null,
|
shortcut: typeof info.defaultShortcut === "string" ? formatShortcut(info.defaultShortcut, mac) : null,
|
||||||
enabled: isEnabled(info.id),
|
enabled: isEnabled(info.id),
|
||||||
|
menuPath: typeof info.menuPath === "string" && info.menuPath !== "" ? info.menuPath : null,
|
||||||
|
ui: info.ui === true,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -187,8 +197,9 @@ export const useCommandsStore = defineStore("commands", () => {
|
||||||
* Runs a command the user chose (keyboard or palette): through its
|
* Runs a command the user chose (keyboard or palette): through its
|
||||||
* handler if a component supplied one, else through the engine. A
|
* handler if a component supplied one, else through the engine. A
|
||||||
* disabled command does nothing. A failure raises an error toast. Any
|
* disabled command does nothing. A failure raises an error toast. Any
|
||||||
* command but `palette.open` closes the palette before it runs, and any
|
* command but `palette.open` closes the palette before it runs, any
|
||||||
* command but the go-to open commands closes the go-to popup.
|
* command but the go-to open commands closes the go-to popup, and any
|
||||||
|
* command but `menu.open` closes the app menu.
|
||||||
*
|
*
|
||||||
* @param id - the command id.
|
* @param id - the command id.
|
||||||
* @param params - the params.
|
* @param params - the params.
|
||||||
|
|
@ -204,6 +215,9 @@ export const useCommandsStore = defineStore("commands", () => {
|
||||||
if (!GOTO_OPEN.has(id)) {
|
if (!GOTO_OPEN.has(id)) {
|
||||||
modals.dismiss("goto");
|
modals.dismiss("goto");
|
||||||
}
|
}
|
||||||
|
if (id !== MENU_OPEN) {
|
||||||
|
modals.dismiss("menu");
|
||||||
|
}
|
||||||
const handler = handlers.get(id);
|
const handler = handlers.get(id);
|
||||||
if (handler) {
|
if (handler) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ export interface UiCommandSpec {
|
||||||
/** The frontend's UI commands. */
|
/** The frontend's UI commands. */
|
||||||
export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
||||||
{ id: "editor.reveal", labelKey: "command.editor.reveal" },
|
{ id: "editor.reveal", labelKey: "command.editor.reveal" },
|
||||||
{ id: "find.open", labelKey: "command.find.open", defaultShortcut: "Mod+Alt+F" },
|
{ id: "find.open", labelKey: "command.find.open", menuPath: "View/Find in Files…", defaultShortcut: "Mod+Alt+F" },
|
||||||
{ id: "goto.classOpen", labelKey: "command.goto.classOpen", defaultShortcut: "Mod+Alt+C" },
|
{ id: "goto.classOpen", labelKey: "command.goto.classOpen", menuPath: "Go/Class…", defaultShortcut: "Mod+Alt+C" },
|
||||||
{ id: "goto.fileOpen", labelKey: "command.goto.fileOpen", defaultShortcut: "Mod+P" },
|
{ id: "goto.fileOpen", labelKey: "command.goto.fileOpen", menuPath: "Go/File…", defaultShortcut: "Mod+P" },
|
||||||
{ id: "goto.symbolOpen", labelKey: "command.goto.symbolOpen", defaultShortcut: "Mod+T" },
|
{ id: "goto.symbolOpen", labelKey: "command.goto.symbolOpen", menuPath: "Go/Symbol…", defaultShortcut: "Mod+T" },
|
||||||
{ id: "palette.open", labelKey: "command.palette.open", defaultShortcut: "Mod+Shift+P" },
|
{ id: "menu.open", labelKey: "command.menu.open", defaultShortcut: "Alt+M" },
|
||||||
{ id: "settings.open", labelKey: "command.settings.open", defaultShortcut: "Mod+," },
|
{ id: "palette.open", labelKey: "command.palette.open", menuPath: "View/Command Palette", defaultShortcut: "Mod+Shift+P" },
|
||||||
{ id: "view.toggleProjectTree", labelKey: "command.view.toggleProjectTree", defaultShortcut: "Mod+1" },
|
{ id: "settings.open", labelKey: "command.settings.open", menuPath: "View/Settings…", defaultShortcut: "Mod+," },
|
||||||
{ id: "view.toggleStructure", labelKey: "command.view.toggleStructure", defaultShortcut: "Mod+2" },
|
{ id: "view.toggleProjectTree", labelKey: "command.view.toggleProjectTree", menuPath: "View/Project", defaultShortcut: "Mod+1" },
|
||||||
|
{ id: "view.toggleStructure", labelKey: "command.view.toggleStructure", menuPath: "View/Structure", defaultShortcut: "Mod+2" },
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
* appears with the UI command `find.open` (`Mod+Alt+F`, supplied here so it
|
* appears with the UI command `find.open` (`Mod+Alt+F`, supplied here so it
|
||||||
* works before the panel exists), collapses to its header and closes from
|
* works before the panel exists), collapses to its header and closes from
|
||||||
* its header; the Find store keeps the results while it is closed.
|
* its header; the Find store keeps the results while it is closed.
|
||||||
|
*
|
||||||
|
* A slim header bar along the top (M3.9) holds the app menu
|
||||||
|
* ({@link AppMenu}); its `header` slot can replace it.
|
||||||
*/
|
*/
|
||||||
import { FolderTree, ListTree } from "@lucide/vue";
|
import { FolderTree, ListTree } from "@lucide/vue";
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
||||||
|
|
@ -29,6 +32,7 @@ import FindToolWindow from "../find/FindToolWindow.vue";
|
||||||
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
|
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
|
||||||
import StatusBar from "../StatusBar.vue";
|
import StatusBar from "../StatusBar.vue";
|
||||||
import StructureToolWindow from "../structure/StructureToolWindow.vue";
|
import StructureToolWindow from "../structure/StructureToolWindow.vue";
|
||||||
|
import AppMenu from "../menu/AppMenu.vue";
|
||||||
import BottomPanel from "./BottomPanel.vue";
|
import BottomPanel from "./BottomPanel.vue";
|
||||||
import ToolWindow from "./ToolWindow.vue";
|
import ToolWindow from "./ToolWindow.vue";
|
||||||
|
|
||||||
|
|
@ -100,6 +104,14 @@ onBeforeUnmount(() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="main-layout">
|
<div class="main-layout">
|
||||||
|
<header
|
||||||
|
class="main-layout__header"
|
||||||
|
data-test="main-header"
|
||||||
|
>
|
||||||
|
<slot name="header">
|
||||||
|
<AppMenu />
|
||||||
|
</slot>
|
||||||
|
</header>
|
||||||
<div class="main-layout__row">
|
<div class="main-layout__row">
|
||||||
<nav
|
<nav
|
||||||
class="main-layout__stripe"
|
class="main-layout__stripe"
|
||||||
|
|
@ -163,6 +175,16 @@ onBeforeUnmount(() => {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main-layout__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: none;
|
||||||
|
height: 28px;
|
||||||
|
padding: 0 var(--lt-space-s, 4px);
|
||||||
|
background: var(--lt-bg);
|
||||||
|
border-bottom: 1px solid var(--lt-border);
|
||||||
|
}
|
||||||
|
|
||||||
.main-layout__row {
|
.main-layout__row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
|
||||||
376
ui/src/components/menu/AppMenu.vue
Normal file
376
ui/src/components/menu/AppMenu.vue
Normal file
|
|
@ -0,0 +1,376 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* The app menu (M3.9): a button with the Lucide `menu` icon at the top
|
||||||
|
* left of the window that opens a dropdown of every command with a menu
|
||||||
|
* path, grouped by the path's first segment (see `menu.ts`).
|
||||||
|
*
|
||||||
|
* - **Opening:** a click on the button (again closes it) or the UI command
|
||||||
|
* `menu.open` (`Alt+M`, Lutra's own; also over `uiCommand`). Opening
|
||||||
|
* refreshes the enabled states and focuses the first item.
|
||||||
|
* - **Items** show the command's shortcut; disabled ones are dimmed, stay
|
||||||
|
* focusable and do nothing.
|
||||||
|
* - **Keyboard:** arrows move (wrapping), Home/End jump, Enter or Space
|
||||||
|
* runs, Escape or Tab closes, typing a letter jumps to the next item
|
||||||
|
* starting with what was typed (the typed text resets after 500 ms).
|
||||||
|
* - **Modal rule:** the menu is an exclusive modal and a launcher: opening
|
||||||
|
* it closes the palette or another modal, and running any command but
|
||||||
|
* `menu.open` (keyboard, palette, `uiCommand`) closes it. A chosen
|
||||||
|
* command runs after the menu closed and gave the focus back.
|
||||||
|
*/
|
||||||
|
import { Menu } from "@lucide/vue";
|
||||||
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue";
|
||||||
|
import { useModalsStore } from "../../commands/modals";
|
||||||
|
import { useCommandsStore } from "../../commands/store";
|
||||||
|
import { t } from "../../i18n";
|
||||||
|
import { buildMenu, typeAhead, type MenuItem } from "./menu";
|
||||||
|
|
||||||
|
/** Time after which type-ahead starts over, in milliseconds. */
|
||||||
|
const TYPE_AHEAD_RESET_MS = 500;
|
||||||
|
|
||||||
|
const commands = useCommandsStore();
|
||||||
|
const modals = useModalsStore();
|
||||||
|
|
||||||
|
/** Whether the dropdown is shown. */
|
||||||
|
const open = ref(false);
|
||||||
|
/** Index of the focused item in {@link flat}. */
|
||||||
|
const focused = ref(0);
|
||||||
|
/** The dropdown. */
|
||||||
|
const panel = ref<HTMLElement | null>(null);
|
||||||
|
/** The menu button. */
|
||||||
|
const button = ref<HTMLButtonElement | null>(null);
|
||||||
|
/** The element that had the focus before the menu opened. */
|
||||||
|
let returnFocus: HTMLElement | null = null;
|
||||||
|
/** What was typed for type-ahead. */
|
||||||
|
let typed = "";
|
||||||
|
/** Clears {@link typed}; set while typing. */
|
||||||
|
let typedTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
/** Withdraws the `menu.open` handler; set while mounted. */
|
||||||
|
let withdraw: (() => void) | null = null;
|
||||||
|
|
||||||
|
/** The groups of the menu. */
|
||||||
|
const groups = computed(() => buildMenu(commands.entries));
|
||||||
|
/** Every item in display order. */
|
||||||
|
const flat = computed<MenuItem[]>(() => groups.value.flatMap((group) => group.items));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The index of an item in {@link flat}.
|
||||||
|
*
|
||||||
|
* @param id - the command id.
|
||||||
|
*/
|
||||||
|
function indexOf(id: string): number {
|
||||||
|
return flat.value.findIndex((item) => item.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focuses an item and remembers it as focused.
|
||||||
|
*
|
||||||
|
* @param index - index in {@link flat}.
|
||||||
|
*/
|
||||||
|
function focusItem(index: number): void {
|
||||||
|
if (index < 0 || index >= flat.value.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
focused.value = index;
|
||||||
|
void nextTick(() => {
|
||||||
|
panel.value?.querySelector<HTMLElement>(`#lt-menu-${String(index)}`)?.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Opens the menu, refreshes the enabled states and focuses the first item. */
|
||||||
|
async function show(): Promise<void> {
|
||||||
|
modals.opened("menu", close);
|
||||||
|
if (!open.value) {
|
||||||
|
const active = document.activeElement;
|
||||||
|
returnFocus = active instanceof HTMLElement ? active : null;
|
||||||
|
}
|
||||||
|
open.value = true;
|
||||||
|
focusItem(0);
|
||||||
|
await commands.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Closes the menu and gives the focus back. */
|
||||||
|
function close(): void {
|
||||||
|
if (!open.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
open.value = false;
|
||||||
|
modals.closed("menu");
|
||||||
|
typed = "";
|
||||||
|
returnFocus?.focus();
|
||||||
|
returnFocus = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Opens the menu or, when it is open, closes it (the button). */
|
||||||
|
function toggle(): void {
|
||||||
|
if (open.value) {
|
||||||
|
close();
|
||||||
|
} else {
|
||||||
|
void show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs an item's command if it is enabled; the menu closes first.
|
||||||
|
*
|
||||||
|
* @param item - the item.
|
||||||
|
*/
|
||||||
|
function choose(item: MenuItem | undefined): void {
|
||||||
|
if (!item?.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
void commands.execute(item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a typed character and moves to the next matching item.
|
||||||
|
*
|
||||||
|
* @param char - the character.
|
||||||
|
*/
|
||||||
|
function onType(char: string): void {
|
||||||
|
typed += char;
|
||||||
|
if (typedTimer !== null) {
|
||||||
|
clearTimeout(typedTimer);
|
||||||
|
}
|
||||||
|
typedTimer = setTimeout(() => {
|
||||||
|
typed = "";
|
||||||
|
typedTimer = null;
|
||||||
|
}, TYPE_AHEAD_RESET_MS);
|
||||||
|
const index = typeAhead(
|
||||||
|
flat.value.map((item) => item.label),
|
||||||
|
typed,
|
||||||
|
focused.value,
|
||||||
|
);
|
||||||
|
focusItem(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keyboard handling inside the dropdown.
|
||||||
|
*
|
||||||
|
* @param event - the key press.
|
||||||
|
*/
|
||||||
|
function onKeydown(event: KeyboardEvent): void {
|
||||||
|
const count = flat.value.length;
|
||||||
|
switch (event.key) {
|
||||||
|
case "ArrowDown":
|
||||||
|
focusItem(count > 0 ? (focused.value + 1) % count : -1);
|
||||||
|
break;
|
||||||
|
case "ArrowUp":
|
||||||
|
focusItem(count > 0 ? (focused.value - 1 + count) % count : -1);
|
||||||
|
break;
|
||||||
|
case "Home":
|
||||||
|
focusItem(0);
|
||||||
|
break;
|
||||||
|
case "End":
|
||||||
|
focusItem(count - 1);
|
||||||
|
break;
|
||||||
|
case "Enter":
|
||||||
|
case " ":
|
||||||
|
choose(flat.value[focused.value]);
|
||||||
|
break;
|
||||||
|
case "Escape":
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
case "Tab":
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
||||||
|
onType(event.key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
withdraw = commands.provide("menu.open", { run: show });
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
withdraw?.();
|
||||||
|
withdraw = null;
|
||||||
|
if (typedTimer !== null) {
|
||||||
|
clearTimeout(typedTimer);
|
||||||
|
typedTimer = null;
|
||||||
|
}
|
||||||
|
if (open.value) {
|
||||||
|
modals.closed("menu");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
defineExpose({ show, close });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="app-menu">
|
||||||
|
<button
|
||||||
|
ref="button"
|
||||||
|
type="button"
|
||||||
|
class="app-menu__button"
|
||||||
|
:class="{ 'app-menu__button--open': open }"
|
||||||
|
aria-haspopup="menu"
|
||||||
|
:aria-expanded="open"
|
||||||
|
aria-controls="lt-app-menu"
|
||||||
|
:aria-label="t('menu.button')"
|
||||||
|
:title="t('menu.button')"
|
||||||
|
data-test="menu-button"
|
||||||
|
@mousedown.prevent
|
||||||
|
@click="toggle()"
|
||||||
|
>
|
||||||
|
<Menu :size="16" />
|
||||||
|
</button>
|
||||||
|
<div
|
||||||
|
v-if="open"
|
||||||
|
class="app-menu__backdrop"
|
||||||
|
data-test="menu-backdrop"
|
||||||
|
@mousedown.self.prevent="close()"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
id="lt-app-menu"
|
||||||
|
ref="panel"
|
||||||
|
class="app-menu__panel"
|
||||||
|
role="menu"
|
||||||
|
:aria-label="t('menu.label')"
|
||||||
|
data-test="menu"
|
||||||
|
@keydown="onKeydown"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="group in groups"
|
||||||
|
:key="group.key"
|
||||||
|
class="app-menu__group"
|
||||||
|
role="group"
|
||||||
|
:aria-labelledby="`lt-menu-group-${group.key}`"
|
||||||
|
data-test="menu-group"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
:id="`lt-menu-group-${group.key}`"
|
||||||
|
class="app-menu__heading"
|
||||||
|
role="presentation"
|
||||||
|
>
|
||||||
|
{{ group.label }}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="item in group.items"
|
||||||
|
:id="`lt-menu-${String(indexOf(item.id))}`"
|
||||||
|
:key="item.id"
|
||||||
|
class="app-menu__item"
|
||||||
|
:class="{
|
||||||
|
'app-menu__item--focused': indexOf(item.id) === focused,
|
||||||
|
'app-menu__item--disabled': !item.enabled,
|
||||||
|
}"
|
||||||
|
role="menuitem"
|
||||||
|
:tabindex="indexOf(item.id) === focused ? 0 : -1"
|
||||||
|
:aria-disabled="!item.enabled"
|
||||||
|
:data-command="item.id"
|
||||||
|
data-test="menu-item"
|
||||||
|
@mousemove="focusItem(indexOf(item.id))"
|
||||||
|
@mousedown.prevent
|
||||||
|
@click="choose(item)"
|
||||||
|
>
|
||||||
|
<span class="app-menu__label">{{ item.label }}</span>
|
||||||
|
<kbd
|
||||||
|
v-if="item.shortcut"
|
||||||
|
class="app-menu__shortcut"
|
||||||
|
data-test="menu-shortcut"
|
||||||
|
>{{ item.shortcut }}</kbd>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.app-menu {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: var(--lt-space-xs, 2px);
|
||||||
|
color: var(--lt-fg-muted);
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: var(--lt-radius, 4px);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__button:hover,
|
||||||
|
.app-menu__button--open {
|
||||||
|
color: var(--lt-fg);
|
||||||
|
background: color-mix(in srgb, var(--lt-fg) 8%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__button:focus-visible {
|
||||||
|
outline: 2px solid var(--lt-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__panel {
|
||||||
|
position: absolute;
|
||||||
|
top: 28px;
|
||||||
|
left: 4px;
|
||||||
|
min-width: 260px;
|
||||||
|
max-height: calc(100vh - 40px);
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 4px 0;
|
||||||
|
color: var(--lt-fg);
|
||||||
|
background: var(--lt-bg);
|
||||||
|
border: 1px solid var(--lt-border);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__group + .app-menu__group {
|
||||||
|
margin-top: 4px;
|
||||||
|
padding-top: 4px;
|
||||||
|
border-top: 1px solid var(--lt-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__heading {
|
||||||
|
padding: 2px 12px;
|
||||||
|
font-size: 0.85em;
|
||||||
|
color: var(--lt-fg-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__item {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 4px 12px 4px 20px;
|
||||||
|
cursor: default;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__item--focused {
|
||||||
|
background: var(--lt-editor-selection-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__item--disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__label {
|
||||||
|
flex: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__shortcut {
|
||||||
|
font: inherit;
|
||||||
|
color: var(--lt-fg-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-menu__item--focused .app-menu__shortcut {
|
||||||
|
color: var(--lt-fg);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
173
ui/src/components/menu/menu.ts
Normal file
173
ui/src/components/menu/menu.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
/**
|
||||||
|
* The app menu's model (M3.9): the commands that have a menu path, grouped
|
||||||
|
* by the path's first segment.
|
||||||
|
*
|
||||||
|
* - **Groups** come in Lutra's order (File, Edit, View, Go, Help); a group
|
||||||
|
* Lutra does not know goes before Help, sorted by name. Empty groups are
|
||||||
|
* left out. Known group names come from the catalog.
|
||||||
|
* - **Items** in a group follow {@link ITEM_ORDER}; others come after it,
|
||||||
|
* sorted by label.
|
||||||
|
* - **Labels:** a UI command shows its catalog label; an engine command
|
||||||
|
* shows the rest of its menu path (`File/Close Tab` → `Close Tab`), since
|
||||||
|
* the engine has no catalog and its path is written for menus. Deeper
|
||||||
|
* paths are joined with ` › `.
|
||||||
|
*/
|
||||||
|
import type { PaletteEntry } from "../../commands/store";
|
||||||
|
import { t } from "../../i18n";
|
||||||
|
|
||||||
|
/** One entry of the menu. */
|
||||||
|
export interface MenuItem {
|
||||||
|
/** Command id. */
|
||||||
|
id: string;
|
||||||
|
/** Text shown. */
|
||||||
|
label: string;
|
||||||
|
/** Formatted shortcut, or null. */
|
||||||
|
shortcut: string | null;
|
||||||
|
/** Whether it can run now; disabled items are dimmed and do nothing. */
|
||||||
|
enabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One group of the menu. */
|
||||||
|
export interface MenuGroup {
|
||||||
|
/** The first segment of the menu path, e.g. `File`. */
|
||||||
|
key: string;
|
||||||
|
/** Heading shown. */
|
||||||
|
label: string;
|
||||||
|
/** Items in display order. */
|
||||||
|
items: MenuItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Known groups in display order. */
|
||||||
|
const GROUP_ORDER = ["File", "Edit", "View", "Go", "Help"];
|
||||||
|
|
||||||
|
/** Order of known commands inside their group. */
|
||||||
|
const ITEM_ORDER = [
|
||||||
|
"project.openDialog",
|
||||||
|
"file.save",
|
||||||
|
"file.saveAll",
|
||||||
|
"buffer.close",
|
||||||
|
"project.close",
|
||||||
|
"app.quit",
|
||||||
|
"palette.open",
|
||||||
|
"view.toggleProjectTree",
|
||||||
|
"view.toggleStructure",
|
||||||
|
"find.open",
|
||||||
|
"terminal.toggle",
|
||||||
|
"settings.open",
|
||||||
|
"goto.fileOpen",
|
||||||
|
"goto.classOpen",
|
||||||
|
"goto.symbolOpen",
|
||||||
|
"app.about",
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The heading of a group: catalog text for Lutra's groups, else the name.
|
||||||
|
*
|
||||||
|
* @param key - the first segment of the menu path.
|
||||||
|
*/
|
||||||
|
function groupLabel(key: string): string {
|
||||||
|
switch (key) {
|
||||||
|
case "File":
|
||||||
|
return t("menu.group.file");
|
||||||
|
case "Edit":
|
||||||
|
return t("menu.group.edit");
|
||||||
|
case "View":
|
||||||
|
return t("menu.group.view");
|
||||||
|
case "Go":
|
||||||
|
return t("menu.group.go");
|
||||||
|
case "Help":
|
||||||
|
return t("menu.group.help");
|
||||||
|
default:
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sort rank of a group.
|
||||||
|
*
|
||||||
|
* @param key - the group name.
|
||||||
|
*/
|
||||||
|
function groupRank(key: string): number {
|
||||||
|
const index = GROUP_ORDER.indexOf(key);
|
||||||
|
if (index >= 0) {
|
||||||
|
return key === "Help" ? 1000 : index;
|
||||||
|
}
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sort rank of an item.
|
||||||
|
*
|
||||||
|
* @param id - the command id.
|
||||||
|
*/
|
||||||
|
function itemRank(id: string): number {
|
||||||
|
const index = ITEM_ORDER.indexOf(id);
|
||||||
|
return index >= 0 ? index : ITEM_ORDER.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a menu path into its non-empty segments.
|
||||||
|
*
|
||||||
|
* @param path - for example `File/Save`.
|
||||||
|
*/
|
||||||
|
function segments(path: string): string[] {
|
||||||
|
return path
|
||||||
|
.split("/")
|
||||||
|
.map((part) => part.trim())
|
||||||
|
.filter((part) => part !== "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the menu from the commands the palette knows.
|
||||||
|
*
|
||||||
|
* @param entries - the commands; those without a menu path are left out.
|
||||||
|
* @returns the groups in display order, none empty.
|
||||||
|
*/
|
||||||
|
export function buildMenu(entries: readonly PaletteEntry[]): MenuGroup[] {
|
||||||
|
const groups = new Map<string, MenuItem[]>();
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.menuPath === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const [group, ...rest] = segments(entry.menuPath);
|
||||||
|
if (group === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const label = entry.ui || rest.length === 0 ? entry.label : rest.join(" › ");
|
||||||
|
const items = groups.get(group) ?? [];
|
||||||
|
items.push({ id: entry.id, label, shortcut: entry.shortcut, enabled: entry.enabled });
|
||||||
|
groups.set(group, items);
|
||||||
|
}
|
||||||
|
return [...groups.entries()]
|
||||||
|
.sort(([a], [b]) => groupRank(a) - groupRank(b) || a.localeCompare(b))
|
||||||
|
.map(([key, items]) => ({
|
||||||
|
key,
|
||||||
|
label: groupLabel(key),
|
||||||
|
items: items.sort((a, b) => itemRank(a.id) - itemRank(b.id) || a.label.localeCompare(b.label)),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the next item whose label starts with the typed text, searching
|
||||||
|
* from the item after `from` and wrapping around; when the text is one
|
||||||
|
* character typed again, this cycles through the items with that initial.
|
||||||
|
*
|
||||||
|
* @param labels - item labels in display order.
|
||||||
|
* @param typed - what was typed, case-insensitive.
|
||||||
|
* @param from - index of the focused item, -1 for none.
|
||||||
|
* @returns the index, or -1 when no label matches.
|
||||||
|
*/
|
||||||
|
export function typeAhead(labels: readonly string[], typed: string, from: number): number {
|
||||||
|
const needle = typed.toLocaleLowerCase();
|
||||||
|
if (needle === "" || labels.length === 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
const start = needle.length > 1 ? Math.max(from, 0) : from + 1;
|
||||||
|
for (let step = 0; step < labels.length; step += 1) {
|
||||||
|
const index = (start + step + labels.length) % labels.length;
|
||||||
|
if ((labels[index] ?? "").toLocaleLowerCase().startsWith(needle)) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
"command.key.ctrl": "Ctrl",
|
"command.key.ctrl": "Ctrl",
|
||||||
"command.key.option": "Option",
|
"command.key.option": "Option",
|
||||||
"command.key.shift": "Shift",
|
"command.key.shift": "Shift",
|
||||||
|
"command.menu.open": "Open Main Menu",
|
||||||
"command.palette.open": "Command Palette",
|
"command.palette.open": "Command Palette",
|
||||||
"command.settings.open": "Settings…",
|
"command.settings.open": "Settings…",
|
||||||
"command.unavailable": "{command} cannot run right now",
|
"command.unavailable": "{command} cannot run right now",
|
||||||
|
|
@ -68,6 +69,13 @@
|
||||||
"goto.placeholder.file": "File name or path",
|
"goto.placeholder.file": "File name or path",
|
||||||
"goto.placeholder.symbol": "Function, method, property or constant; Class::member",
|
"goto.placeholder.symbol": "Function, method, property or constant; Class::member",
|
||||||
"goto.switchHint": "Tab switches",
|
"goto.switchHint": "Tab switches",
|
||||||
|
"menu.button": "Main menu",
|
||||||
|
"menu.group.edit": "Edit",
|
||||||
|
"menu.group.file": "File",
|
||||||
|
"menu.group.go": "Go",
|
||||||
|
"menu.group.help": "Help",
|
||||||
|
"menu.group.view": "View",
|
||||||
|
"menu.label": "Main menu",
|
||||||
"notification.close": "Close notification",
|
"notification.close": "Close notification",
|
||||||
"notification.command.failed": "{command} failed: {message}",
|
"notification.command.failed": "{command} failed: {message}",
|
||||||
"notification.project.notLocal": "The chosen folder is not on this computer: {reason}",
|
"notification.project.notLocal": "The chosen folder is not on this computer: {reason}",
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ describe("en.json", () => {
|
||||||
it("uses flat dotted keys of known areas with string values", () => {
|
it("uses flat dotted keys of known areas with string values", () => {
|
||||||
for (const [key, value] of Object.entries(en)) {
|
for (const [key, value] of Object.entries(en)) {
|
||||||
expect(key).toMatch(
|
expect(key).toMatch(
|
||||||
/^(app|command|project|editor|common|palette|theme|recovery|notification|settings|find|goto|structure)\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$/,
|
/^(app|command|project|editor|common|palette|theme|recovery|notification|settings|find|goto|structure|menu)\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$/,
|
||||||
);
|
);
|
||||||
expect(typeof value).toBe("string");
|
expect(typeof value).toBe("string");
|
||||||
expect(value.trim()).not.toBe("");
|
expect(value.trim()).not.toBe("");
|
||||||
|
|
|
||||||
368
ui/tests/menu/AppMenu.test.ts
Normal file
368
ui/tests/menu/AppMenu.test.ts
Normal file
|
|
@ -0,0 +1,368 @@
|
||||||
|
/**
|
||||||
|
* Tests of the app menu (M3.9): the model (`buildMenu` grouping, order and
|
||||||
|
* labels, `typeAhead`), and the component: opening from the button, from
|
||||||
|
* `menu.open` and from a `uiCommand`, shortcuts and dimmed disabled items,
|
||||||
|
* the keyboard (arrows, Home/End, Enter, Escape, type-ahead), running
|
||||||
|
* engine and UI commands from it, and the modal rule (a launcher that any
|
||||||
|
* other command closes). The engine is a fake behind the mocked Tauri
|
||||||
|
* `invoke` and `listen`.
|
||||||
|
*/
|
||||||
|
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||||
|
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { defineComponent, h } from "vue";
|
||||||
|
|
||||||
|
const invoke = vi.hoisted(() => vi.fn());
|
||||||
|
const listen = vi.hoisted(() => vi.fn());
|
||||||
|
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||||
|
vi.mock("@tauri-apps/api/event", () => ({ listen }));
|
||||||
|
|
||||||
|
import { useModalsStore } from "../../src/commands/modals";
|
||||||
|
import { useCommandsStore, type PaletteEntry } from "../../src/commands/store";
|
||||||
|
import { UI_COMMANDS } from "../../src/commands/uiCommands";
|
||||||
|
import AppMenu from "../../src/components/menu/AppMenu.vue";
|
||||||
|
import { buildMenu, typeAhead } from "../../src/components/menu/menu";
|
||||||
|
import CommandPalette from "../../src/components/palette/CommandPalette.vue";
|
||||||
|
import SettingsDialog from "../../src/components/settings/SettingsDialog.vue";
|
||||||
|
|
||||||
|
/** Engine commands the fake lists. */
|
||||||
|
const ENGINE_COMMANDS = [
|
||||||
|
{ id: "app.about", label: "About Lutra", menuPath: "Help/About Lutra", defaultShortcut: null, params: "", enabled: true, ui: false },
|
||||||
|
{ id: "app.quit", label: "Quit", menuPath: "File/Quit", defaultShortcut: "Mod+Q", params: "", enabled: true, ui: false },
|
||||||
|
{ id: "buffer.close", label: "Close Buffer", menuPath: "File/Close Tab", defaultShortcut: "Mod+W", params: "", enabled: false, ui: false },
|
||||||
|
{ id: "buffer.edit", label: "Edit Buffer", menuPath: null, defaultShortcut: null, params: "", enabled: true, ui: false },
|
||||||
|
{ id: "file.save", label: "Save", menuPath: "File/Save", defaultShortcut: "Mod+S", params: "", enabled: true, ui: false },
|
||||||
|
{ id: "file.saveAll", label: "Save All", menuPath: "File/Save All", defaultShortcut: "Mod+Alt+S", params: "", enabled: true, ui: false },
|
||||||
|
{ id: "project.close", label: "Close Project", menuPath: "File/Close Project", defaultShortcut: null, params: "", enabled: false, ui: false },
|
||||||
|
{ id: "project.openDialog", label: "Open Folder…", menuPath: "File/Open Folder…", defaultShortcut: "Mod+O", params: "", enabled: true, ui: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** The engine event callbacks, one per subscription. */
|
||||||
|
let listeners: ((payload: unknown) => void)[];
|
||||||
|
/** Every `engine_execute` call, in order. */
|
||||||
|
let calls: { command: string; params: unknown }[];
|
||||||
|
/** Pinia of the current test. */
|
||||||
|
let pinia: Pinia;
|
||||||
|
/** Mounted components, unmounted after each test. */
|
||||||
|
let mounted: VueWrapper[];
|
||||||
|
|
||||||
|
/** The fake engine's listing: its commands plus the registered UI commands. */
|
||||||
|
function listing(): unknown[] {
|
||||||
|
const registered = calls.find((c) => c.command === "ui.registerCommands")?.params as
|
||||||
|
| { commands: { id: string; labelKey: string; menuPath?: string; defaultShortcut?: string }[] }
|
||||||
|
| undefined;
|
||||||
|
const ui = (registered?.commands ?? []).map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
label: c.labelKey,
|
||||||
|
labelKey: c.labelKey,
|
||||||
|
menuPath: c.menuPath ?? null,
|
||||||
|
defaultShortcut: c.defaultShortcut ?? null,
|
||||||
|
params: "",
|
||||||
|
enabled: true,
|
||||||
|
ui: true,
|
||||||
|
}));
|
||||||
|
return [...ENGINE_COMMANDS, ...ui];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an engine event to every subscriber.
|
||||||
|
*
|
||||||
|
* @param payload - the event.
|
||||||
|
*/
|
||||||
|
async function emit(payload: unknown): Promise<void> {
|
||||||
|
for (const listener of listeners) {
|
||||||
|
listener(payload);
|
||||||
|
}
|
||||||
|
await flushPromises();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Presses a key on the focused element (or the body).
|
||||||
|
*
|
||||||
|
* @param init - key event properties.
|
||||||
|
*/
|
||||||
|
async function press(init: KeyboardEventInit): Promise<void> {
|
||||||
|
const target = document.activeElement ?? document.body;
|
||||||
|
target.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...init }));
|
||||||
|
await flushPromises();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The `menu.open` shortcut, `Alt+M`. */
|
||||||
|
const MENU_KEY: KeyboardEventInit = { key: "m", code: "KeyM", altKey: true };
|
||||||
|
|
||||||
|
/** A focusable button standing in for the editor. */
|
||||||
|
const Host = defineComponent({
|
||||||
|
setup: () => () => h("button", { id: "host-button" }, "host"),
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Mounts the editor stand-in, the menu and the other modals, and starts the commands. */
|
||||||
|
async function mountApp(): Promise<VueWrapper> {
|
||||||
|
const host = mount(Host, { attachTo: document.body });
|
||||||
|
const menu = mount(AppMenu, { attachTo: document.body, global: { plugins: [pinia] } });
|
||||||
|
const palette = mount(CommandPalette, { attachTo: document.body, global: { plugins: [pinia] } });
|
||||||
|
const settings = mount(SettingsDialog, { attachTo: document.body, global: { plugins: [pinia] } });
|
||||||
|
mounted.push(host, menu, palette, settings);
|
||||||
|
await useCommandsStore(pinia).start();
|
||||||
|
await flushPromises();
|
||||||
|
document.getElementById("host-button")?.focus();
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the dropdown is shown. */
|
||||||
|
function menuShown(): boolean {
|
||||||
|
return document.querySelector("[data-test=menu]") !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The command id of the focused item, or null. */
|
||||||
|
function focusedCommand(): string | null {
|
||||||
|
const active = document.activeElement;
|
||||||
|
return active instanceof HTMLElement ? (active.dataset.command ?? null) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The items' command ids in display order. */
|
||||||
|
function itemIds(): string[] {
|
||||||
|
return [...document.querySelectorAll<HTMLElement>("[data-test=menu-item]")].map((el) => el.dataset.command ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a palette entry for the model tests.
|
||||||
|
*
|
||||||
|
* @param id - command id.
|
||||||
|
* @param menuPath - its menu path.
|
||||||
|
* @param ui - whether it is a UI command.
|
||||||
|
*/
|
||||||
|
function entry(id: string, menuPath: string | null, ui = false): PaletteEntry {
|
||||||
|
return { id, label: `label of ${id}`, shortcut: null, enabled: true, menuPath, ui };
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
pinia = createPinia();
|
||||||
|
setActivePinia(pinia);
|
||||||
|
listeners = [];
|
||||||
|
calls = [];
|
||||||
|
mounted = [];
|
||||||
|
listen.mockReset();
|
||||||
|
listen.mockImplementation((_name: string, callback: (event: { payload: unknown }) => void) => {
|
||||||
|
listeners.push((payload) => {
|
||||||
|
callback({ payload });
|
||||||
|
});
|
||||||
|
return Promise.resolve(() => undefined);
|
||||||
|
});
|
||||||
|
invoke.mockReset();
|
||||||
|
invoke.mockImplementation((cmd: string, args?: { command: string; params: unknown }) => {
|
||||||
|
if (cmd === "engine_list_commands") {
|
||||||
|
return Promise.resolve(listing());
|
||||||
|
}
|
||||||
|
if (cmd === "engine_execute" && args) {
|
||||||
|
calls.push({ command: args.command, params: args.params });
|
||||||
|
if (args.command === "settings.list") {
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
if (args.command === "settings.get") {
|
||||||
|
return Promise.resolve({ values: {} });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.resolve(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
useCommandsStore(pinia).stop();
|
||||||
|
for (const wrapper of mounted) {
|
||||||
|
wrapper.unmount();
|
||||||
|
}
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("buildMenu", () => {
|
||||||
|
it("groups by the first segment in Lutra's order, unknown groups before Help", () => {
|
||||||
|
const groups = buildMenu([
|
||||||
|
entry("app.about", "Help/About Lutra"),
|
||||||
|
entry("x.tool", "Tools/Thing"),
|
||||||
|
entry("goto.fileOpen", "Go/File…", true),
|
||||||
|
entry("file.save", "File/Save"),
|
||||||
|
entry("palette.open", "View/Command Palette", true),
|
||||||
|
entry("buffer.edit", null),
|
||||||
|
]);
|
||||||
|
expect(groups.map((g) => g.key)).toEqual(["File", "View", "Go", "Tools", "Help"]);
|
||||||
|
expect(groups.map((g) => g.label)).toEqual(["File", "View", "Go", "Tools", "Help"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("orders known items and sorts the others by label after them", () => {
|
||||||
|
const groups = buildMenu([
|
||||||
|
entry("zzz.other", "File/Another"),
|
||||||
|
entry("app.quit", "File/Quit"),
|
||||||
|
entry("project.openDialog", "File/Open Folder…"),
|
||||||
|
entry("aaa.other", "File/Bother"),
|
||||||
|
entry("file.save", "File/Save"),
|
||||||
|
]);
|
||||||
|
expect(groups[0]?.items.map((i) => i.id)).toEqual(["project.openDialog", "file.save", "app.quit", "zzz.other", "aaa.other"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("labels engine commands by their path and UI commands by their catalog label", () => {
|
||||||
|
const groups = buildMenu([
|
||||||
|
entry("buffer.close", "File/Close Tab"),
|
||||||
|
entry("deep.one", "File/Recent/Project A"),
|
||||||
|
entry("settings.open", "View/Settings…", true),
|
||||||
|
]);
|
||||||
|
expect(groups[0]?.items.map((i) => i.label)).toEqual(["Close Tab", "Recent › Project A"]);
|
||||||
|
expect(groups[1]?.items.map((i) => i.label)).toEqual(["label of settings.open"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("skips empty paths and trims segments", () => {
|
||||||
|
const groups = buildMenu([entry("a.b", "/"), entry("c.d", ""), entry("e.f", " File / Save ")]);
|
||||||
|
expect(groups).toHaveLength(1);
|
||||||
|
expect(groups[0]?.items[0]?.label).toBe("Save");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("typeAhead", () => {
|
||||||
|
const labels = ["Open Folder…", "Save", "Save All", "Close Tab", "Settings…"];
|
||||||
|
|
||||||
|
it("finds the next item with the typed initial and cycles", () => {
|
||||||
|
expect(typeAhead(labels, "s", 0)).toBe(1);
|
||||||
|
expect(typeAhead(labels, "s", 1)).toBe(2);
|
||||||
|
expect(typeAhead(labels, "s", 4)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("matches longer text from the focused item on, case-insensitively", () => {
|
||||||
|
expect(typeAhead(labels, "SE", 1)).toBe(4);
|
||||||
|
expect(typeAhead(labels, "sa", 1)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns -1 without a match", () => {
|
||||||
|
expect(typeAhead(labels, "x", 0)).toBe(-1);
|
||||||
|
expect(typeAhead([], "s", -1)).toBe(-1);
|
||||||
|
expect(typeAhead(labels, "", 0)).toBe(-1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AppMenu", () => {
|
||||||
|
it("registers menu.open with its shortcut and gives commands menu paths", () => {
|
||||||
|
const spec = UI_COMMANDS.find((c) => c.id === "menu.open");
|
||||||
|
expect(spec?.defaultShortcut).toBe("Alt+M");
|
||||||
|
expect(UI_COMMANDS.find((c) => c.id === "settings.open")?.menuPath).toBe("View/Settings…");
|
||||||
|
expect(UI_COMMANDS.find((c) => c.id === "goto.fileOpen")?.menuPath).toBe("Go/File…");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opens from the button with groups, shortcuts and dimmed disabled items", async () => {
|
||||||
|
const menu = await mountApp();
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
await menu.find("[data-test=menu-button]").trigger("click");
|
||||||
|
await flushPromises();
|
||||||
|
expect(menuShown()).toBe(true);
|
||||||
|
expect(menu.find("[data-test=menu-button]").attributes("aria-expanded")).toBe("true");
|
||||||
|
const headings = [...document.querySelectorAll("[data-test=menu-group]")].map((g) => g.querySelector(".app-menu__heading")?.textContent.trim());
|
||||||
|
expect(headings).toEqual(["File", "View", "Go", "Help"]);
|
||||||
|
expect(itemIds()).toEqual([
|
||||||
|
"project.openDialog",
|
||||||
|
"file.save",
|
||||||
|
"file.saveAll",
|
||||||
|
"buffer.close",
|
||||||
|
"project.close",
|
||||||
|
"app.quit",
|
||||||
|
"palette.open",
|
||||||
|
"view.toggleProjectTree",
|
||||||
|
"view.toggleStructure",
|
||||||
|
"find.open",
|
||||||
|
"settings.open",
|
||||||
|
"goto.fileOpen",
|
||||||
|
"goto.classOpen",
|
||||||
|
"goto.symbolOpen",
|
||||||
|
"app.about",
|
||||||
|
]);
|
||||||
|
const close = document.querySelector("[data-command='buffer.close']");
|
||||||
|
expect(close?.textContent).toContain("Close Tab");
|
||||||
|
expect(close?.querySelector("[data-test=menu-shortcut]")?.textContent).toBe("Ctrl+W");
|
||||||
|
expect(close?.getAttribute("aria-disabled")).toBe("true");
|
||||||
|
expect(close?.classList.contains("app-menu__item--disabled")).toBe(true);
|
||||||
|
expect(document.querySelector("[data-command='settings.open']")?.textContent).toContain("Settings…");
|
||||||
|
expect(focusedCommand()).toBe("project.openDialog");
|
||||||
|
await menu.find("[data-test=menu-button]").trigger("click");
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opens with Alt+M and from a uiCommand", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
expect(menuShown()).toBe(true);
|
||||||
|
await press({ key: "Escape" });
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
expect(document.activeElement?.id).toBe("host-button");
|
||||||
|
await emit({ kind: "uiCommand", id: "menu.open", params: {} });
|
||||||
|
expect(menuShown()).toBe(true);
|
||||||
|
expect(useModalsStore(pinia).current).toBe("menu");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("moves with arrows, Home and End, wrapping", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
await press({ key: "ArrowUp" });
|
||||||
|
expect(focusedCommand()).toBe("app.about");
|
||||||
|
await press({ key: "ArrowDown" });
|
||||||
|
expect(focusedCommand()).toBe("project.openDialog");
|
||||||
|
await press({ key: "ArrowDown" });
|
||||||
|
expect(focusedCommand()).toBe("file.save");
|
||||||
|
await press({ key: "End" });
|
||||||
|
expect(focusedCommand()).toBe("app.about");
|
||||||
|
await press({ key: "Home" });
|
||||||
|
expect(focusedCommand()).toBe("project.openDialog");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("jumps by typed text", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
await press({ key: "s" });
|
||||||
|
expect(focusedCommand()).toBe("file.save");
|
||||||
|
await press({ key: "e" });
|
||||||
|
expect(focusedCommand()).toBe("settings.open");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs Settings with Enter: the menu closes and the dialog opens", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
await press({ key: "s" });
|
||||||
|
await press({ key: "e" });
|
||||||
|
await press({ key: "Enter" });
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
expect(document.querySelector("[data-test=settings]")).not.toBeNull();
|
||||||
|
expect(useModalsStore(pinia).current).toBe("settings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs an engine command on click and ignores disabled items", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
document.querySelector<HTMLElement>("[data-command='project.close']")?.click();
|
||||||
|
await flushPromises();
|
||||||
|
expect(menuShown()).toBe(true);
|
||||||
|
expect(calls.map((c) => c.command)).not.toContain("project.close");
|
||||||
|
await press({ key: "End" });
|
||||||
|
document.querySelector<HTMLElement>("[data-command='project.openDialog']")?.click();
|
||||||
|
await flushPromises();
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
expect(calls.map((c) => c.command)).toContain("project.openDialog");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("closes on a click outside", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
document.querySelector("[data-test=menu-backdrop]")?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true }));
|
||||||
|
await flushPromises();
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is a launcher: another command or modal closes it", async () => {
|
||||||
|
await mountApp();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
await press({ key: "s", code: "KeyS", ctrlKey: true });
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
expect(calls.map((c) => c.command)).toContain("file.save");
|
||||||
|
await press(MENU_KEY);
|
||||||
|
await emit({ kind: "uiCommand", id: "palette.open", params: {} });
|
||||||
|
expect(menuShown()).toBe(false);
|
||||||
|
expect(document.querySelector("[data-test=palette]")).not.toBeNull();
|
||||||
|
await press(MENU_KEY);
|
||||||
|
expect(document.querySelector("[data-test=palette]")).toBeNull();
|
||||||
|
expect(menuShown()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -45,13 +45,13 @@ let mounted: VueWrapper[];
|
||||||
*/
|
*/
|
||||||
function listing(): unknown[] {
|
function listing(): unknown[] {
|
||||||
const registered = calls.find((c) => c.command === "ui.registerCommands")?.params as
|
const registered = calls.find((c) => c.command === "ui.registerCommands")?.params as
|
||||||
| { commands: { id: string; labelKey: string; defaultShortcut?: string }[] }
|
| { commands: { id: string; labelKey: string; menuPath?: string; defaultShortcut?: string }[] }
|
||||||
| undefined;
|
| undefined;
|
||||||
const ui = (registered?.commands ?? []).map((c) => ({
|
const ui = (registered?.commands ?? []).map((c) => ({
|
||||||
id: c.id,
|
id: c.id,
|
||||||
label: c.labelKey,
|
label: c.labelKey,
|
||||||
labelKey: c.labelKey,
|
labelKey: c.labelKey,
|
||||||
menuPath: null,
|
menuPath: c.menuPath ?? null,
|
||||||
defaultShortcut: c.defaultShortcut ?? null,
|
defaultShortcut: c.defaultShortcut ?? null,
|
||||||
params: "",
|
params: "",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
@ -166,7 +166,7 @@ describe("command store", () => {
|
||||||
expect(store.infos.filter((c) => c.ui === true).map((c) => c.id)).toEqual(UI_COMMANDS.map((c) => c.id));
|
expect(store.infos.filter((c) => c.ui === true).map((c) => c.id)).toEqual(UI_COMMANDS.map((c) => c.id));
|
||||||
expect(store.entries.map((e) => e.id)).not.toContain("buffer.edit");
|
expect(store.entries.map((e) => e.id)).not.toContain("buffer.edit");
|
||||||
const toggle = store.entries.find((e) => e.id === "view.toggleProjectTree");
|
const toggle = store.entries.find((e) => e.id === "view.toggleProjectTree");
|
||||||
expect(toggle).toEqual({ id: "view.toggleProjectTree", label: "Show or Hide Project", shortcut: "Ctrl+1", enabled: false });
|
expect(toggle).toEqual({ id: "view.toggleProjectTree", label: "Show or Hide Project", shortcut: "Ctrl+1", enabled: false, menuPath: "View/Project", ui: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps the UI commands when the engine refuses them, with an error toast", async () => {
|
it("keeps the UI commands when the engine refuses them, with an error toast", async () => {
|
||||||
|
|
@ -265,6 +265,7 @@ describe("CommandPalette", () => {
|
||||||
"goto.fileOpen",
|
"goto.fileOpen",
|
||||||
"goto.symbolOpen",
|
"goto.symbolOpen",
|
||||||
"project.openDialog",
|
"project.openDialog",
|
||||||
|
"menu.open",
|
||||||
"app.quit",
|
"app.quit",
|
||||||
"editor.reveal",
|
"editor.reveal",
|
||||||
"settings.open",
|
"settings.open",
|
||||||
|
|
@ -286,7 +287,7 @@ describe("CommandPalette", () => {
|
||||||
const wrapper = await mountPalette();
|
const wrapper = await mountPalette();
|
||||||
await press(PALETTE_KEY);
|
await press(PALETTE_KEY);
|
||||||
await type(wrapper, "o");
|
await type(wrapper, "o");
|
||||||
expect(rows(wrapper).slice(0, 3)).toEqual(["project.openDialog", "find.open", "palette.open"]);
|
expect(rows(wrapper).slice(0, 3)).toEqual(["project.openDialog", "menu.open", "find.open"]);
|
||||||
await type(wrapper, "open f");
|
await type(wrapper, "open f");
|
||||||
expect(rows(wrapper)[0]).toBe("project.openDialog");
|
expect(rows(wrapper)[0]).toBe("project.openDialog");
|
||||||
await press({ key: "ArrowDown" });
|
await press({ key: "ArrowDown" });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue