This commit is contained in:
Evan Simkowitz 2024-10-10 11:48:44 -04:00
parent ad3166a2c9
commit 24a47496a5
No known key found for this signature in database
4 changed files with 62 additions and 8 deletions

View File

@ -398,6 +398,12 @@ async function openLink(uri: string, forceOpenInternally = false) {
}
}
function getActiveBlockId() {
const layoutModel = getLayoutModelForActiveTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
return focusedNode?.data?.blockId;
}
function registerBlockComponentModel(blockId: string, bcm: BlockComponentModel) {
blockComponentModelMap.set(blockId, bcm);
}
@ -410,6 +416,11 @@ function getBlockComponentModel(blockId: string): BlockComponentModel {
return blockComponentModelMap.get(blockId);
}
function getActiveBlockComponentModel(): BlockComponentModel {
const blockId = getActiveBlockId();
return getBlockComponentModel(blockId);
}
function refocusNode(blockId: string) {
if (blockId == null) {
return;
@ -457,6 +468,15 @@ async function loadConnStatus() {
}
}
function subscribeToBrowserEvents() {
window.addEventListener("hashchange", (e) => {
console.log("hashchange");
});
window.addEventListener("popstate", (e) => {
console.log("popstate");
});
}
function subscribeToConnEvents() {
waveEventSubscribe({
eventType: "connchange",
@ -529,6 +549,8 @@ export {
countersPrint,
createBlock,
fetchWaveFile,
getActiveBlockComponentModel,
getActiveBlockId,
getApi,
getBlockComponentModel,
getConnStatusAtom,
@ -549,6 +571,7 @@ export {
removeFlashError,
setNodeFocus,
setPlatform,
subscribeToBrowserEvents,
subscribeToConnEvents,
unregisterBlockComponentModel,
useBlockAtom,

View File

@ -1,7 +1,15 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { atoms, createBlock, getApi, getBlockComponentModel, globalStore, refocusNode, WOS } from "@/app/store/global";
import {
atoms,
createBlock,
getActiveBlockComponentModel,
getApi,
globalStore,
refocusNode,
WOS,
} from "@/app/store/global";
import * as services from "@/app/store/services";
import {
deleteLayoutModelForTab,
@ -163,11 +171,8 @@ function appHandleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
if (handled) {
return true;
}
const layoutModel = getLayoutModelForActiveTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
const blockId = focusedNode?.data?.blockId;
if (blockId != null && shouldDispatchToBlock(waveEvent)) {
const bcm = getBlockComponentModel(blockId);
if (shouldDispatchToBlock(waveEvent)) {
const bcm = getActiveBlockComponentModel();
const viewModel = bcm?.viewModel;
if (viewModel?.keyDownHandler) {
const handledByBlock = viewModel.keyDownHandler(waveEvent);
@ -264,12 +269,33 @@ function registerGlobalKeys() {
return true;
});
globalKeyMap.set("Cmd:g", () => {
const bcm = getBlockComponentModel(getFocusedBlockInActiveTab());
const bcm = getActiveBlockComponentModel();
if (bcm.openSwitchConnection != null) {
bcm.openSwitchConnection();
return true;
}
});
const onBrowserBack = () => {
console.log("onBrowserBack");
const bcm = getActiveBlockComponentModel();
const onBack = bcm?.viewModel?.onBack;
if (onBack != null) {
onBack();
return true;
}
};
globalKeyMap.set("BrowserBack", onBrowserBack);
globalKeyMap.set("GoBack", onBrowserBack);
const onBrowserForward = () => {
console.log("onBrowserForward");
const bcm = getActiveBlockComponentModel();
const onForward = bcm?.viewModel?.onForward;
onForward();
return true;
}
};
globalKeyMap.set("BrowserForward", onBrowserForward);
for (let idx = 1; idx <= 9; idx++) {
globalKeyMap.set(`Cmd:${idx}`, () => {
switchTabAbs(idx);

View File

@ -477,7 +477,10 @@ function TableBody({
model.goHistory(newFileName);
setSearch("");
}}
onClick={() => setFocusIndex(idx)}
onClick={(e) => {
setFocusIndex(idx);
console.log("onclick", e.nativeEvent);
}}
onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path"), row.getValue("mimetype"))}
>
{row.getVisibleCells().map((cell) => (

View File

@ -23,6 +23,7 @@ import {
initGlobalWaveEventSubs,
loadConnStatus,
pushFlashError,
subscribeToBrowserEvents,
subscribeToConnEvents,
} from "@/store/global";
import * as WOS from "@/store/wos";
@ -67,6 +68,7 @@ document.addEventListener("DOMContentLoaded", async () => {
await loadConnStatus();
initGlobalWaveEventSubs();
subscribeToConnEvents();
subscribeToBrowserEvents();
// ensures client/window/workspace are loaded into the cache before rendering
const client = await WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", clientId));