@@ -138,6 +138,20 @@ function setDiffMode(value)
138138 localStorage . setItem ( 'domjudge_editor_diff_mode' , value ) ;
139139}
140140
141+ function getDiffTag ( )
142+ {
143+ let diffTag = localStorage . getItem ( 'domjudge_editor_diff_tag' ) ;
144+ if ( diffTag === undefined ) {
145+ return 'no-diff' ;
146+ }
147+ return diffTag ;
148+ }
149+
150+ function setDiffTag ( value )
151+ {
152+ localStorage . setItem ( 'domjudge_editor_diff_tag' , value ) ;
153+ }
154+
141155// Send a notification if notifications have been enabled.
142156// The options argument is passed to the Notification constructor,
143157// except that the following tags (if found) are interpreted and
@@ -1295,10 +1309,23 @@ const editors = [];
12951309function initDiffEditor ( editorId ) {
12961310 const wrapper = $ ( `#${ editorId } -wrapper` ) ;
12971311
1298- // TODO: store and restore tag preference in local storage.
1299- const initialSelect = "" ;
1312+ const initialTag = getDiffTag ( ) ;
13001313 const select = wrapper . find ( ".diff-select" ) ;
1301- select [ 0 ] . selectedIndex = 0 ;
1314+ for ( let i = 0 ; i < select [ 0 ] . options . length ; i ++ ) {
1315+ if ( select [ 0 ] . options [ i ] . dataset . tag == initialTag ) {
1316+ select [ 0 ] . selectedIndex = i ;
1317+ break ;
1318+ }
1319+ }
1320+ // Fall back to other tagged diff if preferred tag is not available for this submission.
1321+ if ( initialTag !== "no-diff" && select [ 0 ] . selectedIndex === 0 ) {
1322+ for ( let i = 1 ; i < select [ 0 ] . options . length ; i ++ ) {
1323+ if ( select [ 0 ] . options [ i ] . dataset . tag ) {
1324+ select [ 0 ] . selectedIndex = i ;
1325+ break ;
1326+ }
1327+ }
1328+ }
13021329
13031330 const initialDiffMode = getDiffMode ( ) ;
13041331 const radios = wrapper . find ( `.diff-mode > input[type='radio']` ) ;
@@ -1368,9 +1395,15 @@ function initDiffEditor(editorId) {
13681395 radios . each ( ( _ , radio ) => {
13691396 radio . disabled = noDiff ;
13701397 } ) ;
1398+
1399+ const selected = select [ 0 ] . options [ select [ 0 ] . selectedIndex ] ;
1400+ if ( selected && selected . dataset . tag ) {
1401+ setDiffTag ( selected . dataset . tag ) ;
1402+ }
1403+
13711404 // TODO: add tab panes for deleted source files.
13721405 } ;
1373- updateSelect ( "" , true ) ;
1406+ updateSelect ( select [ 0 ] . value , select [ 0 ] . value === "" ) ;
13741407 editor . onDiffSelectChange ( updateSelect ) ;
13751408}
13761409
@@ -1390,6 +1423,13 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
13901423 theme : getCurrentEditorTheme ( ) ,
13911424 } ) ;
13921425
1426+ const updateMode = ( diffMode ) => {
1427+ diffEditor . updateOptions ( {
1428+ renderSideBySide : diffMode === 'side-by-side' ,
1429+ } ) ;
1430+ } ;
1431+ editors [ editorId ] . onDiffModeChange ( updateMode ) ;
1432+
13931433 const updateSelect = ( submitId , noDiff ) => {
13941434 if ( ! noDiff ) {
13951435 const model = models [ submitId ] ;
@@ -1430,7 +1470,7 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14301470 } )
14311471 } ;
14321472 editors [ editorId ] . onDiffSelectChange ( updateSelect ) ;
1433- updateSelect ( "" , true ) ;
1473+ updateSelect ( editors [ editorId ] . getDiffSelection ( ) , editors [ editorId ] . getDiffSelection ( ) === "" ) ;
14341474
14351475 const updateIcon = ( ) => {
14361476 const noDiff = editors [ editorId ] . getDiffSelection ( ) === "" ;
@@ -1449,11 +1489,4 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14491489 }
14501490 }
14511491 diffEditor . onDidUpdateDiff ( updateIcon ) ;
1452-
1453- const updateMode = ( diffMode ) => {
1454- diffEditor . updateOptions ( {
1455- renderSideBySide : diffMode === 'side-by-side' ,
1456- } ) ;
1457- } ;
1458- editors [ editorId ] . onDiffModeChange ( updateMode ) ;
14591492}
0 commit comments