mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 17:01:37 +03:00
fix(tui): restore session focus during permission prompts (#45391)
This commit is contained in:
committed by
GitHub
Unverified
parent
5ac4156eb2
commit
6b0613ac6f
@@ -1,5 +1,5 @@
|
||||
import { RGBA } from "@opentui/core"
|
||||
import { useTerminalDimensions } from "@opentui/solid"
|
||||
import { useRenderer, useTerminalDimensions } from "@opentui/solid"
|
||||
import { batch, createEffect, createMemo, createResource, createSignal, on, Show } from "solid-js"
|
||||
import { useConfig } from "../config"
|
||||
import { useData } from "../context/data"
|
||||
@@ -18,6 +18,7 @@ export function SessionFrame(props: { sessionID: string; verticalTabsWidth: numb
|
||||
const config = useConfig()
|
||||
const data = useData()
|
||||
const toast = useToast()
|
||||
const renderer = useRenderer()
|
||||
const dimensions = useTerminalDimensions()
|
||||
const [sidebarOpen, setSidebarOpen] = createSignal(false)
|
||||
const [sessionWidth, setSessionWidth] = createSignal<number>()
|
||||
@@ -66,10 +67,15 @@ export function SessionFrame(props: { sessionID: string; verticalTabsWidth: numb
|
||||
if (!visible && selectedTerminal()) void sessions.selectTerminal(props.sessionID, null).catch(toast.error)
|
||||
})
|
||||
}
|
||||
const focusSession = () => {
|
||||
// Permission prompts replace the input, so returning focus must not depend on it.
|
||||
if (terminalFocused()) renderer.currentFocusedRenderable?.blur()
|
||||
prompt.current?.focus()
|
||||
}
|
||||
createEffect(() => {
|
||||
if (!restoreTerminalFocus() || selectedTerminal()) return
|
||||
setRestoreTerminalFocus(false)
|
||||
prompt.current?.focus()
|
||||
focusSession()
|
||||
})
|
||||
Keymap.createLayer(() => ({
|
||||
enabled: () => config.data.session.terminal === true,
|
||||
@@ -77,9 +83,7 @@ export function SessionFrame(props: { sessionID: string; verticalTabsWidth: numb
|
||||
{
|
||||
id: "pane.focus.left",
|
||||
title: "Focus session pane",
|
||||
run: () => {
|
||||
prompt.current?.focus()
|
||||
},
|
||||
run: focusSession,
|
||||
},
|
||||
{
|
||||
id: "pane.focus.right",
|
||||
@@ -119,7 +123,8 @@ export function SessionFrame(props: { sessionID: string; verticalTabsWidth: numb
|
||||
width="100%"
|
||||
height="100%"
|
||||
zIndex={1}
|
||||
onMouseDown={() => prompt.current?.focus()}
|
||||
// Consume the release before revealing permission buttons underneath.
|
||||
onMouseUp={focusSession}
|
||||
/>
|
||||
</Show>
|
||||
</box>
|
||||
|
||||
@@ -143,7 +143,8 @@ export function TerminalPane(props: {
|
||||
},
|
||||
{ priority: 100 },
|
||||
)
|
||||
const onFocused = () => props.onFocusChange?.(terminal?.focused === true)
|
||||
// Blur emits this event before updating the terminal's own focused flag.
|
||||
const onFocused = () => props.onFocusChange?.(renderer.currentFocusedRenderable === terminal)
|
||||
renderer.on(CliRenderEvents.FOCUSED_RENDERABLE, onFocused)
|
||||
createEffect(() => {
|
||||
if (!props.autoFocus || !terminal) return
|
||||
|
||||
Reference in New Issue
Block a user