mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Explicitly set focus on insert (#285)
Adds a flag to the insert layout action to explicitly set the focus of a newly inserted node. This also adds a flag in the starter layout to focus on the terminal block.
This commit is contained in:
parent
a3aa941b68
commit
fb65ec1e23
@ -433,6 +433,7 @@ async function createBlock(blockDef: BlockDef, magnified = false): Promise<strin
|
|||||||
type: LayoutTreeActionType.InsertNode,
|
type: LayoutTreeActionType.InsertNode,
|
||||||
node: newLayoutNode(undefined, undefined, undefined, { blockId }),
|
node: newLayoutNode(undefined, undefined, undefined, { blockId }),
|
||||||
magnified,
|
magnified,
|
||||||
|
focused: true,
|
||||||
};
|
};
|
||||||
const activeTabId = globalStore.get(atoms.uiContext).activetabid;
|
const activeTabId = globalStore.get(atoms.uiContext).activetabid;
|
||||||
const layoutModel = getLayoutModelForTabById(activeTabId);
|
const layoutModel = getLayoutModelForTabById(activeTabId);
|
||||||
|
@ -393,6 +393,7 @@ export class LayoutModel {
|
|||||||
blockId: action.blockid,
|
blockId: action.blockid,
|
||||||
}),
|
}),
|
||||||
magnified: action.magnified,
|
magnified: action.magnified,
|
||||||
|
focused: action.focused,
|
||||||
};
|
};
|
||||||
this.treeReducer(insertNodeAction);
|
this.treeReducer(insertNodeAction);
|
||||||
break;
|
break;
|
||||||
@ -423,6 +424,7 @@ export class LayoutModel {
|
|||||||
}),
|
}),
|
||||||
indexArr: action.indexarr,
|
indexArr: action.indexarr,
|
||||||
magnified: action.magnified,
|
magnified: action.magnified,
|
||||||
|
focused: action.focused,
|
||||||
};
|
};
|
||||||
this.treeReducer(insertAction);
|
this.treeReducer(insertAction);
|
||||||
break;
|
break;
|
||||||
|
@ -75,7 +75,6 @@ export function useDebouncedNodeInnerRect(nodeModel: NodeModel): CSSProperties {
|
|||||||
}
|
}
|
||||||
setDebounceTimeout(
|
setDebounceTimeout(
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log("setting inner rect", nodeInnerRect);
|
|
||||||
setInnerRect(nodeInnerRect);
|
setInnerRect(nodeInnerRect);
|
||||||
setDebounceTimeout(null);
|
setDebounceTimeout(null);
|
||||||
}, nodeModel.animationTimeS * 1000)
|
}, nodeModel.animationTimeS * 1000)
|
||||||
|
@ -268,7 +268,10 @@ export function insertNode(layoutState: LayoutTreeState, action: LayoutTreeInser
|
|||||||
addChildAt(insertLoc.node, insertLoc.index, action.node);
|
addChildAt(insertLoc.node, insertLoc.index, action.node);
|
||||||
if (action.magnified) {
|
if (action.magnified) {
|
||||||
layoutState.magnifiedNodeId = action.node.id;
|
layoutState.magnifiedNodeId = action.node.id;
|
||||||
|
layoutState.focusedNodeId = action.node.id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (action.focused) {
|
||||||
layoutState.focusedNodeId = action.node.id;
|
layoutState.focusedNodeId = action.node.id;
|
||||||
}
|
}
|
||||||
layoutState.generation++;
|
layoutState.generation++;
|
||||||
@ -290,7 +293,10 @@ export function insertNodeAtIndex(layoutState: LayoutTreeState, action: LayoutTr
|
|||||||
addChildAt(insertLoc.node, insertLoc.index + 1, action.node);
|
addChildAt(insertLoc.node, insertLoc.index + 1, action.node);
|
||||||
if (action.magnified) {
|
if (action.magnified) {
|
||||||
layoutState.magnifiedNodeId = action.node.id;
|
layoutState.magnifiedNodeId = action.node.id;
|
||||||
|
layoutState.focusedNodeId = action.node.id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (action.focused) {
|
||||||
layoutState.focusedNodeId = action.node.id;
|
layoutState.focusedNodeId = action.node.id;
|
||||||
}
|
}
|
||||||
layoutState.generation++;
|
layoutState.generation++;
|
||||||
|
@ -125,7 +125,11 @@ interface InsertNodeOperation {
|
|||||||
/**
|
/**
|
||||||
* Whether the inserted node should be magnified.
|
* Whether the inserted node should be magnified.
|
||||||
*/
|
*/
|
||||||
magnified?: boolean;
|
magnified: boolean;
|
||||||
|
/**
|
||||||
|
* Whether the inserted node should be focused.
|
||||||
|
*/
|
||||||
|
focused: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
3
frontend/types/gotypes.d.ts
vendored
3
frontend/types/gotypes.d.ts
vendored
@ -209,7 +209,8 @@ declare global {
|
|||||||
blockid: string;
|
blockid: string;
|
||||||
nodesize?: number;
|
nodesize?: number;
|
||||||
indexarr?: number[];
|
indexarr?: number[];
|
||||||
magnified?: boolean;
|
focused: boolean;
|
||||||
|
magnified: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// waveobj.LayoutState
|
// waveobj.LayoutState
|
||||||
|
@ -139,6 +139,7 @@ func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId
|
|||||||
wlayout.QueueLayoutActionForTab(ctx, newWindow.ActiveTabId, waveobj.LayoutActionData{
|
wlayout.QueueLayoutActionForTab(ctx, newWindow.ActiveTabId, waveobj.LayoutActionData{
|
||||||
ActionType: wlayout.LayoutActionDataType_Insert,
|
ActionType: wlayout.LayoutActionDataType_Insert,
|
||||||
BlockId: blockId,
|
BlockId: blockId,
|
||||||
|
Focused: true,
|
||||||
})
|
})
|
||||||
return waveobj.ContextGetUpdatesRtn(ctx), nil
|
return waveobj.ContextGetUpdatesRtn(ctx), nil
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,8 @@ type LayoutActionData struct {
|
|||||||
BlockId string `json:"blockid"`
|
BlockId string `json:"blockid"`
|
||||||
NodeSize *uint `json:"nodesize,omitempty"`
|
NodeSize *uint `json:"nodesize,omitempty"`
|
||||||
IndexArr *[]int `json:"indexarr,omitempty"`
|
IndexArr *[]int `json:"indexarr,omitempty"`
|
||||||
Magnified *bool `json:"magnified,omitempty"`
|
Focused bool `json:"focused"`
|
||||||
|
Magnified bool `json:"magnified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LayoutState struct {
|
type LayoutState struct {
|
||||||
|
@ -24,6 +24,7 @@ type PortableLayout []struct {
|
|||||||
IndexArr []int `json:"indexarr"`
|
IndexArr []int `json:"indexarr"`
|
||||||
Size *uint `json:"size,omitempty"`
|
Size *uint `json:"size,omitempty"`
|
||||||
BlockDef *waveobj.BlockDef `json:"blockdef"`
|
BlockDef *waveobj.BlockDef `json:"blockdef"`
|
||||||
|
Focused bool `json:"focused"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStarterLayout() PortableLayout {
|
func GetStarterLayout() PortableLayout {
|
||||||
@ -33,7 +34,7 @@ func GetStarterLayout() PortableLayout {
|
|||||||
waveobj.MetaKey_View: "term",
|
waveobj.MetaKey_View: "term",
|
||||||
waveobj.MetaKey_Controller: "shell",
|
waveobj.MetaKey_Controller: "shell",
|
||||||
},
|
},
|
||||||
}},
|
}, Focused: true},
|
||||||
{IndexArr: []int{1}, BlockDef: &waveobj.BlockDef{
|
{IndexArr: []int{1}, BlockDef: &waveobj.BlockDef{
|
||||||
Meta: waveobj.MetaMapType{
|
Meta: waveobj.MetaMapType{
|
||||||
waveobj.MetaKey_View: "cpuplot",
|
waveobj.MetaKey_View: "cpuplot",
|
||||||
@ -77,7 +78,7 @@ func GetNewTabLayout() PortableLayout {
|
|||||||
waveobj.MetaKey_View: "term",
|
waveobj.MetaKey_View: "term",
|
||||||
waveobj.MetaKey_Controller: "shell",
|
waveobj.MetaKey_Controller: "shell",
|
||||||
},
|
},
|
||||||
}},
|
}, Focused: true},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +133,7 @@ func ApplyPortableLayout(ctx context.Context, tabId string, layout PortableLayou
|
|||||||
BlockId: blockData.OID,
|
BlockId: blockData.OID,
|
||||||
IndexArr: &layoutAction.IndexArr,
|
IndexArr: &layoutAction.IndexArr,
|
||||||
NodeSize: layoutAction.Size,
|
NodeSize: layoutAction.Size,
|
||||||
|
Focused: layoutAction.Focused,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,8 @@ func (ws *WshServer) CreateBlockCommand(ctx context.Context, data wshrpc.Command
|
|||||||
wlayout.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
|
wlayout.QueueLayoutActionForTab(ctx, tabId, waveobj.LayoutActionData{
|
||||||
ActionType: wlayout.LayoutActionDataType_Insert,
|
ActionType: wlayout.LayoutActionDataType_Insert,
|
||||||
BlockId: blockRef.OID,
|
BlockId: blockRef.OID,
|
||||||
Magnified: &data.Magnified,
|
Magnified: data.Magnified,
|
||||||
|
Focused: true,
|
||||||
})
|
})
|
||||||
return &waveobj.ORef{OType: waveobj.OType_Block, OID: blockRef.OID}, nil
|
return &waveobj.ORef{OType: waveobj.OType_Block, OID: blockRef.OID}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user