mirror of
https://github.com/block/buzz.git
synced 2026-11-04 00:12:02 +00:00
feat(terminal): focus management — terminal on open, composer on close
- Opening terminal: xterm.focus() called after fit in the visibility effect - Closing terminal: ProseMirror editor focused via querySelector after rAF - Works for all paths: pill click, ⌘+J toggle, trash icon kill
This commit is contained in:
@@ -35,6 +35,21 @@ export function TerminalProvider({ children }: { children: React.ReactNode }) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Focus management: return focus to composer when terminal closes.
|
||||
const prevOpenRef = React.useRef(isOpen);
|
||||
React.useEffect(() => {
|
||||
if (prevOpenRef.current && !isOpen) {
|
||||
// Terminal just closed — focus the composer.
|
||||
requestAnimationFrame(() => {
|
||||
const editor = document.querySelector<HTMLElement>(
|
||||
'[data-testid="message-composer"] .ProseMirror',
|
||||
);
|
||||
editor?.focus();
|
||||
});
|
||||
}
|
||||
prevOpenRef.current = isOpen;
|
||||
}, [isOpen]);
|
||||
|
||||
const value = React.useMemo(
|
||||
() => ({ isOpen, toggle, close }),
|
||||
[isOpen, toggle, close],
|
||||
|
||||
@@ -212,11 +212,12 @@ export function TerminalInstance({
|
||||
};
|
||||
}, [channelId, isVisible]);
|
||||
|
||||
// Re-fit when visibility changes.
|
||||
// Re-fit and focus when visibility changes.
|
||||
React.useEffect(() => {
|
||||
if (isVisible && fitAddonRef.current) {
|
||||
requestAnimationFrame(() => {
|
||||
fitAddonRef.current?.fit();
|
||||
termRef.current?.focus();
|
||||
if (sessionIdRef.current && termRef.current) {
|
||||
invoke("terminal_resize", {
|
||||
input: {
|
||||
|
||||
Reference in New Issue
Block a user