diff --git a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx index 817316a520..340bab9a0c 100644 --- a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx +++ b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx @@ -24,15 +24,18 @@ export interface TabsUIApi { interface ITabsState { selectedIndex: number, fileDecorations: fileDecoration[], + currentExt: string } interface ITabsAction { type: string, payload: any, + ext?: string, } const initialTabsState: ITabsState = { selectedIndex: -1, fileDecorations: [], + currentExt: '' } const tabsReducer = (state: ITabsState, action: ITabsAction) => { @@ -40,6 +43,7 @@ const tabsReducer = (state: ITabsState, action: ITabsAction) => { case 'SELECT_INDEX': return { ...state, + currentExt: action.ext, selectedIndex: action.payload, } case 'SET_FILE_DECORATIONS': @@ -54,7 +58,6 @@ const tabsReducer = (state: ITabsState, action: ITabsAction) => { export const TabsUI = (props: TabsUIProps) => { const [tabsState, dispatch] = useReducer(tabsReducer, initialTabsState); - const [currentFileExt, setCurrentFileExt] = useState('sol') const currentIndexRef = useRef(-1) const tabsRef = useRef({}) const tabsElement = useRef(null) @@ -104,9 +107,7 @@ export const TabsUI = (props: TabsUIProps) => { const activateTab = (name: string) => { const index = tabs.current.findIndex((tab) => tab.name === name) currentIndexRef.current = index - const ext = getExt(name) - setCurrentFileExt(ext) - dispatch({ type: 'SELECT_INDEX', payload: index }) + dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(name)}) } const setFileDecorations = (fileStates: fileDecoration[]) => { @@ -136,32 +137,32 @@ export const TabsUI = (props: TabsUIProps) => { const root = path.split('#')[0].split('?')[0] const ext = root.indexOf('.') !== -1 ? /[^.]+$/.exec(root) : null if (ext) return ext[0] - else return'txt' + else return '' } return (
- - - Run script - - - }> - - + + props.onZoomOut()}> props.onZoomIn()}>
@@ -176,7 +177,7 @@ export const TabsUI = (props: TabsUIProps) => { onSelect={(index) => { props.onSelect(index) currentIndexRef.current = index - dispatch({ type: 'SELECT_INDEX', payload: index }) + dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(props.tabs[currentIndexRef.current].name)}) }} >