@@ -14,13 +14,15 @@ import {
1414 useLanguageServerEnabled ,
1515 useVimModeEnabled ,
1616 useMatchProgressBarEnabled ,
17- useObjdiffClientEnabled ,
17+ useDefaultDiffTab ,
18+ DefaultDiffTab ,
1819} from "@/lib/settings" ;
1920
2021import CompilerOpts from "../compiler/CompilerOpts" ;
2122import CustomLayout , {
2223 activateTabInLayout ,
2324 type Layout ,
25+ visitLayout ,
2426} from "../CustomLayout" ;
2527import CompilationPanel from "../Diff/CompilationPanel" ;
2628import CodeMirror from "../Editor/CodeMirror" ;
@@ -121,6 +123,24 @@ function getDefaultLayout(
121123 return "mobile_2row" ;
122124}
123125
126+ function cloneValue < T > ( layout : T ) : T {
127+ return JSON . parse ( JSON . stringify ( layout ) ) as T ;
128+ }
129+
130+ function applyDefaultDiffTab (
131+ layout : Layout ,
132+ defaultDiffTab : DefaultDiffTab ,
133+ ) : Layout {
134+ const preferredTab =
135+ defaultDiffTab === DefaultDiffTab . OBJDIFF ? TabId . OBJDIFF : TabId . DIFF ;
136+ visitLayout ( layout , ( node ) => {
137+ if ( node . kind === "pane" && node . tabs . includes ( preferredTab ) ) {
138+ node . activeTab = preferredTab ;
139+ }
140+ } ) ;
141+ return layout ;
142+ }
143+
124144export type Props = {
125145 scratch : Readonly < api . Scratch > ;
126146 onChange : ( scratch : Partial < api . Scratch > ) => void ;
@@ -150,6 +170,7 @@ export default function Scratch({
150170 const [ autoRecompileDelaySetting ] = useAutoRecompileDelaySetting ( ) ;
151171 const [ languageServerEnabledSetting ] = useLanguageServerEnabled ( ) ;
152172 const [ matchProgressBarEnabledSetting ] = useMatchProgressBarEnabled ( ) ;
173+ const [ defaultDiffTab ] = useDefaultDiffTab ( ) ;
153174 const { compilation, isCompiling, isCompilationOld, compile } =
154175 api . useCompilation (
155176 scratch ,
@@ -210,15 +231,13 @@ export default function Scratch({
210231 useEffect ( ( ) => {
211232 if ( decompilationTabEnabled ) {
212233 setLayout ( ( layout ) => {
213- const clone = { ... layout } ;
234+ const clone = cloneValue ( layout ) ;
214235 activateTabInLayout ( clone , TabId . DECOMPILATION ) ;
215236 return clone ;
216237 } ) ;
217238 }
218239 } , [ decompilationTabEnabled ] ) ;
219240
220- const [ objdiffClientEnabled ] = useObjdiffClientEnabled ( ) ;
221-
222241 // If the version of the scratch changes, refresh code editors
223242 useEffect ( ( ) => {
224243 incrementValueVersion ( ) ;
@@ -378,22 +397,20 @@ export default function Scratch({
378397 ) ;
379398 case TabId . OBJDIFF :
380399 return (
381- objdiffClientEnabled && (
382- < Tab
383- key = { id }
384- tabKey = { id }
385- label = "objdiff [alpha]"
386- className = { styles . diffTab }
387- >
388- { compilation && (
389- < ObjdiffPanel
390- scratch = { scratch }
391- compilation = { compilation }
392- buildRunning = { isCompiling }
393- />
394- ) }
395- </ Tab >
396- )
400+ < Tab
401+ key = { id }
402+ tabKey = { id }
403+ label = "objdiff"
404+ className = { styles . diffTab }
405+ >
406+ { compilation && (
407+ < ObjdiffPanel
408+ scratch = { scratch }
409+ compilation = { compilation }
410+ buildRunning = { isCompiling }
411+ />
412+ ) }
413+ </ Tab >
397414 ) ;
398415 case TabId . DECOMPILATION :
399416 return (
@@ -435,7 +452,12 @@ export default function Scratch({
435452
436453 if ( layoutName !== preferredLayout ) {
437454 setLayoutName ( preferredLayout ) ;
438- setLayout ( DEFAULT_LAYOUTS [ preferredLayout ] ) ;
455+ setLayout (
456+ applyDefaultDiffTab (
457+ cloneValue ( DEFAULT_LAYOUTS [ preferredLayout ] ) ,
458+ defaultDiffTab ,
459+ ) ,
460+ ) ;
439461 }
440462 }
441463
0 commit comments