mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
feat(studio): auto-reveal source when selecting elements in Code tab
When the Code tab is active and a user clicks an element in the preview, the code editor now auto-scrolls to the corresponding HTML source. This removes the need for Alt+click — the existing click-to-source mechanism fires automatically when the Code tab is already open. - Add getTab() to LeftSidebarHandle for reading the active tab - Add getSidebarTab getter to useDomEditSession - Add effect that calls openSourceForSelection on selection change when Code tab is active
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
useState,
|
||||
useCallback,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
forwardRef,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
@@ -17,6 +18,7 @@ export type SidebarTab = "compositions" | "assets" | "code" | "blocks";
|
||||
|
||||
export interface LeftSidebarHandle {
|
||||
selectTab: (tab: SidebarTab) => void;
|
||||
getTab: () => SidebarTab;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = "hf-studio-sidebar-tab";
|
||||
@@ -87,6 +89,8 @@ export const LeftSidebar = memo(
|
||||
ref,
|
||||
) {
|
||||
const [tab, setTab] = useState<SidebarTab>(getPersistedTab);
|
||||
const tabRef = useRef(tab);
|
||||
tabRef.current = tab;
|
||||
|
||||
const selectTab = useCallback((t: SidebarTab) => {
|
||||
setTab(t);
|
||||
@@ -94,7 +98,9 @@ export const LeftSidebar = memo(
|
||||
trackStudioEvent("tab_switch", { panel: "left_sidebar", tab: t });
|
||||
}, []);
|
||||
|
||||
useImperativeHandle(ref, () => ({ selectTab }), [selectTab]);
|
||||
const getTab = useCallback(() => tabRef.current, []);
|
||||
|
||||
useImperativeHandle(ref, () => ({ selectTab, getTab }), [selectTab, getTab]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user