Skip to content

Commit 8c0bca3

Browse files
SunkenInTimeclaude
andcommitted
fix(web): Enter creates the new project after clicking an option
Clicking the GitHub repository option left the mouse on its row, and Enter ran the highlighted row, so it unticked the box instead of creating the project. In New project only a keyboard highlight now takes over Enter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dc19285 commit 8c0bca3

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ function OpenCommandPaletteDialog(props: {
607607
const deferredQuery = useDeferredValue(query);
608608
const isActionsOnly = deferredQuery.startsWith(">");
609609
const [highlightedItemValue, setHighlightedItemValue] = useState<string | null>(null);
610+
// Whether the mouse, rather than the keyboard, put the highlight where it is.
611+
const [isPointerHighlight, setIsPointerHighlight] = useState(false);
610612
const resultListRef = useRef<LegendListRef | null>(null);
611613
// Typing or entering a submenu clears the highlight. Base UI keeps its own on the
612614
// first row, but the palette shows none until the user navigates, and the first
@@ -2838,6 +2840,10 @@ function OpenCommandPaletteDialog(props: {
28382840
const newProjectPathPreview =
28392841
newProjectsRoot === null ? null : getNewProjectPathPreview(newProjectsRoot, newProjectName);
28402842
const newProjectPublishToggleValue = "new-project:publish";
2843+
// The rows under the name are options for the project, so Enter creates it.
2844+
// Only a row reached with the arrow keys takes Enter over; one under the
2845+
// mouse, such as the option just clicked, does not.
2846+
const newProjectEnterItemValue = isPointerHighlight ? null : highlightedItemValue;
28412847
// The name step's way out to folders and clones, for the selected machine.
28422848
// It replaces the name step (and a sources view for another machine under
28432849
// it), so Back returns to wherever New project was opened from.
@@ -3164,16 +3170,16 @@ function OpenCommandPaletteDialog(props: {
31643170
return;
31653171
}
31663172

3167-
// Enter creates the project unless an item below the name is
3168-
// highlighted, in which case it runs that item.
31693173
if (
31703174
newProjectFlow !== null &&
31713175
event.key === "Enter" &&
3172-
highlightedItemValue === null &&
3176+
newProjectEnterItemValue === null &&
31733177
// Enter that confirms an IME composition is part of typing the name.
31743178
!event.nativeEvent.isComposing &&
31753179
event.keyCode !== 229
31763180
) {
3181+
// Base UI would otherwise click the row under the mouse.
3182+
(event as typeof event & { preventBaseUIHandler?: () => void }).preventBaseUIHandler?.();
31773183
event.preventDefault();
31783184
void submitNewProject();
31793185
return;
@@ -3214,6 +3220,7 @@ function OpenCommandPaletteDialog(props: {
32143220
event.preventDefault();
32153221
highlightClearedRef.current = false;
32163222
setHighlightedItemValue(firstItemValue);
3223+
setIsPointerHighlight(false);
32173224
scrollCommandPaletteRowIntoView(
32183225
resultListRef.current,
32193226
resultRows.rowIndexByItemIndex[0] ?? 0,
@@ -3479,9 +3486,9 @@ function OpenCommandPaletteDialog(props: {
34793486

34803487
const footerActionLabel =
34813488
newProjectFlow !== null
3482-
? highlightedItemValue === null
3489+
? newProjectEnterItemValue === null
34833490
? "Create"
3484-
: highlightedItemValue === newProjectPublishToggleValue
3491+
: newProjectEnterItemValue === newProjectPublishToggleValue
34853492
? "Toggle"
34863493
: "Select"
34873494
: addProjectCloneFlow?.step === "repository"
@@ -3547,6 +3554,7 @@ function OpenCommandPaletteDialog(props: {
35473554
if (eventDetails.reason === "none" && highlightClearedRef.current) return;
35483555
highlightClearedRef.current = false;
35493556
setHighlightedItemValue(typeof value === "string" ? value : null);
3557+
setIsPointerHighlight(eventDetails.reason === "pointer");
35503558
const rowIndex = resultRows.rowIndexByItemIndex[eventDetails.index];
35513559
if (eventDetails.reason === "keyboard" && rowIndex !== undefined) {
35523560
scrollCommandPaletteRowIntoView(resultListRef.current, rowIndex);

0 commit comments

Comments
 (0)