|
|
|
@ -49,6 +49,8 @@ import { jotaiStore } from "../../jotai"; |
|
|
|
import { activeConfirmDialogAtom } from "../ActiveConfirmDialog"; |
|
|
|
import { activeConfirmDialogAtom } from "../ActiveConfirmDialog"; |
|
|
|
import { CommandPaletteItem } from "./types"; |
|
|
|
import { CommandPaletteItem } from "./types"; |
|
|
|
import * as defaultItems from "./defaultCommandPaletteItems"; |
|
|
|
import * as defaultItems from "./defaultCommandPaletteItems"; |
|
|
|
|
|
|
|
import { trackEvent } from "../../analytics"; |
|
|
|
|
|
|
|
import { useStable } from "../../hooks/useStable"; |
|
|
|
|
|
|
|
|
|
|
|
import "./CommandPalette.scss"; |
|
|
|
import "./CommandPalette.scss"; |
|
|
|
|
|
|
|
|
|
|
|
@ -130,12 +132,20 @@ export const CommandPalette = Object.assign( |
|
|
|
if (isCommandPaletteToggleShortcut(event)) { |
|
|
|
if (isCommandPaletteToggleShortcut(event)) { |
|
|
|
event.preventDefault(); |
|
|
|
event.preventDefault(); |
|
|
|
event.stopPropagation(); |
|
|
|
event.stopPropagation(); |
|
|
|
setAppState((appState) => ({ |
|
|
|
setAppState((appState) => { |
|
|
|
openDialog: |
|
|
|
const nextState = |
|
|
|
appState.openDialog?.name === "commandPalette" |
|
|
|
appState.openDialog?.name === "commandPalette" |
|
|
|
? null |
|
|
|
? null |
|
|
|
: { name: "commandPalette" }, |
|
|
|
: ({ name: "commandPalette" } as const); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
if (nextState) { |
|
|
|
|
|
|
|
trackEvent("command_palette", "open", "shortcut"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
openDialog: nextState, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
window.addEventListener(EVENT.KEYDOWN, commandPaletteShortcut, { |
|
|
|
window.addEventListener(EVENT.KEYDOWN, commandPaletteShortcut, { |
|
|
|
@ -174,10 +184,20 @@ function CommandPaletteInner({ |
|
|
|
|
|
|
|
|
|
|
|
const inputRef = useRef<HTMLInputElement>(null); |
|
|
|
const inputRef = useRef<HTMLInputElement>(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stableDeps = useStable({ |
|
|
|
|
|
|
|
uiAppState, |
|
|
|
|
|
|
|
customCommandPaletteItems, |
|
|
|
|
|
|
|
appProps, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!uiAppState || !app.scene || !actionManager) { |
|
|
|
// these props change often and we don't want them to re-run the effect
|
|
|
|
return; |
|
|
|
// which would renew `allCommands`, cascading down and resetting state.
|
|
|
|
} |
|
|
|
//
|
|
|
|
|
|
|
|
// This means that the commands won't update on appState/appProps changes
|
|
|
|
|
|
|
|
// while the command palette is open
|
|
|
|
|
|
|
|
const { uiAppState, customCommandPaletteItems, appProps } = stableDeps; |
|
|
|
|
|
|
|
|
|
|
|
const getActionLabel = (action: Action) => { |
|
|
|
const getActionLabel = (action: Action) => { |
|
|
|
let label = ""; |
|
|
|
let label = ""; |
|
|
|
if (action.label) { |
|
|
|
if (action.label) { |
|
|
|
@ -533,15 +553,13 @@ function CommandPaletteInner({ |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [ |
|
|
|
}, [ |
|
|
|
|
|
|
|
stableDeps, |
|
|
|
app, |
|
|
|
app, |
|
|
|
appProps, |
|
|
|
|
|
|
|
uiAppState, |
|
|
|
|
|
|
|
actionManager, |
|
|
|
actionManager, |
|
|
|
setAllCommands, |
|
|
|
setAllCommands, |
|
|
|
lastUsed?.label, |
|
|
|
lastUsed?.label, |
|
|
|
setLastUsed, |
|
|
|
setLastUsed, |
|
|
|
setAppState, |
|
|
|
setAppState, |
|
|
|
customCommandPaletteItems, |
|
|
|
|
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
const [commandSearch, setCommandSearch] = useState(""); |
|
|
|
const [commandSearch, setCommandSearch] = useState(""); |
|
|
|
|