@@ -95,9 +95,9 @@ export function Help({show, setShow, style}) {
95
95
</ >
96
96
}
97
97
98
- const availableStyles = [ 'Sequent ' , 'SequentBindingMode ' ] ;
98
+ const availableStyles = [ 'UserVisible ' , 'InMemory ' ] ;
99
99
100
- export function MainNavBar ( { compare, setCompare, style, setStyle } ) {
100
+ export function MainNavBar ( { compare, setCompare, style, setStyleName , styleMap } ) {
101
101
const navigate = useNavigate ( )
102
102
const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
103
103
function resetSearchParams ( ) {
@@ -114,11 +114,11 @@ export function MainNavBar({compare, setCompare, style, setStyle}) {
114
114
115
115
const currentStyle = style ;
116
116
const styles = availableStyles . map ( style_name => {
117
- let style = PredicateStyleJs . from_name ( style_name ) ;
117
+ let style = styleMap [ style_name ] ;
118
118
return < OverlayTrigger key = { style_name } placement = "bottom" overlay = { < Tooltip > { style . doc ( ) } </ Tooltip > } >
119
119
< Button
120
120
active = { currentStyle . to_name ( ) == style_name }
121
- onClick = { ( ) => setStyle ( style ) }
121
+ onClick = { ( ) => setStyleName ( style_name ) }
122
122
dangerouslySetInnerHTML = { { __html : style . display_generic_predicate ( ) } }
123
123
> </ Button >
124
124
</ OverlayTrigger >
@@ -399,17 +399,34 @@ export default function Solver() {
399
399
const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
400
400
const sp = { searchParams, setSearchParams} ;
401
401
const [ compare , setCompare ] = useStateInParams ( sp , 'compare' , false , ( x ) => x == 'true' ) ;
402
- const defaultStyle = PredicateStyleJs . from_name ( 'Sequent' ) ;
403
- const [ style , setStyle ] = useStateInParams ( sp , 'style' , defaultStyle , PredicateStyleJs . from_name , ( style ) => style . to_name ( ) ) ;
404
402
const [ optionsLeft , setOptionsLeft ] = useStateInParams ( sp , 'opts1' , RuleSetJs . from_bundle_name ( 'nadri' , 'stable' ) , RuleSetJs . decode , ( o ) => o . encode ( ) ) ;
405
403
const [ optionsRight , setOptionsRight ] = useStateInParams ( sp , 'opts2' , RuleSetJs . from_bundle_name ( 'rfc3627' , 'rfc3627' ) , RuleSetJs . decode , ( o ) => o . encode ( ) ) ;
406
404
const [ inputQuery , setInputQuery ] = useStateInParams ( sp , 'q' , "[&x]: &mut [&T]" ) ;
407
405
const [ mode , setMode ] = useStateInParams ( sp , 'mode' , 'typechecker' , validateIn ( [ 'typechecker' , 'rules' , 'compare' ] ) ) ;
406
+ const [ styleName , setStyleName ] = useStateInParams ( sp , 'style' , 'UserVisible' , validateIn ( [ 'UserVisible' , 'InMemory' , 'Sequent' , 'SequentBindingMode' ] ) ) ;
407
+
408
+ // Map from style name to predicate style. Takes into account the selected
409
+ // options to hide parts of the predicate we don't care about.
410
+ const styleMap = useMemo ( ( ) => {
411
+ var map = availableStyles . reduce ( function ( map , style_name ) {
412
+ if ( compare ) {
413
+ map [ style_name ] = PredicateStyleJs . from_name_and_options ( style_name , optionsLeft , optionsRight ) ;
414
+ } else {
415
+ map [ style_name ] = PredicateStyleJs . from_name_and_option ( style_name , optionsLeft ) ;
416
+ }
417
+ return map ;
418
+ } , { } ) ;
419
+ // Back-compat with permalinks that used the old style names.
420
+ map [ 'Sequent' ] = map [ 'UserVisible' ] ;
421
+ map [ 'SequentBindingMode' ] = map [ 'InMemory' ] ;
422
+ return map ;
423
+ } , [ compare , optionsLeft , optionsRight ] ) ;
424
+ const style = styleMap [ styleName ] ;
408
425
409
426
return (
410
427
< >
411
428
< div className = "sticky-top" >
412
- < MainNavBar { ...{ compare, setCompare, style, setStyle } } />
429
+ < MainNavBar { ...{ compare, setCompare, style, setStyleName , styleMap } } />
413
430
< SolverOptions options = { optionsLeft } setOptions = { setOptionsLeft } title = { compare ? < > Left </ > : null } />
414
431
{ compare ? < SolverOptions options = { optionsRight } setOptions = { setOptionsRight } title = "Right" /> : null }
415
432
</ div >
0 commit comments