Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion emain/emain-window.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025, Command Line Inc.
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { ClientService, ObjectService, WindowService, WorkspaceService } from "@/app/store/services";
Expand Down Expand Up @@ -167,6 +167,7 @@ export class WaveBrowserWindow extends BaseWindow {
winOpts.titleBarStyle = "hiddenInset";
winOpts.titleBarOverlay = false;
winOpts.autoHideMenuBar = !settings?.["window:showmenubar"];
winOpts.acceptFirstMouse = true;
if (isTransparent) {
winOpts.transparent = true;
} else if (isBlur) {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/aipanel/aipanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ const AIPanelComponentInner = memo(({ roundTopLeft }: AIPanelComponentInnerProps
onDrop={handleDrop}
onClick={handleClick}
inert={!isPanelVisible ? true : undefined}
data-aipanel="true"
>
<ConfigChangeModeFixer />
{(isDragOver || isReactDndDragOver) && allowAccess && <AIDragOverlay />}
Expand Down
81 changes: 80 additions & 1 deletion frontend/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getBlockBadgeAtom,
} from "@/app/store/badge";
import { ClientModel } from "@/app/store/client-model";
import { FocusManager } from "@/app/store/focusManager";
import { GlobalModel } from "@/app/store/global-model";
import { globalStore } from "@/app/store/jotaiStore";
import { getTabModelByTabId, TabModelContext } from "@/app/store/tab-model";
Expand All @@ -16,7 +17,7 @@ import { makeWaveEnvImpl } from "@/app/waveenv/waveenvimpl";
import { Workspace } from "@/app/workspace/workspace";
import { getLayoutModelForStaticTab } from "@/layout/index";
import { ContextMenuModel } from "@/store/contextmenu";
import { atoms, createBlock, getSettingsPrefixAtom } from "@/store/global";
import { atoms, createBlock, getSettingsPrefixAtom, refocusNode } from "@/store/global";
import { appHandleKeyDown, keyboardMouseDownHandler } from "@/store/keymodel";
import { getElemAsStr } from "@/util/focusutil";
import * as keyutil from "@/util/keyutil";
Expand Down Expand Up @@ -203,6 +204,83 @@ function AppFocusHandler() {
return null;
}

const MacOSFirstClickHandler = () => {
useEffect(() => {
if (PLATFORM !== "darwin") {
return;
}
let windowFocusTime: number = null;
let cancelNextClick = false;
const handleWindowFocus = (e: FocusEvent) => {
windowFocusTime = Date.now();
};
const getBlockIdFromTarget = (target: EventTarget): string => {
let elem = target as HTMLElement;
while (elem != null) {
const blockId = elem.dataset?.blockid;
if (blockId) {
return blockId;
}
elem = elem.parentElement;
}
return null;
};
const isAIPanelTarget = (target: EventTarget): boolean => {
let elem = target as HTMLElement;
while (elem != null) {
if (elem.dataset?.aipanel) {
return true;
}
elem = elem.parentElement;
}
return false;
};
const handleMouseDown = (e: MouseEvent) => {
const timeDiff = Date.now() - windowFocusTime;
if (windowFocusTime != null && timeDiff < 50) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
cancelNextClick = true;
const blockId = getBlockIdFromTarget(e.target);
if (blockId != null) {
setTimeout(() => {
console.log("macos first-click, focusing block", blockId);
refocusNode(blockId);
}, 10);
} else if (isAIPanelTarget(e.target)) {
setTimeout(() => {
console.log("macos first-click, focusing AI panel");
FocusManager.getInstance().setWaveAIFocused(true);
}, 10);
}
console.log("macos first-click detected, canceled", timeDiff + "ms");
return;
}
cancelNextClick = false;
};
const handleClick = (e: MouseEvent) => {
if (!cancelNextClick) {
return;
}
cancelNextClick = false;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
console.log("macos first-click (click event) canceled");
};
window.addEventListener("focus", handleWindowFocus);
window.addEventListener("mousedown", handleMouseDown, true);
window.addEventListener("click", handleClick, true);
return () => {
window.removeEventListener("focus", handleWindowFocus);
window.removeEventListener("mousedown", handleMouseDown, true);
window.removeEventListener("click", handleClick, true);
};
}, []);
return null;
};

const AppKeyHandlers = () => {
useEffect(() => {
const staticKeyDownHandler = keyutil.keydownWrapper(appHandleKeyDown);
Expand Down Expand Up @@ -300,6 +378,7 @@ const AppInner = () => {
onContextMenu={handleContextMenu}
>
<AppBackground />
<MacOSFirstClickHandler />
<AppKeyHandlers />
<AppFocusHandler />
<AppSettingsUpdater />
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/store/focusManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { waveAIHasFocusWithin } from "@/app/aipanel/waveai-focus-utils";
import { WaveAIModel } from "@/app/aipanel/waveai-model";
import { atoms, getBlockComponentModel } from "@/app/store/global";
import { getBlockComponentModel } from "@/app/store/global";
import { globalStore } from "@/app/store/jotaiStore";
import { focusedBlockId } from "@/util/focusutil";
import { getLayoutModelForStaticTab } from "@/layout/index";
import { focusedBlockId } from "@/util/focusutil";
import { Atom, atom, type PrimitiveAtom } from "jotai";

export type FocusStrType = "node" | "waveai";
Expand Down
3 changes: 1 addition & 2 deletions frontend/app/store/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ function useBlockAtom<T>(blockId: string, name: string, makeFn: () => Atom<T>):
if (atom == null) {
atom = makeFn();
blockCache.set(name, atom);
console.log("New BlockAtom", blockId, name);
}
return atom as Atom<T>;
}
Expand Down Expand Up @@ -666,8 +665,8 @@ export {
getApi,
getBlockComponentModel,
getBlockMetaKeyAtom,
getConnConfigKeyAtom,
getBlockTermDurableAtom,
getConnConfigKeyAtom,
getConnStatusAtom,
getFocusedBlockId,
getHostName,
Expand Down
Loading