diff --git a/apps/web/core/components/power-k/actions/helper.ts b/apps/web/core/components/power-k/actions/helper.ts deleted file mode 100644 index a72f9d44134..00000000000 --- a/apps/web/core/components/power-k/actions/helper.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2023-present Plane Software, Inc. and contributors - * SPDX-License-Identifier: AGPL-3.0-only - * See the LICENSE file for details. - */ - -import { store } from "@/lib/store-context"; - -export const openProjectAndScrollToSidebar = (itemProjectId: string | undefined) => { - if (!itemProjectId) { - console.warn("No project id provided. Cannot open project and scroll to sidebar."); - return; - } - // open the project list - store.commandPalette.toggleProjectListOpen(itemProjectId, true); - // scroll to the element - const scrollElementId = `sidebar-${itemProjectId}-JOINED`; - const scrollElement = document.getElementById(scrollElementId); - // if the element exists, scroll to it - if (scrollElement) { - setTimeout(() => { - scrollElement.scrollIntoView({ behavior: "smooth", block: "start" }); - // Restart the highlight animation every time - scrollElement.style.animation = "none"; - // Trigger a reflow to ensure the animation is restarted - void scrollElement.offsetWidth; - // Restart the highlight animation - scrollElement.style.animation = "highlight 2s ease-in-out"; - }); - } -}; diff --git a/apps/web/core/components/power-k/config/miscellaneous-commands.ts b/apps/web/core/components/power-k/config/miscellaneous-commands.ts index 48c9c9da5a0..3d0954d7487 100644 --- a/apps/web/core/components/power-k/config/miscellaneous-commands.ts +++ b/apps/web/core/components/power-k/config/miscellaneous-commands.ts @@ -19,13 +19,14 @@ import { usePowerK } from "@/hooks/store/use-power-k"; export const usePowerKMiscellaneousCommands = (): TPowerKCommandConfig[] => { // store hooks const { toggleSidebar } = useAppTheme(); - const { topNavInputRef, topNavSearchInputRef } = usePowerK(); + const { topNavInputRef } = usePowerK(); // translation const { t } = useTranslation(); const copyCurrentPageUrlToClipboard = useCallback(() => { const url = new URL(window.location.href); copyTextToClipboard(url.href) + // oxlint-disable-next-line promise/always-return .then(() => { setToast({ type: "success", @@ -42,13 +43,11 @@ export const usePowerKMiscellaneousCommands = (): TPowerKCommandConfig[] => { }, []); const focusTopNavSearch = useCallback(() => { - // Focus PowerK input if available, otherwise focus regular search input - if (topNavSearchInputRef?.current) { - topNavSearchInputRef.current.focus(); - } else if (topNavInputRef?.current) { - topNavInputRef.current.focus(); - } - }, [topNavInputRef, topNavSearchInputRef]); + topNavInputRef?.current?.focus(); + }, [topNavInputRef]); + // Without a mounted top-nav input the command has nothing to focus, and Cmd+F must fall + // through to the browser's Find + const hasTopNavInput = useCallback(() => Boolean(topNavInputRef?.current), [topNavInputRef]); return [ { @@ -83,8 +82,8 @@ export const usePowerKMiscellaneousCommands = (): TPowerKCommandConfig[] => { icon: SearchOutline, action: focusTopNavSearch, modifierShortcut: "cmd+f", - isEnabled: () => true, - isVisible: () => true, + isEnabled: hasTopNavInput, + isVisible: hasTopNavInput, closeOnSelect: true, }, ]; diff --git a/apps/web/core/components/power-k/core/shortcut-handler.ts b/apps/web/core/components/power-k/core/shortcut-handler.ts index 85bcb27a103..76464f1d37f 100644 --- a/apps/web/core/components/power-k/core/shortcut-handler.ts +++ b/apps/web/core/components/power-k/core/shortcut-handler.ts @@ -7,39 +7,147 @@ import type { IPowerKCommandRegistry } from "./registry"; import type { TPowerKCommandConfig, TPowerKContext } from "./types"; +/** `KeyboardEvent.code` -> unshifted character on the active OS keyboard layout */ +export type TKeyboardLayoutMap = ReadonlyMap; + +type TNavigatorWithKeyboard = Navigator & { + keyboard?: { getLayoutMap?: () => Promise }; +}; + +/** + * Reads the active keyboard layout where the browser exposes it (Chromium, secure top-level + * contexts). Resolves to null elsewhere, in which case matching falls back to the US layout. + */ +export async function loadKeyboardLayoutMap(): Promise { + if (typeof navigator === "undefined") return null; + const keyboard = (navigator as TNavigatorWithKeyboard).keyboard; + if (typeof keyboard?.getLayoutMap !== "function") return null; + try { + return await keyboard.getLayoutMap(); + } catch { + return null; + } +} + +/** + * US layout: the base character under each shifted glyph and the physical key it lives on. + * Used only without a layout map, and only when `e.code` agrees, so a layout that puts a + * different character on that key can never fire a shortcut it does not advertise. + */ +const US_SHIFTED_GLYPHS: Record = { + "~": { base: "`", code: "Backquote" }, + "!": { base: "1", code: "Digit1" }, + "@": { base: "2", code: "Digit2" }, + "#": { base: "3", code: "Digit3" }, + $: { base: "4", code: "Digit4" }, + "%": { base: "5", code: "Digit5" }, + "^": { base: "6", code: "Digit6" }, + "&": { base: "7", code: "Digit7" }, + "*": { base: "8", code: "Digit8" }, + "(": { base: "9", code: "Digit9" }, + ")": { base: "0", code: "Digit0" }, + _: { base: "-", code: "Minus" }, + "+": { base: "=", code: "Equal" }, + "{": { base: "[", code: "BracketLeft" }, + "}": { base: "]", code: "BracketRight" }, + "|": { base: "\\", code: "Backslash" }, + ":": { base: ";", code: "Semicolon" }, + '"': { base: "'", code: "Quote" }, + "<": { base: ",", code: "Comma" }, + ">": { base: ".", code: "Period" }, + "?": { base: "/", code: "Slash" }, +}; + +const isAsciiPrintable = (char: string): boolean => char >= " " && char <= "~"; + +/** Letter or digit printed on a physical key in the US layout ("KeyB" -> "b", "Digit2" -> "2") */ +const usKeyForCode = (code: string): string | undefined => { + const letter = /^Key([A-Z])$/.exec(code); + if (letter) return letter[1].toLowerCase(); + const digit = /^Digit([0-9])$/.exec(code); + if (digit) return digit[1]; + return undefined; +}; + +/** + * The layout-independent key a shortcut is registered against: the unshifted character on the + * pressed physical key ("," for Shift+Comma), lowercased; named keys ("backspace") as-is. + * Non-Latin layouts resolve letters and digits by physical position, as browsers do for + * their own shortcuts, so Cmd+B still toggles the sidebar on a Cyrillic or Greek layout. + */ +export function resolveShortcutKey(e: KeyboardEvent, layoutMap: TKeyboardLayoutMap | null): string { + if (e.key === " ") return "space"; + if (e.key.length !== 1) return e.key.toLowerCase(); + + const fromLayout = e.code ? layoutMap?.get(e.code) : undefined; + if (fromLayout) return isAsciiPrintable(fromLayout) ? fromLayout.toLowerCase() : (usKeyForCode(e.code) ?? fromLayout); + + const key = e.key.toLowerCase(); + if (!isAsciiPrintable(key)) return usKeyForCode(e.code) ?? key; + if (!e.shiftKey) return key; + const shifted = US_SHIFTED_GLYPHS[e.key]; + return shifted && shifted.code === e.code ? shifted.base : key; +} + /** * Formats a keyboard event into a modifier shortcut string - * e.g., "cmd+k", "cmd+shift+,", "cmd+delete" + * e.g., "cmd+k", "cmd+shift+,", "cmd+backspace" */ -export function formatModifierShortcut(e: KeyboardEvent): string { +export function formatModifierShortcut(e: KeyboardEvent, layoutMap: TKeyboardLayoutMap | null): string { const parts: string[] = []; if (e.ctrlKey || e.metaKey) parts.push("cmd"); if (e.altKey) parts.push("alt"); if (e.shiftKey) parts.push("shift"); - - const key = e.key.toLowerCase(); - parts.push(key === " " ? "space" : key); + parts.push(resolveShortcutKey(e, layoutMap)); return parts.join("+"); } +/** ARIA roles whose keyboard handling (typing, typeahead) must win over global shortcuts */ +const TYPING_ROLES = new Set([ + "textbox", + "searchbox", + "combobox", + "spinbutton", + "listbox", + "option", + "menu", + "menuitem", + "menuitemcheckbox", + "menuitemradio", +]); + +/** Overlays and editors that own keyboard input while focus is inside them */ +const KEYBOARD_OWNING_ANCESTOR = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"], .ProseMirror'; + /** - * Checks if the event target is a typing-focused element + * Whether keystrokes on this target belong to a widget: form controls, editable content + * (including `plaintext-only` and inherited editability), and ARIA widgets or overlays with + * their own keyboard handling. Global shortcuts neither fire from nor linger across them. */ export function isTypingInInput(target: EventTarget | null): boolean { - if (!target) return false; + if (!(target instanceof Element)) return false; if (target instanceof HTMLInputElement) return true; if (target instanceof HTMLTextAreaElement) return true; + if (target instanceof HTMLSelectElement) return true; + if (target instanceof HTMLElement && target.isContentEditable) return true; - const element = target as Element; - if (element.classList?.contains("ProseMirror")) return true; - if (element.getAttribute?.("contenteditable") === "true") return true; + const role = target.getAttribute("role"); + if (role && TYPING_ROLES.has(role)) return true; - return false; + return target.closest(KEYBOARD_OWNING_ANCESTOR) !== null; } +/** Whether any registered sequence starts with `prefix` (equality included) */ +const hasSequencePrefix = (sequenceMap: ReadonlyMap, prefix: string): boolean => { + for (const sequence of sequenceMap.keys()) { + if (sequence.startsWith(prefix)) return true; + } + return false; +}; + /** * Global shortcut handler * Handles all keyboard shortcuts: single keys, sequences, and modifiers @@ -50,12 +158,30 @@ export class ShortcutHandler { private registry: IPowerKCommandRegistry; private getContext: () => TPowerKContext; private openPalette: () => void; + private togglePalette: () => void; + private layoutMap: TKeyboardLayoutMap | null = null; private isEnabled = true; - constructor(registry: IPowerKCommandRegistry, getContext: () => TPowerKContext, openPalette: () => void) { + constructor( + registry: IPowerKCommandRegistry, + getContext: () => TPowerKContext, + openPalette: () => void, + togglePalette: () => void + ) { this.registry = registry; this.getContext = getContext; this.openPalette = openPalette; + this.togglePalette = togglePalette; + void this.loadLayoutMap(); + } + + /** + * Resolves the OS keyboard layout; until then, and on browsers without the API, the US + * fallback applies + */ + private async loadLayoutMap(): Promise { + const layoutMap = await loadKeyboardLayoutMap(); + if (this.isEnabled) this.layoutMap = layoutMap; } /** @@ -71,36 +197,48 @@ export class ShortcutHandler { handleKeyDown = (e: KeyboardEvent): void => { if (!this.isEnabled) return; - const key = e.key.toLowerCase(); - const hasModifier = e.metaKey || e.ctrlKey || e.altKey || e.shiftKey; + // Auto-repeat must neither re-fire a shortcut nor touch the sequence buffer + if (e.repeat) return; - // Special: Cmd+K always opens command palette - if ((e.metaKey || e.ctrlKey) && key === "k") { + // Cmd+K toggles the palette from anywhere, including inputs. It runs before the + // `defaultPrevented` check because the palette itself prevents the default to keep + // cmdk's Ctrl+K vim binding from moving the selection. + if ((e.metaKey || e.ctrlKey) && resolveShortcutKey(e, this.layoutMap) === "k") { e.preventDefault(); - this.openPalette(); + this.resetSequence(); + this.togglePalette(); + return; + } + + // A component that already handled the key (editor keymaps, cmdk navigation) wins, + // and the key cannot be part of a sequence either + if (e.defaultPrevented) { + this.resetSequence(); return; } - // Don't handle shortcuts when typing in inputs (except Cmd+K) + // Keys typed into inputs and widgets never trigger shortcuts, nor continue a sequence if (isTypingInInput(e.target)) { + this.resetSequence(); return; } - // Handle modifier shortcuts (Cmd+Delete, Cmd+Shift+,, etc.) - if (hasModifier) { + // Any modified key cancels a pending sequence, whether or not it matches a shortcut + if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) { + this.resetSequence(); this.handleModifierShortcut(e); return; } - // Handle single key shortcuts and sequences (c, p, gm, op, etc.) - this.handleKeyOrSequence(e, key); + // Handle single key shortcuts and sequences (s, gm, op, etc.) + this.handleKeyOrSequence(e); }; /** * Handle modifier shortcuts (Cmd+X, Cmd+Shift+X, etc.) */ private handleModifierShortcut(e: KeyboardEvent): void { - const shortcut = formatModifierShortcut(e); + const shortcut = formatModifierShortcut(e, this.layoutMap); const command = this.registry.findByModifierShortcut(this.getContext(), shortcut); if (command && this.canExecuteCommand(command)) { @@ -110,14 +248,26 @@ export class ShortcutHandler { } /** - * Handle single key shortcuts or build sequences (c, gm, op, etc.) + * Handle single key shortcuts or build sequences (s, gm, op, etc.) */ - private handleKeyOrSequence(e: KeyboardEvent, key: string): void { - // Add key to sequence + private handleKeyOrSequence(e: KeyboardEvent): void { + // Non-printable keys (Escape, Tab, Enter, arrows, ...) cancel a pending sequence + if (e.key.length !== 1) { + this.resetSequence(); + return; + } + + const key = resolveShortcutKey(e, this.layoutMap); + const ctx = this.getContext(); + // Visible commands are computed on every call outside a reactive context, so fetch the + // map once and answer both the exact and the prefix lookup from it + const sequenceMap = this.registry.getKeySequenceMap(ctx); + this.sequence += key; // Check if sequence matches a command (e.g., "gm", "op") - const sequenceCommand = this.registry.findByKeySequence(this.getContext(), this.sequence); + const sequenceCommandId = sequenceMap.get(this.sequence); + const sequenceCommand = sequenceCommandId ? this.registry.getCommand(sequenceCommandId) : undefined; if (sequenceCommand && this.canExecuteCommand(sequenceCommand)) { e.preventDefault(); this.executeCommand(sequenceCommand); @@ -125,19 +275,31 @@ export class ShortcutHandler { return; } - // If sequence is one character, check for single-key shortcut + // The buffer can still become a sequence - wait for the next key + if (hasSequencePrefix(sequenceMap, this.sequence)) { + this.scheduleSequenceReset(); + return; + } + + // A fresh key that starts no sequence is a single-key shortcut, or nothing if (this.sequence.length === 1) { - const singleKeyCommand = this.registry.findByShortcut(this.getContext(), key); - if (singleKeyCommand && this.canExecuteCommand(singleKeyCommand)) { + const shortcutCommandId = this.registry.getShortcutMap(ctx).get(key); + const shortcutCommand = shortcutCommandId ? this.registry.getCommand(shortcutCommandId) : undefined; + if (shortcutCommand && this.canExecuteCommand(shortcutCommand)) { e.preventDefault(); - this.executeCommand(singleKeyCommand); - this.resetSequence(); - return; + this.executeCommand(shortcutCommand); } + this.resetSequence(); + return; } - // Reset sequence after 1 second of no typing - this.scheduleSequenceReset(); + // A pending prefix this key does not extend: the key may start a new sequence ("g", "g", + // "m"), otherwise the stray keystroke is dropped rather than re-read as a single-key shortcut + this.resetSequence(); + if (hasSequencePrefix(sequenceMap, key)) { + this.sequence = key; + this.scheduleSequenceReset(); + } } /** diff --git a/apps/web/core/components/power-k/global-shortcuts.tsx b/apps/web/core/components/power-k/global-shortcuts.tsx index fe4fe8e2ea1..50fa8f283f0 100644 --- a/apps/web/core/components/power-k/global-shortcuts.tsx +++ b/apps/web/core/components/power-k/global-shortcuts.tsx @@ -65,7 +65,8 @@ export const GlobalShortcutsProvider = observer(function GlobalShortcutsProvider handlerRef.current = new ShortcutHandler( commandRegistry, () => contextRef.current, - () => togglePowerKModal(true) + () => togglePowerKModal(true), + () => togglePowerKModal() ); document.addEventListener("keydown", handlerRef.current.handleKeyDown); diff --git a/apps/web/core/components/power-k/ui/modal/command-item-shortcut-badge.tsx b/apps/web/core/components/power-k/ui/modal/command-item-shortcut-badge.tsx index 57ad412ff5a..76f73fac122 100644 --- a/apps/web/core/components/power-k/ui/modal/command-item-shortcut-badge.tsx +++ b/apps/web/core/components/power-k/ui/modal/command-item-shortcut-badge.tsx @@ -5,17 +5,17 @@ */ import React from "react"; +// hooks +import { usePlatformOS } from "@/hooks/use-platform-os"; /** - * Formats a shortcut string for display - * Converts "cmd+shift+," to proper keyboard symbols + * Formats a shortcut string for display, one label per key + * e.g. "cmd+shift+," -> ["⌘", "⇧", ","] on Mac, ["Ctrl", "Shift", ","] elsewhere */ -export const formatShortcutForDisplay = (shortcut: string | undefined): string | null => { - if (!shortcut) return null; +export const formatShortcutForDisplay = (shortcut: string | undefined, isMac: boolean): string[] => { + if (!shortcut) return []; - const isMac = typeof window !== "undefined" && navigator.platform.toUpperCase().indexOf("MAC") >= 0; - - const parts = shortcut.split("+").map((part) => { + return shortcut.split("+").map((part) => { const lower = part.toLowerCase().trim(); // Map to proper symbols @@ -63,39 +63,35 @@ export const formatShortcutForDisplay = (shortcut: string | undefined): string | return part.toUpperCase(); } }); - - return parts.join(""); }; export function ShortcutBadge({ shortcut }: { shortcut: string | undefined }) { - if (!shortcut) return null; - - const formatted = formatShortcutForDisplay(shortcut); + const { platform } = usePlatformOS(); + const labels = formatShortcutForDisplay(shortcut, platform === "MacOS"); + if (labels.length === 0) return null; return (
- {formatted?.split("").map((char, index) => ( - - - {char.toUpperCase()} - - + {labels.map((label, index) => ( + + {label} + ))}
); } -/** - * Formats key sequence for display (e.g., "gm" -> "G then M") - */ -export const formatKeySequenceForDisplay = (sequence: string | undefined): string => { - if (!sequence) return ""; - - const chars = sequence.split(""); - return chars.map((c) => c.toUpperCase()).join(" then "); +type TKeySequenceBadgeProps = { + sequence: string | undefined; + /** Translated connector rendered between keys, e.g. "then" in "G then M" */ + separator: string; }; -export function KeySequenceBadge({ sequence }: { sequence: string | undefined }) { +export function KeySequenceBadge({ sequence, separator }: TKeySequenceBadgeProps) { if (!sequence) return null; const chars = sequence.split(""); @@ -103,11 +99,12 @@ export function KeySequenceBadge({ sequence }: { sequence: string | undefined }) return (
{chars.map((char, index) => ( + // oxlint-disable-next-line react/no-array-index-key -- static list from a constant string, never reordered {char.toUpperCase()} - {index < chars.length - 1 && then} + {index < chars.length - 1 && {separator}} ))}
diff --git a/apps/web/core/components/power-k/ui/modal/command-item.tsx b/apps/web/core/components/power-k/ui/modal/command-item.tsx index 17f794b265c..20ce3a9be31 100644 --- a/apps/web/core/components/power-k/ui/modal/command-item.tsx +++ b/apps/web/core/components/power-k/ui/modal/command-item.tsx @@ -19,6 +19,8 @@ type Props = { isDisabled?: boolean; isSelected?: boolean; keySequence?: string; + /** Translated connector rendered between the keys of `keySequence` */ + keySequenceSeparator?: string; label: string | React.ReactNode; onSelect: () => void; shortcut?: string; @@ -26,7 +28,18 @@ type Props = { }; export function PowerKModalCommandItem(props: Props) { - const { icon: Icon, iconNode, isDisabled, isSelected, keySequence, label, onSelect, shortcut, value } = props; + const { + icon: Icon, + iconNode, + isDisabled, + isSelected, + keySequence, + keySequenceSeparator = "", + label, + onSelect, + shortcut, + value, + } = props; return ( @@ -41,7 +54,7 @@ export function PowerKModalCommandItem(props: Props) {
{isSelected && } - {keySequence && } + {keySequence && } {shortcut && }
diff --git a/apps/web/core/components/power-k/ui/modal/search-results.tsx b/apps/web/core/components/power-k/ui/modal/search-results.tsx index eaa5eb9b876..1cc401c3ced 100644 --- a/apps/web/core/components/power-k/ui/modal/search-results.tsx +++ b/apps/web/core/components/power-k/ui/modal/search-results.tsx @@ -58,12 +58,6 @@ export const PowerKModalSearchResults = observer(function PowerKModalSearchResul onSelect={() => { closePalette(); router.push(currentSection.path(item, projectId)); - // const itemProjectId = - // item?.project_id || - // (Array.isArray(item?.project_ids) && item?.project_ids?.length > 0 - // ? item?.project_ids[0] - // : undefined); - // if (itemProjectId) openProjectAndScrollToSidebar(itemProjectId); }} value={value} /> diff --git a/apps/web/core/components/power-k/ui/modal/shortcuts-root.tsx b/apps/web/core/components/power-k/ui/modal/shortcuts-root.tsx index 827c79ae130..5b0871b402f 100644 --- a/apps/web/core/components/power-k/ui/modal/shortcuts-root.tsx +++ b/apps/web/core/components/power-k/ui/modal/shortcuts-root.tsx @@ -5,6 +5,7 @@ */ import { useState } from "react"; +import { observer } from "mobx-react"; // plane imports import { Dialog, @@ -32,7 +33,7 @@ type Props = { onClose: () => void; }; -export function ShortcutsModal(props: Props) { +export const ShortcutsModal = observer(function ShortcutsModal(props: Props) { const { isOpen, onClose } = props; // states const [query, setQuery] = useState(""); @@ -86,8 +87,8 @@ export function ShortcutsModal(props: Props) { type="text" value={query} onChange={(e) => setQuery(e.target.value)} - placeholder="Search for shortcuts" - aria-label="Search for shortcuts" + placeholder={t("power_k.shortcuts_modal.search_placeholder")} + aria-label={t("power_k.shortcuts_modal.search_placeholder")} // oxlint-disable-next-line jsx-a11y/no-autofocus -- the shortcut sheet opens on the search field autoFocus /> @@ -100,4 +101,4 @@ export function ShortcutsModal(props: Props) { ); -} +}); diff --git a/apps/web/core/components/power-k/ui/modal/wrapper.tsx b/apps/web/core/components/power-k/ui/modal/wrapper.tsx index 25294392c20..45c22beb8a0 100644 --- a/apps/web/core/components/power-k/ui/modal/wrapper.tsx +++ b/apps/web/core/components/power-k/ui/modal/wrapper.tsx @@ -69,10 +69,11 @@ export const ProjectsAppPowerKModalWrapper = observer(function ProjectsAppPowerK // Handle keyboard navigation const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { - // Cmd/Ctrl+K closes palette + // Cmd/Ctrl+K is toggled by the document-level ShortcutHandler, which this event still + // reaches. Preventing the default only keeps cmdk's Ctrl+K vim binding from moving the + // selection first. if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") { e.preventDefault(); - onClose(); return; } diff --git a/apps/web/core/components/power-k/ui/pages/work-item-selection-page.tsx b/apps/web/core/components/power-k/ui/pages/work-item-selection-page.tsx deleted file mode 100644 index 4cfe00010b8..00000000000 --- a/apps/web/core/components/power-k/ui/pages/work-item-selection-page.tsx +++ /dev/null @@ -1,168 +0,0 @@ -/** - * Copyright (c) 2023-present Plane Software, Inc. and contributors - * SPDX-License-Identifier: AGPL-3.0-only - * See the LICENSE file for details. - */ - -import { useState, useEffect } from "react"; -// plane imports -// import { useTranslation } from "@plane/i18n"; -import type { TIssueEntityData, TIssueSearchResponse, TActivityEntityData } from "@plane/types"; -// import { generateWorkItemLink } from "@plane/utils"; -// components -// import { CommandPaletteEntityList } from "@/components/command-palette"; -// import { SimpleEmptyState } from "@/components/empty-state/simple-empty-state-root"; -// hooks -// import { useCommandPalette } from "@/hooks/store/use-command-palette"; -// import { usePowerK } from "@/hooks/store/use-power-k"; -// import { useAppRouter } from "@/hooks/use-app-router"; -// plane web imports -// import { IssueIdentifier } from "@/plane-web/components/issues/issue-details/issue-identifier"; -import { WorkspaceService } from "@/services/workspace.service"; - -const workspaceService = new WorkspaceService(); - -type Props = { - workspaceSlug: string | undefined; - projectId: string | undefined; - searchTerm: string; - debouncedSearchTerm: string; - isLoading: boolean; - isSearching: boolean; - resolvedPath: string; - isWorkspaceLevel?: boolean; -}; - -export function WorkItemSelectionPage(props: Props) { - const { workspaceSlug, projectId, debouncedSearchTerm, isWorkspaceLevel = false } = props; - // router - // const router = useAppRouter(); - // plane hooks - // const { t } = useTranslation(); - // store hooks - // const { togglePowerKModal } = usePowerK(); - // states - const [_recentIssues, setRecentIssues] = useState([]); - const [_issueResults, setIssueResults] = useState([]); - - // Load recent issues when component mounts - useEffect(() => { - if (!workspaceSlug) return; - - workspaceService - .fetchWorkspaceRecents(workspaceSlug.toString(), "issue") - .then((res) => - setRecentIssues(res.map((r: TActivityEntityData) => r.entity_data as TIssueEntityData).slice(0, 10)) - ) - .catch(() => setRecentIssues([])); - }, [workspaceSlug]); - - // Search issues based on search term - useEffect(() => { - if (!workspaceSlug || !debouncedSearchTerm) { - setIssueResults([]); - return; - } - - workspaceService - .searchEntity(workspaceSlug.toString(), { - count: 10, - query: debouncedSearchTerm, - query_type: ["issue"], - ...(!isWorkspaceLevel && projectId ? { project_id: projectId.toString() } : {}), - }) - // oxlint-disable-next-line promise/always-return - .then((res) => { - setIssueResults(res.issue || []); - }) - .catch(() => setIssueResults([])); - }, [debouncedSearchTerm, workspaceSlug, projectId, isWorkspaceLevel]); - - if (!workspaceSlug) return null; - - return ( - <> - {/* {searchTerm === "" ? ( - recentIssues.length > 0 ? ( - issue.id} - getLabel={(issue) => `${issue.project_identifier}-${issue.sequence_id} ${issue.name}`} - renderItem={(issue) => ( -
- {issue.project_id && ( - - )} - {issue.name} -
- )} - onSelect={(issue) => { - if (!issue.project_id) return; - togglePowerKModal(false); - router.push( - generateWorkItemLink({ - workspaceSlug: workspaceSlug.toString(), - projectId: issue.project_id, - issueId: issue.id, - projectIdentifier: issue.project_identifier, - sequenceId: issue.sequence_id, - isEpic: issue.is_epic, - }) - ); - }} - emptyText="Search for issue id or issue title" - /> - ) : ( -
Search for issue id or issue title
- ) - ) : issueResults.length > 0 ? ( - issue.id} - getLabel={(issue) => `${issue.project__identifier}-${issue.sequence_id} ${issue.name}`} - renderItem={(issue) => ( -
- {issue.project_id && issue.project__identifier && issue.sequence_id && ( - - )} - {issue.name} -
- )} - onSelect={(issue) => { - if (!issue.project_id) return; - togglePowerKModal(false); - router.push( - generateWorkItemLink({ - workspaceSlug: workspaceSlug.toString(), - projectId: issue.project_id, - issueId: issue.id, - projectIdentifier: issue.project__identifier, - sequenceId: issue.sequence_id, - }) - ); - }} - emptyText={t("command_k.empty_state.search.title") as string} - /> - ) : ( - !isLoading && - !isSearching && ( -
- -
- ) - )} */} - - ); -} diff --git a/apps/web/core/components/power-k/ui/renderer/command.tsx b/apps/web/core/components/power-k/ui/renderer/command.tsx index 408a454700c..769255bab2b 100644 --- a/apps/web/core/components/power-k/ui/renderer/command.tsx +++ b/apps/web/core/components/power-k/ui/renderer/command.tsx @@ -26,6 +26,8 @@ export function CommandRenderer(props: Props) { const { activeContext } = context; // translation const { t } = useTranslation(); + // Translated once here rather than per badge, so rows don't each subscribe to i18n + const keySequenceSeparator = t("power_k.shortcuts_modal.sequence_separator"); const commandsByGroup = commands.reduce( (acc, command) => { @@ -37,6 +39,7 @@ export function CommandRenderer(props: Props) { {} as Record ); + // oxlint-disable-next-line unicorn/no-array-sort const sortedGroups = Object.keys(commandsByGroup).sort((a, b) => { const aPriority = POWER_K_GROUP_PRIORITY[a as TPowerKCommandGroup]; const bPriority = POWER_K_GROUP_PRIORITY[b as TPowerKCommandGroup]; @@ -63,6 +66,7 @@ export function CommandRenderer(props: Props) { iconNode={command.iconNode} label={t(command.i18n_title)} keySequence={command.keySequence} + keySequenceSeparator={keySequenceSeparator} shortcut={command.shortcut || command.modifierShortcut} onSelect={() => onCommandSelect(command)} /> diff --git a/apps/web/core/components/power-k/ui/renderer/shortcut.tsx b/apps/web/core/components/power-k/ui/renderer/shortcut.tsx index 9f4d5098430..92058f3d088 100644 --- a/apps/web/core/components/power-k/ui/renderer/shortcut.tsx +++ b/apps/web/core/components/power-k/ui/renderer/shortcut.tsx @@ -20,10 +20,20 @@ type Props = { commands: TPowerKCommandConfig[]; }; +// Interpolated in place of the query so the translated sentence can be rendered around it +const QUERY_SENTINEL = "\u0000"; + export function ShortcutRenderer(props: Props) { const { searchQuery, commands } = props; // translation const { t } = useTranslation(); + // Translated once here rather than per badge, so rows don't each subscribe to i18n + const keySequenceSeparator = t("power_k.shortcuts_modal.sequence_separator"); + // The query's position in the sentence varies by language, so split the translation on a + // sentinel and give only the query its emphasis + const [noResultsBefore, noResultsAfter] = t("power_k.shortcuts_modal.no_results", { + query: QUERY_SENTINEL, + }).split(QUERY_SENTINEL); // Apply search filter const filteredCommands = commands.filter((command) => substringMatch(t(command.i18n_title), searchQuery)); @@ -89,7 +99,9 @@ export function ShortcutRenderer(props: Props) {

{t(command.i18n_title)}

- {command.keySequence && } + {command.keySequence && ( + + )} {(command.shortcut || command.modifierShortcut) && ( )} @@ -101,13 +113,10 @@ export function ShortcutRenderer(props: Props) {
)) ) : ( -

- No shortcuts found for{" "} - - {`"`} - {searchQuery} - {`"`} - +

+ {noResultsBefore} + {searchQuery} + {noResultsAfter}

)}
diff --git a/apps/web/core/store/base-command-palette.store.ts b/apps/web/core/store/base-command-palette.store.ts index 7b9fb56e869..60bf1493aaa 100644 --- a/apps/web/core/store/base-command-palette.store.ts +++ b/apps/web/core/store/base-command-palette.store.ts @@ -14,11 +14,6 @@ import { EIssuesStoreType } from "@plane/types"; // lib import { store } from "@/lib/store-context"; -export interface ModalData { - store: EIssuesStoreType; - viewId: string; -} - export interface IBaseCommandPaletteStore { // computed isAnyModalOpen: boolean; diff --git a/apps/web/core/store/base-power-k.store.ts b/apps/web/core/store/base-power-k.store.ts index 3d087e41f2f..3ee1c1d3d54 100644 --- a/apps/web/core/store/base-power-k.store.ts +++ b/apps/web/core/store/base-power-k.store.ts @@ -5,18 +5,11 @@ */ import { observable, action, makeObservable } from "mobx"; -// plane imports -import type { EIssuesStoreType } from "@plane/types"; // components import type { IPowerKCommandRegistry } from "@/components/power-k/core/registry"; import { PowerKCommandRegistry } from "@/components/power-k/core/registry"; import type { TPowerKContextType, TPowerKPageType } from "@/components/power-k/core/types"; -export interface ModalData { - store: EIssuesStoreType; - viewId: string; -} - export interface IBasePowerKStore { // observables isPowerKModalOpen: boolean; @@ -25,11 +18,9 @@ export interface IBasePowerKStore { activeContext: TPowerKContextType | null; activePage: TPowerKPageType | null; topNavInputRef: React.RefObject | null; - topNavSearchInputRef: React.RefObject | null; setActiveContext: (entity: TPowerKContextType | null) => void; setActivePage: (page: TPowerKPageType | null) => void; setTopNavInputRef: (ref: React.RefObject | null) => void; - setTopNavSearchInputRef: (ref: React.RefObject | null) => void; // toggle actions togglePowerKModal: (value?: boolean) => void; toggleShortcutsListModal: (value?: boolean) => void; @@ -43,7 +34,6 @@ export class BasePowerKStore implements IBasePowerKStore { activeContext: TPowerKContextType | null = null; activePage: TPowerKPageType | null = null; topNavInputRef: React.RefObject | null = null; - topNavSearchInputRef: React.RefObject | null = null; constructor() { makeObservable(this, { @@ -54,14 +44,12 @@ export class BasePowerKStore implements IBasePowerKStore { activeContext: observable, activePage: observable, topNavInputRef: observable.ref, - topNavSearchInputRef: observable.ref, // toggle actions togglePowerKModal: action, toggleShortcutsListModal: action, setActiveContext: action, setActivePage: action, setTopNavInputRef: action, - setTopNavSearchInputRef: action, }); } @@ -89,14 +77,6 @@ export class BasePowerKStore implements IBasePowerKStore { this.topNavInputRef = ref; }; - /** - * Sets the top nav search input ref for keyboard shortcut access - * @param ref - */ - setTopNavSearchInputRef = (ref: React.RefObject | null) => { - this.topNavSearchInputRef = ref; - }; - /** * Toggles the command palette modal * @param value diff --git a/packages/i18n/src/locales/cs/power-k.json b/packages/i18n/src/locales/cs/power-k.json index edcdc158c19..e1a7046d53f 100644 --- a/packages/i18n/src/locales/cs/power-k.json +++ b/packages/i18n/src/locales/cs/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Úroveň pracovního prostoru" }, + "shortcuts_modal": { + "search_placeholder": "Hledat klávesové zkratky", + "no_results": "Nenalezeny žádné klávesové zkratky pro „{query}“", + "sequence_separator": "pak" + }, "group_titles": { "actions": "Akce", "contextual": "Kontextové", diff --git a/packages/i18n/src/locales/de/power-k.json b/packages/i18n/src/locales/de/power-k.json index 278be2113aa..2f9226031b3 100644 --- a/packages/i18n/src/locales/de/power-k.json +++ b/packages/i18n/src/locales/de/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Arbeitsbereich-Ebene" }, + "shortcuts_modal": { + "search_placeholder": "Tastaturkürzel suchen", + "no_results": "Keine Tastaturkürzel für „{query}“ gefunden", + "sequence_separator": "dann" + }, "group_titles": { "actions": "Aktionen", "contextual": "Kontextbezogen", diff --git a/packages/i18n/src/locales/en/power-k.json b/packages/i18n/src/locales/en/power-k.json index c00d2e59f6f..a8b5882b9ba 100644 --- a/packages/i18n/src/locales/en/power-k.json +++ b/packages/i18n/src/locales/en/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Workspace level" }, + "shortcuts_modal": { + "search_placeholder": "Search for shortcuts", + "no_results": "No shortcuts found for \"{query}\"", + "sequence_separator": "then" + }, "group_titles": { "actions": "Actions", "contextual": "Contextual", diff --git a/packages/i18n/src/locales/es/power-k.json b/packages/i18n/src/locales/es/power-k.json index 6144f32a8a5..ecf69550c0f 100644 --- a/packages/i18n/src/locales/es/power-k.json +++ b/packages/i18n/src/locales/es/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Nivel de espacio de trabajo" }, + "shortcuts_modal": { + "search_placeholder": "Buscar atajos de teclado", + "no_results": "No se encontraron atajos de teclado para «{query}»", + "sequence_separator": "luego" + }, "group_titles": { "actions": "Acciones", "contextual": "Contextual", diff --git a/packages/i18n/src/locales/fr/power-k.json b/packages/i18n/src/locales/fr/power-k.json index 9461dcdceae..1d74d7f0510 100644 --- a/packages/i18n/src/locales/fr/power-k.json +++ b/packages/i18n/src/locales/fr/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Niveau espace de travail" }, + "shortcuts_modal": { + "search_placeholder": "Rechercher des raccourcis clavier", + "no_results": "Aucun raccourci clavier trouvé pour « {query} »", + "sequence_separator": "puis" + }, "group_titles": { "actions": "Actions", "contextual": "Contextuel", diff --git a/packages/i18n/src/locales/id/power-k.json b/packages/i18n/src/locales/id/power-k.json index accb57b00c7..6c99023a02c 100644 --- a/packages/i18n/src/locales/id/power-k.json +++ b/packages/i18n/src/locales/id/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Tingkat ruang kerja" }, + "shortcuts_modal": { + "search_placeholder": "Cari pintasan keyboard", + "no_results": "Tidak ada pintasan keyboard yang ditemukan untuk \"{query}\"", + "sequence_separator": "lalu" + }, "group_titles": { "actions": "Aksi", "contextual": "Kontekstual", diff --git a/packages/i18n/src/locales/it/power-k.json b/packages/i18n/src/locales/it/power-k.json index 2f7baab3fbf..b0111788a8e 100644 --- a/packages/i18n/src/locales/it/power-k.json +++ b/packages/i18n/src/locales/it/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Livello dello spazio di lavoro" }, + "shortcuts_modal": { + "search_placeholder": "Cerca scorciatoie da tastiera", + "no_results": "Nessuna scorciatoia da tastiera trovata per «{query}»", + "sequence_separator": "poi" + }, "group_titles": { "actions": "Azioni", "contextual": "Contestuale", diff --git a/packages/i18n/src/locales/ja/power-k.json b/packages/i18n/src/locales/ja/power-k.json index b7e66cd18b7..222a2d2cd12 100644 --- a/packages/i18n/src/locales/ja/power-k.json +++ b/packages/i18n/src/locales/ja/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "ワークスペースレベル" }, + "shortcuts_modal": { + "search_placeholder": "キーボードショートカットを検索", + "no_results": "「{query}」のキーボードショートカットが見つかりません", + "sequence_separator": "次に" + }, "group_titles": { "actions": "アクション", "contextual": "コンテキスト", diff --git a/packages/i18n/src/locales/ka-ge/power-k.json b/packages/i18n/src/locales/ka-ge/power-k.json index c00d2e59f6f..a8783db9972 100644 --- a/packages/i18n/src/locales/ka-ge/power-k.json +++ b/packages/i18n/src/locales/ka-ge/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Workspace level" }, + "shortcuts_modal": { + "search_placeholder": "კლავიატურის მალსახმობების ძებნა", + "no_results": "კლავიატურის მალსახმობები \"{query}\"-ისთვის ვერ მოიძებნა", + "sequence_separator": "შემდეგ" + }, "group_titles": { "actions": "Actions", "contextual": "Contextual", diff --git a/packages/i18n/src/locales/ko/power-k.json b/packages/i18n/src/locales/ko/power-k.json index 883f1f5b3a2..57a0f88815b 100644 --- a/packages/i18n/src/locales/ko/power-k.json +++ b/packages/i18n/src/locales/ko/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "작업 공간 수준" }, + "shortcuts_modal": { + "search_placeholder": "키보드 단축키 검색", + "no_results": "\"{query}\"에 대한 키보드 단축키를 찾을 수 없습니다", + "sequence_separator": "다음" + }, "group_titles": { "actions": "액션", "contextual": "컨텍스트", diff --git a/packages/i18n/src/locales/nl/power-k.json b/packages/i18n/src/locales/nl/power-k.json index d93eb2ca06c..af8fa82c05a 100644 --- a/packages/i18n/src/locales/nl/power-k.json +++ b/packages/i18n/src/locales/nl/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Werkruimteniveau" }, + "shortcuts_modal": { + "search_placeholder": "Sneltoetsen zoeken", + "no_results": "Geen sneltoetsen gevonden voor \"{query}\"", + "sequence_separator": "dan" + }, "group_titles": { "actions": "Acties", "contextual": "Contextueel", diff --git a/packages/i18n/src/locales/pl/power-k.json b/packages/i18n/src/locales/pl/power-k.json index 6498a06e513..fcc0305831a 100644 --- a/packages/i18n/src/locales/pl/power-k.json +++ b/packages/i18n/src/locales/pl/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Poziom przestrzeni roboczej" }, + "shortcuts_modal": { + "search_placeholder": "Szukaj skrótów klawiaturowych", + "no_results": "Nie znaleziono skrótów klawiaturowych dla „{query}”", + "sequence_separator": "potem" + }, "group_titles": { "actions": "Akcje", "contextual": "Kontekstowe", diff --git a/packages/i18n/src/locales/pt-BR/power-k.json b/packages/i18n/src/locales/pt-BR/power-k.json index 3b22938cc5f..6aa88128395 100644 --- a/packages/i18n/src/locales/pt-BR/power-k.json +++ b/packages/i18n/src/locales/pt-BR/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Nível do espaço de trabalho" }, + "shortcuts_modal": { + "search_placeholder": "Pesquisar atalhos do teclado", + "no_results": "Nenhum atalho do teclado encontrado para \"{query}\"", + "sequence_separator": "depois" + }, "group_titles": { "actions": "Ações", "contextual": "Contextual", diff --git a/packages/i18n/src/locales/ro/power-k.json b/packages/i18n/src/locales/ro/power-k.json index eca4f240b3d..bea7a3a89d1 100644 --- a/packages/i18n/src/locales/ro/power-k.json +++ b/packages/i18n/src/locales/ro/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "La nivel de spațiu de lucru" }, + "shortcuts_modal": { + "search_placeholder": "Căutați scurtături de tastatură", + "no_results": "Nicio scurtătură de tastatură găsită pentru „{query}”", + "sequence_separator": "apoi" + }, "group_titles": { "actions": "Acțiuni", "contextual": "Contextual", diff --git a/packages/i18n/src/locales/ru/power-k.json b/packages/i18n/src/locales/ru/power-k.json index 6d63a6c5675..5828245212a 100644 --- a/packages/i18n/src/locales/ru/power-k.json +++ b/packages/i18n/src/locales/ru/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Уровень рабочего пространства" }, + "shortcuts_modal": { + "search_placeholder": "Найти горячие клавиши", + "no_results": "Не найдено горячих клавиш для «{query}»", + "sequence_separator": "затем" + }, "group_titles": { "actions": "Действия", "contextual": "Контекстные", diff --git a/packages/i18n/src/locales/sk/power-k.json b/packages/i18n/src/locales/sk/power-k.json index 5117a6826c3..18f08bdb69d 100644 --- a/packages/i18n/src/locales/sk/power-k.json +++ b/packages/i18n/src/locales/sk/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Úroveň pracovného priestoru" }, + "shortcuts_modal": { + "search_placeholder": "Hľadať klávesové skratky", + "no_results": "Nenašli sa žiadne klávesové skratky pre „{query}“", + "sequence_separator": "potom" + }, "group_titles": { "actions": "Akcie", "contextual": "Kontextové", diff --git a/packages/i18n/src/locales/tr-TR/power-k.json b/packages/i18n/src/locales/tr-TR/power-k.json index d5afdec6a08..1228de0e5b2 100644 --- a/packages/i18n/src/locales/tr-TR/power-k.json +++ b/packages/i18n/src/locales/tr-TR/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Çalışma alanı seviyesi" }, + "shortcuts_modal": { + "search_placeholder": "Klavye kısayollarını ara", + "no_results": "\"{query}\" için klavye kısayolu bulunamadı", + "sequence_separator": "sonra" + }, "group_titles": { "actions": "Eylemler", "contextual": "Bağlamsal", diff --git a/packages/i18n/src/locales/ua/power-k.json b/packages/i18n/src/locales/ua/power-k.json index 5e4630fc664..abbfaa4fc37 100644 --- a/packages/i18n/src/locales/ua/power-k.json +++ b/packages/i18n/src/locales/ua/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Рівень робочого простору" }, + "shortcuts_modal": { + "search_placeholder": "Знайти гарячі клавіші", + "no_results": "Не знайдено гарячих клавіш для «{query}»", + "sequence_separator": "потім" + }, "group_titles": { "actions": "Дії", "contextual": "Контекстні", diff --git a/packages/i18n/src/locales/vi-VN/power-k.json b/packages/i18n/src/locales/vi-VN/power-k.json index ef55655e2d6..ecbfb7000fe 100644 --- a/packages/i18n/src/locales/vi-VN/power-k.json +++ b/packages/i18n/src/locales/vi-VN/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "Cấp không gian làm việc" }, + "shortcuts_modal": { + "search_placeholder": "Tìm phím tắt", + "no_results": "Không tìm thấy phím tắt cho \"{query}\"", + "sequence_separator": "rồi" + }, "group_titles": { "actions": "Hành động", "contextual": "Theo ngữ cảnh", diff --git a/packages/i18n/src/locales/zh-CN/power-k.json b/packages/i18n/src/locales/zh-CN/power-k.json index 88e06085141..5ae4bc84c60 100644 --- a/packages/i18n/src/locales/zh-CN/power-k.json +++ b/packages/i18n/src/locales/zh-CN/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "工作区级别" }, + "shortcuts_modal": { + "search_placeholder": "搜索键盘快捷键", + "no_results": "未找到“{query}”的键盘快捷键", + "sequence_separator": "然后" + }, "group_titles": { "actions": "操作", "contextual": "上下文", diff --git a/packages/i18n/src/locales/zh-TW/power-k.json b/packages/i18n/src/locales/zh-TW/power-k.json index 794259af97a..eef86d3ff3a 100644 --- a/packages/i18n/src/locales/zh-TW/power-k.json +++ b/packages/i18n/src/locales/zh-TW/power-k.json @@ -176,6 +176,11 @@ "footer": { "workspace_level": "工作區層級" }, + "shortcuts_modal": { + "search_placeholder": "搜尋鍵盤快速鍵", + "no_results": "找不到「{query}」的鍵盤快速鍵", + "sequence_separator": "然後" + }, "group_titles": { "actions": "操作", "contextual": "情境",