Add the command palette, Write formatting keys, and platform labels
Phase 5-2. - Ctrl+Shift+P opens the command palette: every workbench command with its shortcut, then the plugin commands (UI-048). - In Write, Ctrl+B, Ctrl+I, Ctrl+Shift+X, and Ctrl+Shift+H format the selection, and Ctrl+K inserts a Markdown link. The Format menu shows these shortcuts. - Ctrl+\ toggles the side pane. It matches the physical key on every keyboard layout. Ctrl+B now belongs to Write. - Help lists every shortcut in groups, open by default. The list comes from the command table. - src/lib/ui/shortcuts.ts writes shortcut labels for the platform: Ctrl+Shift+P on Windows and Linux, and the macOS symbols on a Mac. The catalog uses placeholders, so no translation contains "Ctrl". - 19 new catalog rows, and 10 rows converted to placeholders, in French, Japanese, and Simplified Chinese. - Docs: UI-048, the user guide keyboard tables, and a label rule in ui-design.md. New tests: layout/commands, tests/unit/ui/shortcuts.spec.ts, and new cases in workbenchKeys.spec.ts. Tests that read the old labels or pressed Ctrl+B for the side pane now use the new names and Ctrl+\. The smoke harness raises the resource timing buffer to 5000 entries. The new modules pushed the CodeMirror language module past the default 250 entries, so editor/markdownPaste could not find its URL.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { keys } from "$lib/ui/shortcuts";
|
||||
import { tick, untrack } from "svelte";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
@@ -81,7 +82,7 @@
|
||||
<TabBar {tabs} activePath={active} onSelect={select} onClose={close} onCloseTabs={close}
|
||||
onMove={move} onPin={pinPluginEditor} fileActions={() => []} tabActions={actions}
|
||||
tabDragData={dragData} onDropTab={(data, index) => void receive(data, index)} />
|
||||
<IconButton icon="plus" label={$t("New browser tab (Ctrl T)")} disabled={!browser?.newTab || opening} onclick={() => void newTab()} />
|
||||
<IconButton icon="plus" label={$t("New browser tab ({shortcut})", { shortcut: keys("Mod+T") })} disabled={!browser?.newTab || opening} onclick={() => void newTab()} />
|
||||
<div class="window-drag-space" data-tauri-drag-region></div>
|
||||
<WindowControls onError={message => error = message} />
|
||||
</header>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts" module>
|
||||
export type PaletteCommand = { id: string; label: string; detail?: string; shortcut?: string; run: () => void };
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
// The command palette (Ctrl+Shift+P): every app command and plugin command, with its shortcut.
|
||||
import { t } from "$lib/i18n";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let { commands, onClose }: { commands: PaletteCommand[]; onClose: () => void } = $props();
|
||||
let query = $state("");
|
||||
let selected = $state(0);
|
||||
let dialog: HTMLDialogElement;
|
||||
let input: HTMLInputElement;
|
||||
let picked = false;
|
||||
// Every word of the query must appear in the label or the detail.
|
||||
const matches = $derived(commands.filter(command => {
|
||||
const text = `${command.label} ${command.detail ?? ""}`.toLowerCase();
|
||||
return query.toLowerCase().split(/\s+/).every(part => text.includes(part));
|
||||
}));
|
||||
function pick(command?: PaletteCommand) {
|
||||
if (!command) return;
|
||||
picked = true;
|
||||
onClose();
|
||||
// Run after the dialog closes, so the command can move focus or open another dialog.
|
||||
queueMicrotask(command.run);
|
||||
}
|
||||
onMount(() => {
|
||||
const origin = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
dialog.showModal(); input.focus();
|
||||
return () => { if (!picked && origin?.isConnected) origin.focus({ preventScroll: true }); };
|
||||
});
|
||||
</script>
|
||||
|
||||
<dialog class="rs-picker" bind:this={dialog} aria-label={$t("Commands")} onpointerdown={(event) => {
|
||||
const bounds = dialog.getBoundingClientRect();
|
||||
if (event.target === dialog && (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)) onClose();
|
||||
}} oncancel={onClose}>
|
||||
<input bind:this={input} bind:value={query} oninput={() => selected = 0} aria-label={$t("Find a command")} placeholder={$t("Find a command…")}
|
||||
aria-controls="command-results" aria-activedescendant={matches.length ? `command-${selected}` : undefined} onkeydown={(event) => {
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault(); selected = Math.max(0, Math.min(matches.length - 1, selected + (event.key === "ArrowDown" ? 1 : -1)));
|
||||
dialog.querySelector(`[data-index="${selected}"]`)?.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
if (event.key === "Enter") { event.preventDefault(); pick(matches[selected]); }
|
||||
}} />
|
||||
<div class="results" id="command-results">
|
||||
{#each matches as command, index (command.id)}
|
||||
<button class="rs-picker-row" id={`command-${index}`} data-index={index} aria-current={selected === index ? 'true' : undefined} onclick={() => pick(command)}>
|
||||
<span class="command-label">{command.label}{#if command.detail}<span class="rs-picker-hint">{command.detail}</span>{/if}</span>
|
||||
{#if command.shortcut}<kbd>{command.shortcut}</kbd>{/if}
|
||||
</button>
|
||||
{/each}
|
||||
{#if !matches.length}<p>{$t("No matching commands.")}</p>{/if}
|
||||
</div>
|
||||
<footer><span>{$t("{count} commands", { count: commands.length })}</span> <span>{$t("↑ ↓ select · Enter {action} · Esc close", { action: $t("run") })}</span></footer>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog { margin-top: 12vh; width: min(640px, 85vw); }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
input { width: 100%; padding: 16px; border: 0; background: var(--rs-bg); color: var(--rs-text-strong); }
|
||||
.results { max-height: 50vh; overflow: auto; }
|
||||
.results p { margin: 12px 14px; color: var(--rs-text-dim); }
|
||||
.command-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
||||
.command-label .rs-picker-hint { display: inline; margin-left: 8px; }
|
||||
kbd { flex: 0 0 auto; color: var(--rs-text-dim); font: 12px var(--rs-font-ui); white-space: nowrap; }
|
||||
footer { padding: 10px 14px; display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--rs-border); color: var(--rs-text-dim); font-size: var(--rs-settings-description-size); }
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { commandShortcut } from "./workbenchKeys";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import type { GitLineInfo } from "$lib/git/contracts";
|
||||
import FindPanel from "$lib/editor/FindPanel.svelte";
|
||||
@@ -158,13 +159,13 @@
|
||||
<div class="welcome-actions">
|
||||
{#if hasWorkspace}
|
||||
<div class="welcome-row">
|
||||
<button onclick={onNewFile}><Icon icon="file-plus" /> {$t("New file")} <kbd>Ctrl N</kbd></button>
|
||||
<button onclick={onNewFile}><Icon icon="file-plus" /> {$t("New file")} <kbd>{commandShortcut("new-file")}</kbd></button>
|
||||
{#if onNewNote}<button onclick={onNewNote}><Icon icon="pen" /> {$t("New note")}</button>{/if}
|
||||
<button onclick={onQuickOpen}><Icon icon="search" /> {$t("Find file")} <kbd>Ctrl P</kbd></button>
|
||||
<button onclick={onQuickOpen}><Icon icon="search" /> {$t("Find file")} <kbd>{commandShortcut("quick-open")}</kbd></button>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="welcome-row">
|
||||
<button onclick={onOpenWorkspace}><Icon icon="folder-open" /> {$t("Open folder")} <kbd>Ctrl O</kbd></button>
|
||||
<button onclick={onOpenWorkspace}><Icon icon="folder-open" /> {$t("Open folder")} <kbd>{commandShortcut("open-workspace")}</kbd></button>
|
||||
{#if onOpenBrowser}<button onclick={onOpenBrowser} disabled={browserOpening}><Icon icon="globe" /> {browserOpening ? $t("Opening browser…") : $t("Open browser")}</button>{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -200,7 +201,7 @@
|
||||
{ value: "Ide", label: $t("IDE"), icon: "code" },
|
||||
{ value: "Writing", label: $t("Writer"), icon: "text" },
|
||||
]}
|
||||
shortcut=" (Ctrl E)"
|
||||
shortcut={` (${commandShortcut("toggle-layout")})`}
|
||||
onchange={(mode) => { if (mode !== chrome) onToggleChrome?.(); }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import FileTree from "./FileTree.svelte";
|
||||
import SearchPane from "./SearchPane.svelte";
|
||||
import BookmarksPane from "./BookmarksPane.svelte";
|
||||
import { commandShortcut } from "./workbenchKeys";
|
||||
|
||||
type Props = {
|
||||
workspace: WorkspaceInfo | null;
|
||||
@@ -74,8 +75,8 @@
|
||||
<span class="ws">{workspace ? workspace.name : $t("No workspace")}</span>
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<IconButton icon="help" label={$t("Help and about (F1)")} onclick={onHelp} />
|
||||
<IconButton icon="settings" label={$t("Settings (Ctrl+,)")} onclick={onSettings} />
|
||||
<IconButton icon="help" label={$t("Help and about ({shortcut})", { shortcut: commandShortcut("help") })} onclick={onHelp} />
|
||||
<IconButton icon="settings" label={$t("Settings ({shortcut})", { shortcut: commandShortcut("settings") })} onclick={onSettings} />
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { keys } from "$lib/ui/shortcuts";
|
||||
import { tick } from "svelte";
|
||||
import type { OutlineItem } from "$lib/workspace/outline";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
@@ -51,7 +52,7 @@
|
||||
<section class="outline" aria-label={$t("Outline")} tabindex="0" bind:this={pane} onkeydown={keydown}>
|
||||
<div class="pane-label">
|
||||
<span>{$t("Outline")}</span>
|
||||
<IconButton icon="search" label={$t("Find in outline (Ctrl+F)")} active={searchOpen} onclick={() => void openSearch()} />
|
||||
<IconButton icon="search" label={$t("Find in outline ({shortcut})", { shortcut: keys("Mod+F") })} active={searchOpen} onclick={() => void openSearch()} />
|
||||
</div>
|
||||
{#if searchOpen}
|
||||
<div class="rs-find-bar outline-search">
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
import { DEFAULT_SETTINGS, MIN_AUTOSAVE_SECONDS, MAX_AUTOSAVE_SECONDS, validAutosaveSeconds, type AppSettings } from "$lib/workspace/settings";
|
||||
import { license } from "../../../package.json";
|
||||
import { appVersion as version } from "../appVersion";
|
||||
import { COMMAND_LABELS, OTHER_SHORTCUTS, commandShortcut, shortcutKeys, type WorkbenchCommand } from "./workbenchKeys";
|
||||
import { isMac } from "$lib/ui/shortcuts";
|
||||
// Help lists every shortcut: the workbench commands, then the editor and file tree shortcuts.
|
||||
const shortcutSections = (() => {
|
||||
const general = (Object.keys(COMMAND_LABELS) as WorkbenchCommand[]).map(command => ({ label: COMMAND_LABELS[command], keys: commandShortcut(command) })).filter(item => item.keys);
|
||||
const others = new Map<string, { label: string; keys: string }[]>();
|
||||
for (const item of OTHER_SHORTCUTS) others.set(item.section, [...(others.get(item.section) ?? []), { label: item.label, keys: shortcutKeys(isMac() && item.macKeys ? item.macKeys : item.keys) }]);
|
||||
return [{ name: "General", items: general }, ...[...others].map(([name, items]) => ({ name, items }))];
|
||||
})();
|
||||
|
||||
let { settings, help = false, standalone = false, windowError = "", windowControls, onSave, onClose }: {
|
||||
settings: AppSettings;
|
||||
@@ -151,7 +160,7 @@
|
||||
<div class="interval"><input id="autosave-seconds" type="number" min={MIN_AUTOSAVE_SECONDS} max={MAX_AUTOSAVE_SECONDS} step="1" required disabled={!settings.autosaveEnabled} aria-describedby="interval-description" aria-invalid={!!error} bind:value={seconds} onchange={changeInterval} /><span>{$t("seconds")}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="note">{settings.autosaveEnabled ? $t("Only changed files are saved.") : $t("Auto-save is off. Use Ctrl+S to save your changes.")} {$t("Disk conflicts keep your edits for review.")}</p>
|
||||
<p class="note">{settings.autosaveEnabled ? $t("Only changed files are saved.") : $t("Auto-save is off. Use {shortcut} to save your changes.", { shortcut: commandShortcut("save") })} {$t("Disk conflicts keep your edits for review.")}</p>
|
||||
<div class="section-footer"><button class="text-button" onclick={() => { seconds = DEFAULT_SETTINGS.autosaveSeconds; apply({ ...DEFAULT_SETTINGS }); }}>{$t("Restore defaults")}</button><span>{$t("Default: every 5 seconds")}</span></div>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<p class="saved" role="status">{message}</p>
|
||||
@@ -166,9 +175,14 @@
|
||||
{:else}
|
||||
<div class="brand"><img src="/runestone.svg" alt="" width="88" height="88" /><h2>RuneStone</h2><p>{$t("Version {version}", { version })}</p></div>
|
||||
<div class="card help-card">
|
||||
<details><summary><Icon icon="book-open" /> {$t("Get started")}</summary><div class="help-copy"><p>{$t("Use the folder button to open a workspace or create one. Your notes and scripts stay as ordinary files on disk.")}</p><p>{$t("Use the + beside the tabs for a new tab. Press Ctrl+N to create a file, or Ctrl+P to find one.")}</p><p>{$t("Press Ctrl+E to switch between writing and source editing. Use the terminal button to work with a shell beside your files.")}</p></div></details>
|
||||
<details><summary><Icon icon="save" /> {$t("Save your work")}</summary><div class="help-copy"><p>{$t("Auto-save saves changed files at the interval in Settings → General. Ctrl+S saves the active file immediately.")}</p><p>{$t("If another app changes a file, RuneStone keeps your edits and offers both versions for review.")}</p></div></details>
|
||||
<details><summary><Icon icon="code" /> {$t("Keyboard shortcuts")}</summary><dl><div><dt>{$t("Open a workspace")}</dt><dd><kbd>Ctrl+O</kbd></dd></div><div><dt>{$t("Find a file")}</dt><dd><kbd>Ctrl+P</kbd></dd></div><div><dt>{$t("Save the active file")}</dt><dd><kbd>Ctrl+S</kbd></dd></div><div><dt>{$t("Search the workspace")}</dt><dd><kbd>Ctrl+Shift+F</kbd></dd></div><div><dt>{$t("Open settings")}</dt><dd><kbd>Ctrl+,</kbd></dd></div><div><dt>{$t("Help and about")}</dt><dd><kbd>F1</kbd></dd></div></dl></details>
|
||||
<details><summary><Icon icon="book-open" /> {$t("Get started")}</summary><div class="help-copy"><p>{$t("Use the folder button to open a workspace or create one. Your notes and scripts stay as ordinary files on disk.")}</p><p>{$t("Use the + beside the tabs for a new tab. Press {newFile} to create a file, or {quickOpen} to find one.", { newFile: commandShortcut("new-file"), quickOpen: commandShortcut("quick-open") })}</p><p>{$t("Press {shortcut} to switch between writing and source editing. Use the terminal button to work with a shell beside your files.", { shortcut: commandShortcut("toggle-layout") })}</p></div></details>
|
||||
<details><summary><Icon icon="save" /> {$t("Save your work")}</summary><div class="help-copy"><p>{$t("Auto-save saves changed files at the interval in Settings → General. {shortcut} saves the active file immediately.", { shortcut: commandShortcut("save") })}</p><p>{$t("If another app changes a file, RuneStone keeps your edits and offers both versions for review.")}</p></div></details>
|
||||
<details open><summary><Icon icon="code" /> {$t("Keyboard shortcuts")}</summary>
|
||||
{#each shortcutSections as section (section.name)}
|
||||
<h3 class="shortcut-section">{$t(section.name)}</h3>
|
||||
<dl>{#each section.items as item (item.label)}<div><dt>{$t(item.label)}</dt><dd><kbd>{item.keys}</kbd></dd></div>{/each}</dl>
|
||||
{/each}
|
||||
</details>
|
||||
</div>
|
||||
<p class="about-note">{$t("RuneStone is under development. Maintained by kwyvern-gh.")}</p>
|
||||
{/if}
|
||||
@@ -233,6 +247,7 @@
|
||||
.help-copy p:first-child { margin-top: 0; }
|
||||
dl div { display: flex; justify-content: space-between; gap: 12px; margin: 10px 0; }
|
||||
dd { margin: 0; }
|
||||
.shortcut-section { margin: 4px 0 0 28px; font-size: 12px; color: var(--rs-text-dim); text-transform: none; }
|
||||
kbd { font-family: var(--rs-font-mono); color: var(--rs-text-dim); }
|
||||
.about-note { text-align: center; margin: 20px 0 0; }
|
||||
@media (max-width: 660px) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { t } from "$lib/i18n";
|
||||
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
|
||||
import type PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
||||
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup } from "$lib/plugins/external";
|
||||
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup, pluginTools, installedPlugins, runPluginCommand } from "$lib/plugins/external";
|
||||
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
|
||||
import { pluginSidebar, closePluginSidebar, pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginFileOpen, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external";
|
||||
import { onMount, onDestroy, tick, untrack } from "svelte";
|
||||
@@ -26,6 +26,7 @@
|
||||
import { requestText } from "$lib/workspace/dialogs.svelte";
|
||||
import TextDialog from "./TextDialog.svelte";
|
||||
import QuickOpen from "./QuickOpen.svelte";
|
||||
import CommandPalette, { type PaletteCommand } from "./CommandPalette.svelte";
|
||||
import TemplateManager from "./TemplateManager.svelte";
|
||||
import WorkspacePicker from "./WorkspacePicker.svelte";
|
||||
import SettingsDialog from "./SettingsDialog.svelte";
|
||||
@@ -35,7 +36,7 @@
|
||||
import { TAB_TRANSFER_ID, cancelTabTransfer, finishTabTransfer, offerTabTransfer, onTabTransferAccepted, parseTabTransfer, takeTabTransfer } from "$lib/workspace/tabTransfer";
|
||||
import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout, type WorkbenchLayout } from "$lib/workspace/workbenchLayout";
|
||||
import type FileTree from "./FileTree.svelte";
|
||||
import { preferenceKeys, workbenchCommand, type WorkbenchCommand } from "./workbenchKeys";
|
||||
import { COMMAND_LABELS, commandShortcut, preferenceKeys, workbenchCommand, type WorkbenchCommand } from "./workbenchKeys";
|
||||
import type EditorPane from "./EditorPane.svelte";
|
||||
import WorkbenchHeader from "./WorkbenchHeader.svelte";
|
||||
import PluginRibbon from "./PluginRibbon.svelte";
|
||||
@@ -147,6 +148,19 @@
|
||||
let documentPanes = $state(initialDocumentPanes());
|
||||
const reading = $derived(documentPanes.panes.find(pane => pane.id === documentPanes.active)?.reading ?? false);
|
||||
let quickOpen = $state(false);
|
||||
let palette = $state(false);
|
||||
/** The commands of the palette: the app commands that apply here, then the plugin commands. */
|
||||
function paletteCommands(): PaletteCommand[] {
|
||||
const hidden = new Set<WorkbenchCommand>(["command-palette", ...(terminalEnabled ? [] : ["toggle-terminal" as const]), ...(workspace ? [] : ["quick-open" as const])]);
|
||||
const app = (Object.keys(COMMAND_LABELS) as WorkbenchCommand[]).filter(command => !hidden.has(command)).map(command => ({
|
||||
id: command, label: $t(COMMAND_LABELS[command]), shortcut: commandShortcut(command) || undefined, run: () => { runCommand(command); },
|
||||
}));
|
||||
const plugins = $pluginTools.filter(tool => tool.kind === "command" && tool.surface === "commands").map(tool => ({
|
||||
id: `plugin:${tool.owner}:${tool.id}`, label: tool.title, detail: $installedPlugins.plugins.find(row => row.manifest.id === tool.owner)?.manifest.name ?? tool.owner,
|
||||
run: () => { void runPluginCommand(tool.owner, tool.id).catch(reason => error = String(reason)); },
|
||||
}));
|
||||
return [...app, ...plugins];
|
||||
}
|
||||
let templateManager = $state(false);
|
||||
let terminalStarted = $state(false);
|
||||
let terminalMaximized = $state(false);
|
||||
@@ -858,6 +872,7 @@
|
||||
selectWorkingTab(workingTabs[next].relPath);
|
||||
return true;
|
||||
}
|
||||
case "command-palette": palette = true; return true;
|
||||
case "settings": void openSettings(); return true;
|
||||
case "help": preferences = "help"; return true;
|
||||
case "quick-open": if (workspace) quickOpen = true; return true;
|
||||
@@ -1162,6 +1177,7 @@
|
||||
<WorkspacePicker bind:this={workspacePicker} currentRoot={workspace?.root} anchor={workspaceAnchor} onOpen={openPath} />
|
||||
{#if preferences}<SettingsDialog {settings} help={preferences === "help"} onSave={updateSettings} onClose={() => preferences = null} />{/if}
|
||||
{#if quickOpen && workspace}<QuickOpen onOpen={(entry) => void openFile(entry)} onClose={() => quickOpen = false} />{/if}
|
||||
{#if palette}<CommandPalette commands={paletteCommands()} onClose={() => palette = false} />{/if}
|
||||
{#if templateManager && workspace}<TemplateManager {session} onClose={() => templateManager = false}
|
||||
onEdit={(entry) => { templateManager = false; void openFile(entry, undefined, "new"); }} />{/if}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte";
|
||||
import { openPluginView, pluginSidebar } from "$lib/plugins/external";
|
||||
import TabBar from "./TabBar.svelte";
|
||||
import { commandShortcut } from "./workbenchKeys";
|
||||
|
||||
type LeftView = "files" | "search" | "bookmarks";
|
||||
type Props = {
|
||||
@@ -53,7 +54,7 @@
|
||||
</div>
|
||||
<div class="header-center" data-tauri-drag-region>
|
||||
<TabBar {...tabBar} />
|
||||
<IconButton icon="plus" label={$t("New tab (Ctrl T)")} onclick={onNewTab} />
|
||||
<IconButton icon="plus" label={$t("New tab ({shortcut})", { shortcut: commandShortcut("new-tab") })} onclick={onNewTab} />
|
||||
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
|
||||
</div>
|
||||
<div class="header-right" data-tauri-drag-region>
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import { message } from "../i18n/index.ts";
|
||||
import { keys, shortcutLabel } from "../ui/shortcuts.ts";
|
||||
|
||||
/** The commands of the workbench shortcuts. Workbench.svelte runs them. */
|
||||
export type WorkbenchCommand =
|
||||
| "quick-open" | "new-tab" | "search-workspace" | "save" | "open-workspace" | "new-file" | "toggle-layout"
|
||||
| "command-palette" | "quick-open" | "new-tab" | "search-workspace" | "save" | "open-workspace" | "new-file" | "toggle-layout"
|
||||
| "toggle-terminal" | "close-tab" | "toggle-sidebar" | "rename" | "next-tab" | "previous-tab" | "settings" | "help";
|
||||
|
||||
/**
|
||||
* One shortcut. `mod` is Ctrl, or Cmd on macOS. `ctrl` is Ctrl only.
|
||||
* `shift` and `alt` must match when they are set. A missing value accepts both states.
|
||||
* `code` matches the physical key, for keys that move between keyboard layouts.
|
||||
* `outsideFields` ignores the key in text inputs, where it has its own meaning.
|
||||
*/
|
||||
export type WorkbenchKey = {
|
||||
key: string;
|
||||
code?: string;
|
||||
command: WorkbenchCommand;
|
||||
mod?: boolean;
|
||||
ctrl?: boolean;
|
||||
@@ -20,6 +25,7 @@ export type WorkbenchKey = {
|
||||
|
||||
/** Shortcuts of the main window. The first match wins. */
|
||||
export const workbenchKeys: WorkbenchKey[] = [
|
||||
{ key: "p", mod: true, shift: true, command: "command-palette" },
|
||||
{ key: "p", mod: true, command: "quick-open" },
|
||||
{ key: "t", mod: true, shift: false, alt: false, command: "new-tab" },
|
||||
{ key: "f", mod: true, shift: true, command: "search-workspace" },
|
||||
@@ -29,7 +35,8 @@ export const workbenchKeys: WorkbenchKey[] = [
|
||||
{ key: "e", mod: true, command: "toggle-layout" },
|
||||
{ key: "`", mod: true, command: "toggle-terminal" },
|
||||
{ key: "w", mod: true, command: "close-tab" },
|
||||
{ key: "b", mod: true, command: "toggle-sidebar" },
|
||||
// Ctrl+B makes text bold in Write, so the side pane toggle uses Ctrl+\.
|
||||
{ key: "\\", code: "Backslash", mod: true, command: "toggle-sidebar" },
|
||||
{ key: "F2", mod: false, alt: false, outsideFields: true, command: "rename" },
|
||||
];
|
||||
|
||||
@@ -41,11 +48,54 @@ export const preferenceKeys: WorkbenchKey[] = [
|
||||
{ key: "F1", mod: false, shift: false, alt: false, command: "help" },
|
||||
];
|
||||
|
||||
type KeyEvent = Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "shiftKey" | "altKey" | "target">;
|
||||
/** The name of each command in the command palette and in Help. */
|
||||
export const COMMAND_LABELS: Record<WorkbenchCommand, string> = {
|
||||
"command-palette": message("Show all commands"),
|
||||
"quick-open": message("Find a file"),
|
||||
"new-tab": message("New tab"),
|
||||
"search-workspace": message("Search the workspace"),
|
||||
save: message("Save the active file"),
|
||||
"open-workspace": message("Open a workspace"),
|
||||
"new-file": message("New file"),
|
||||
"toggle-layout": message("Switch between writing and source editing"),
|
||||
"toggle-terminal": message("Show or hide the terminal"),
|
||||
"close-tab": message("Close the tab"),
|
||||
"toggle-sidebar": message("Show or hide the side pane"),
|
||||
rename: message("Rename the active file"),
|
||||
"next-tab": message("Next tab"),
|
||||
"previous-tab": message("Previous tab"),
|
||||
settings: message("Open settings"),
|
||||
help: message("Help and about"),
|
||||
};
|
||||
|
||||
/** The label of the first shortcut of a command, or an empty string. */
|
||||
export function commandShortcut(command: WorkbenchCommand): string {
|
||||
const binding = [...workbenchKeys, ...preferenceKeys].find(item => item.command === command);
|
||||
return binding ? shortcutLabel(binding) : "";
|
||||
}
|
||||
|
||||
/** Shortcuts of the editors and the file tree, for Help. `keys` uses Mod for Ctrl, or Cmd on macOS. `macKeys` replaces `keys` on macOS. */
|
||||
export const OTHER_SHORTCUTS: readonly { section: string; label: string; keys: string; macKeys?: string }[] = [
|
||||
{ section: message("Write"), label: message("Bold"), keys: "Mod+B" },
|
||||
{ section: message("Write"), label: message("Italic"), keys: "Mod+I" },
|
||||
{ section: message("Write"), label: message("Add external link"), keys: "Mod+K" },
|
||||
{ section: message("Write"), label: message("Strikethrough"), keys: "Mod+Shift+X" },
|
||||
{ section: message("Write"), label: message("Highlight"), keys: "Mod+Shift+H" },
|
||||
{ section: message("Write"), label: message("Find in the document"), keys: "Mod+F" },
|
||||
{ section: message("Files"), label: message("Rename"), keys: "F2" },
|
||||
{ section: message("Files"), label: message("Move to the Recycle Bin"), keys: "Delete", macKeys: "Mod+Backspace" },
|
||||
{ section: message("Files"), label: message("Delete permanently"), keys: "Shift+Delete", macKeys: "Mod+Alt+Backspace" },
|
||||
{ section: message("Files"), label: message("Open the context menu"), keys: "Shift+F10" },
|
||||
];
|
||||
|
||||
/** The label of a written combination, such as "Mod+Shift+X". */
|
||||
export { keys as shortcutKeys };
|
||||
|
||||
type KeyEvent = Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "shiftKey" | "altKey" | "target"> & { code?: string };
|
||||
|
||||
function matches(binding: WorkbenchKey, event: KeyEvent): boolean {
|
||||
const key = binding.key.length === 1 ? event.key.toLowerCase() : event.key;
|
||||
if (key !== binding.key) return false;
|
||||
if (key !== binding.key && !(binding.code && event.code === binding.code)) return false;
|
||||
if (binding.mod !== undefined && (event.ctrlKey || event.metaKey) !== binding.mod) return false;
|
||||
if (binding.ctrl && (!event.ctrlKey || event.metaKey)) return false;
|
||||
if (binding.shift !== undefined && event.shiftKey !== binding.shift) return false;
|
||||
|
||||
Reference in New Issue
Block a user