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
17 changes: 17 additions & 0 deletions cmd/wsh/cmd/wshcmd-web.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ var webGetInner bool
var webGetAll bool
var webGetJson bool
var webOpenMagnified bool
var webOpenReplaceBlock string

func init() {
webOpenCmd.Flags().BoolVarP(&webOpenMagnified, "magnified", "m", false, "open view in magnified mode")
webOpenCmd.Flags().StringVarP(&webOpenReplaceBlock, "replace", "r", "", "replace block")
webCmd.AddCommand(webOpenCmd)
webGetCmd.Flags().BoolVarP(&webGetInner, "inner", "", false, "get inner html (instead of outer)")
webGetCmd.Flags().BoolVarP(&webGetAll, "all", "", false, "get all matches (querySelectorAll)")
Expand Down Expand Up @@ -98,6 +100,17 @@ func webOpenRun(cmd *cobra.Command, args []string) (rtnErr error) {
sendActivity("web", rtnErr == nil)
}()

var replaceBlockORef *waveobj.ORef
if webOpenReplaceBlock != "" {
var err error
replaceBlockORef, err = resolveSimpleId(webOpenReplaceBlock)
if err != nil {
return fmt.Errorf("resolving -r blockid: %w", err)
}
}
if replaceBlockORef != nil && webOpenMagnified {
return fmt.Errorf("cannot use --replace and --magnified together")
}
wshCmd := wshrpc.CommandCreateBlockData{
BlockDef: &waveobj.BlockDef{
Meta: map[string]any{
Expand All @@ -107,6 +120,10 @@ func webOpenRun(cmd *cobra.Command, args []string) (rtnErr error) {
},
Magnified: webOpenMagnified,
}
if replaceBlockORef != nil {
wshCmd.TargetBlockId = replaceBlockORef.OID
wshCmd.TargetAction = wshrpc.CreateBlockAction_Replace
}
oref, err := wshclient.CreateBlockCommand(RpcClient, wshCmd, nil)
if err != nil {
return fmt.Errorf("creating block: %w", err)
Expand Down
51 changes: 51 additions & 0 deletions frontend/app/store/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
newLayoutNode,
} from "@/layout/index";
import { getLayoutModelForStaticTab } from "@/layout/lib/layoutModelHooks";
import { LayoutTreeSplitHorizontalAction, LayoutTreeSplitVerticalAction } from "@/layout/lib/types";
import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil";
import { deepCompareReturnPrev, getPrefixedSettings, isBlank } from "@/util/util";
Expand Down Expand Up @@ -379,6 +380,54 @@ function getApi(): ElectronApi {
return (window as any).api;
}

async function createBlockSplitHorizontally(
blockDef: BlockDef,
targetBlockId: string,
position: "before" | "after"
): Promise<string> {
const tabId = globalStore.get(atoms.staticTabId);
const layoutModel = getLayoutModelForTabById(tabId);
const rtOpts: RuntimeOpts = { termsize: { rows: 25, cols: 80 } };
const newBlockId = await ObjectService.CreateBlock(blockDef, rtOpts);
const targetNodeId = layoutModel.getNodeByBlockId(targetBlockId)?.id;
if (targetNodeId == null) {
throw new Error(`targetNodeId not found for blockId: ${targetBlockId}`);
}
const splitAction: LayoutTreeSplitHorizontalAction = {
type: LayoutTreeActionType.SplitHorizontal,
targetNodeId: targetNodeId,
newNode: newLayoutNode(undefined, undefined, undefined, { blockId: newBlockId }),
position: position,
focused: true,
};
layoutModel.treeReducer(splitAction);
return newBlockId;
}

async function createBlockSplitVertically(
blockDef: BlockDef,
targetBlockId: string,
position: "before" | "after"
): Promise<string> {
const tabId = globalStore.get(atoms.staticTabId);
const layoutModel = getLayoutModelForTabById(tabId);
const rtOpts: RuntimeOpts = { termsize: { rows: 25, cols: 80 } };
const newBlockId = await ObjectService.CreateBlock(blockDef, rtOpts);
const targetNodeId = layoutModel.getNodeByBlockId(targetBlockId)?.id;
if (targetNodeId == null) {
throw new Error(`targetNodeId not found for blockId: ${targetBlockId}`);
}
const splitAction: LayoutTreeSplitVerticalAction = {
type: LayoutTreeActionType.SplitVertical,
targetNodeId: targetNodeId,
newNode: newLayoutNode(undefined, undefined, undefined, { blockId: newBlockId }),
position: position,
focused: true,
};
layoutModel.treeReducer(splitAction);
return newBlockId;
}

async function createBlock(blockDef: BlockDef, magnified = false, ephemeral = false): Promise<string> {
const tabId = globalStore.get(atoms.staticTabId);
const layoutModel = getLayoutModelForTabById(tabId);
Expand Down Expand Up @@ -682,6 +731,8 @@ export {
countersClear,
countersPrint,
createBlock,
createBlockSplitHorizontally,
createBlockSplitVertically,
createTab,
fetchWaveFile,
getAllBlockComponentModels,
Expand Down
62 changes: 62 additions & 0 deletions frontend/app/store/keymodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import {
atoms,
createBlock,
createBlockSplitHorizontally,
createBlockSplitVertically,
createTab,
getAllBlockComponentModels,
getApi,
Expand Down Expand Up @@ -198,6 +200,58 @@ async function handleCmdN() {
await createBlock(termBlockDef);
}

async function handleSplitHorizontal() {
// split horizontally
const termBlockDef: BlockDef = {
meta: {
view: "term",
controller: "shell",
},
};
const layoutModel = getLayoutModelForStaticTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
if (focusedNode == null) {
return;
}
const blockAtom = WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", focusedNode.data?.blockId));
const blockData = globalStore.get(blockAtom);
if (blockData?.meta?.view == "term") {
if (blockData?.meta?.["cmd:cwd"] != null) {
termBlockDef.meta["cmd:cwd"] = blockData.meta["cmd:cwd"];
}
}
if (blockData?.meta?.connection != null) {
termBlockDef.meta.connection = blockData.meta.connection;
}
await createBlockSplitHorizontally(termBlockDef, focusedNode.data.blockId, "after");
}

async function handleSplitVertical() {
// split horizontally
const termBlockDef: BlockDef = {
meta: {
view: "term",
controller: "shell",
},
};
const layoutModel = getLayoutModelForStaticTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
if (focusedNode == null) {
return;
}
const blockAtom = WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", focusedNode.data?.blockId));
const blockData = globalStore.get(blockAtom);
if (blockData?.meta?.view == "term") {
if (blockData?.meta?.["cmd:cwd"] != null) {
termBlockDef.meta["cmd:cwd"] = blockData.meta["cmd:cwd"];
}
}
if (blockData?.meta?.connection != null) {
termBlockDef.meta.connection = blockData.meta.connection;
}
await createBlockSplitVertically(termBlockDef, focusedNode.data.blockId, "after");
}

let lastHandledEvent: KeyboardEvent | null = null;

function appHandleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
Expand Down Expand Up @@ -280,6 +334,14 @@ function registerGlobalKeys() {
handleCmdN();
return true;
});
globalKeyMap.set("Cmd:d", () => {
handleSplitHorizontal();
return true;
});
globalKeyMap.set("Shift:Cmd:d", () => {
handleSplitVertical();
return true;
});
globalKeyMap.set("Cmd:i", () => {
handleCmdI();
return true;
Expand Down
93 changes: 91 additions & 2 deletions frontend/layout/lib/layoutModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
insertNodeAtIndex,
magnifyNodeToggle,
moveNode,
replaceNode,
resizeNode,
splitHorizontal,
splitVertical,
swapNode,
} from "./layoutTree";
import {
Expand All @@ -35,8 +38,11 @@ import {
LayoutTreeInsertNodeAtIndexAction,
LayoutTreeMagnifyNodeToggleAction,
LayoutTreeMoveNodeAction,
LayoutTreeReplaceNodeAction,
LayoutTreeResizeNodeAction,
LayoutTreeSetPendingAction,
LayoutTreeSplitHorizontalAction,
LayoutTreeSplitVerticalAction,
LayoutTreeState,
LayoutTreeSwapNodeAction,
NavigateDirection,
Expand Down Expand Up @@ -375,10 +381,18 @@ export class LayoutModel {
case LayoutTreeActionType.MagnifyNodeToggle:
magnifyNodeToggle(this.treeState, action as LayoutTreeMagnifyNodeToggleAction);
break;
case LayoutTreeActionType.ClearTree: {
case LayoutTreeActionType.ClearTree:
clearTree(this.treeState);
break;
}
case LayoutTreeActionType.ReplaceNode:
replaceNode(this.treeState, action as LayoutTreeReplaceNodeAction);
break;
case LayoutTreeActionType.SplitHorizontal:
splitHorizontal(this.treeState, action as LayoutTreeSplitHorizontalAction);
break;
case LayoutTreeActionType.SplitVertical:
splitVertical(this.treeState, action as LayoutTreeSplitVerticalAction);
break;
default:
console.error("Invalid reducer action", this.treeState, action);
}
Expand Down Expand Up @@ -472,6 +486,81 @@ export class LayoutModel {
);
break;
}
case LayoutTreeActionType.ReplaceNode: {
const targetNode = this?.getNodeByBlockId(action.targetblockid);
if (!targetNode) {
console.error(
"Cannot apply eventbus layout action ReplaceNode, could not find target node with blockId",
action.targetblockid
);
break;
}
const replaceAction: LayoutTreeReplaceNodeAction = {
type: LayoutTreeActionType.ReplaceNode,
targetNodeId: targetNode.id,
newNode: newLayoutNode(undefined, action.nodesize, undefined, {
blockId: action.blockid,
}),
};
this.treeReducer(replaceAction, false);
break;
}
case LayoutTreeActionType.SplitHorizontal: {
const targetNode = this?.getNodeByBlockId(action.targetblockid);
if (!targetNode) {
console.error(
"Cannot apply eventbus layout action SplitHorizontal, could not find target node with blockId",
action.targetblockid
);
break;
}
if (action.position != "before" && action.position != "after") {
console.error(
"Cannot apply eventbus layout action SplitHorizontal, invalid position",
action.position
);
break;
}
const newNode = newLayoutNode(undefined, action.nodesize, undefined, {
blockId: action.blockid,
});
const splitAction: LayoutTreeSplitHorizontalAction = {
type: LayoutTreeActionType.SplitHorizontal,
targetNodeId: targetNode.id,
newNode: newNode,
position: action.position,
};
this.treeReducer(splitAction, false);
break;
}
case LayoutTreeActionType.SplitVertical: {
const targetNode = this?.getNodeByBlockId(action.targetblockid);
if (!targetNode) {
console.error(
"Cannot apply eventbus layout action SplitVertical, could not find target node with blockId",
action.targetblockid
);
break;
}
if (action.position != "before" && action.position != "after") {
console.error(
"Cannot apply eventbus layout action SplitVertical, invalid position",
action.position
);
break;
}
const newNode = newLayoutNode(undefined, action.nodesize, undefined, {
blockId: action.blockid,
});
const splitAction: LayoutTreeSplitVerticalAction = {
type: LayoutTreeActionType.SplitVertical,
targetNodeId: targetNode.id,
newNode: newNode,
position: action.position,
};
this.treeReducer(splitAction, false);
break;
}
default:
console.warn("unsupported layout action", action);
break;
Expand Down
Loading
Loading