Auto-open left drawer for selector shortcuts
This commit is contained in:
@@ -338,55 +338,55 @@ const InstanceShell2: Component<InstanceShellProps> = (props) => {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const runAfterDrawerReady = (callback: (() => void) | undefined, attempts = 12) => {
|
interface PendingSidebarAction {
|
||||||
if (!callback) return
|
action: SessionSidebarRequestAction
|
||||||
if (leftDrawerContentEl()) {
|
id: number
|
||||||
requestAnimationFrame(() => callback())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (attempts <= 0) return
|
|
||||||
requestAnimationFrame(() => runAfterDrawerReady(callback, attempts - 1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ensureLeftDrawerVisible = (callback?: () => void) => {
|
let sidebarActionId = 0
|
||||||
if (leftPinned()) {
|
const [pendingSidebarAction, setPendingSidebarAction] = createSignal<PendingSidebarAction | null>(null)
|
||||||
runAfterDrawerReady(callback)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!leftOpen()) {
|
|
||||||
setLeftOpen(true)
|
|
||||||
measureDrawerHost()
|
|
||||||
}
|
|
||||||
runAfterDrawerReady(callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
const focusAgentSelectorControl = () => {
|
const focusAgentSelectorControl = () => {
|
||||||
const agentTrigger = leftDrawerContentEl()?.querySelector("[data-agent-selector]") as HTMLElement | null
|
const agentTrigger = leftDrawerContentEl()?.querySelector("[data-agent-selector]") as HTMLElement | null
|
||||||
if (!agentTrigger) return
|
if (!agentTrigger) return false
|
||||||
agentTrigger.focus()
|
agentTrigger.focus()
|
||||||
setTimeout(() => agentTrigger.click(), 20)
|
setTimeout(() => agentTrigger.click(), 10)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const focusModelSelectorControl = () => {
|
const focusModelSelectorControl = () => {
|
||||||
const trigger = leftDrawerContentEl()?.querySelector(
|
const trigger = leftDrawerContentEl()?.querySelector<HTMLElement>(
|
||||||
"[data-model-selector-control] .selector-trigger",
|
"[data-model-selector-control] .selector-trigger",
|
||||||
) as HTMLElement | null
|
)
|
||||||
if (!trigger) return
|
if (!trigger) return false
|
||||||
trigger.focus()
|
trigger.focus()
|
||||||
setTimeout(() => trigger.click(), 20)
|
setTimeout(() => trigger.click(), 10)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSidebarRequest = (action: SessionSidebarRequestAction) => {
|
createEffect(() => {
|
||||||
if (action === "focus-agent-selector") {
|
const pending = pendingSidebarAction()
|
||||||
ensureLeftDrawerVisible(() => focusAgentSelectorControl())
|
if (!pending) return
|
||||||
return
|
const action = pending.action
|
||||||
}
|
const contentReady = Boolean(leftDrawerContentEl())
|
||||||
if (action === "focus-model-selector") {
|
if (!contentReady) {
|
||||||
ensureLeftDrawerVisible(() => focusModelSelectorControl())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (action === "show-session-list") {
|
if (action === "show-session-list") {
|
||||||
ensureLeftDrawerVisible()
|
setPendingSidebarAction(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const handled = action === "focus-agent-selector" ? focusAgentSelectorControl() : focusModelSelectorControl()
|
||||||
|
if (handled) {
|
||||||
|
setPendingSidebarAction(null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleSidebarRequest = (action: SessionSidebarRequestAction) => {
|
||||||
|
setPendingSidebarAction({ action, id: sidebarActionId++ })
|
||||||
|
if (!leftPinned() && !leftOpen()) {
|
||||||
|
setLeftOpen(true)
|
||||||
|
measureDrawerHost()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user