@@ -138,6 +138,20 @@ function setDiffMode(value)
138
138
localStorage . setItem ( 'domjudge_editor_diff_mode' , value ) ;
139
139
}
140
140
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
+
141
155
// Send a notification if notifications have been enabled.
142
156
// The options argument is passed to the Notification constructor,
143
157
// except that the following tags (if found) are interpreted and
@@ -1295,10 +1309,23 @@ const editors = [];
1295
1309
function initDiffEditor ( editorId ) {
1296
1310
const wrapper = $ ( `#${ editorId } -wrapper` ) ;
1297
1311
1298
- // TODO: store and restore tag preference in local storage.
1299
- const initialSelect = "" ;
1312
+ const initialTag = getDiffTag ( ) ;
1300
1313
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
+ }
1302
1329
1303
1330
const initialDiffMode = getDiffMode ( ) ;
1304
1331
const radios = wrapper . find ( `.diff-mode > input[type='radio']` ) ;
@@ -1368,9 +1395,15 @@ function initDiffEditor(editorId) {
1368
1395
radios . each ( ( _ , radio ) => {
1369
1396
radio . disabled = noDiff ;
1370
1397
} ) ;
1398
+
1399
+ const selected = select [ 0 ] . options [ select [ 0 ] . selectedIndex ] ;
1400
+ if ( selected && selected . dataset . tag ) {
1401
+ setDiffTag ( selected . dataset . tag ) ;
1402
+ }
1403
+
1371
1404
// TODO: add tab panes for deleted source files.
1372
1405
} ;
1373
- updateSelect ( "" , true ) ;
1406
+ updateSelect ( select [ 0 ] . value , select [ 0 ] . value === "" ) ;
1374
1407
editor . onDiffSelectChange ( updateSelect ) ;
1375
1408
}
1376
1409
@@ -1390,6 +1423,13 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
1390
1423
theme : getCurrentEditorTheme ( ) ,
1391
1424
} ) ;
1392
1425
1426
+ const updateMode = ( diffMode ) => {
1427
+ diffEditor . updateOptions ( {
1428
+ renderSideBySide : diffMode === 'side-by-side' ,
1429
+ } ) ;
1430
+ } ;
1431
+ editors [ editorId ] . onDiffModeChange ( updateMode ) ;
1432
+
1393
1433
const updateSelect = ( submitId , noDiff ) => {
1394
1434
if ( ! noDiff ) {
1395
1435
const model = models [ submitId ] ;
@@ -1430,7 +1470,7 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
1430
1470
} )
1431
1471
} ;
1432
1472
editors [ editorId ] . onDiffSelectChange ( updateSelect ) ;
1433
- updateSelect ( "" , true ) ;
1473
+ updateSelect ( editors [ editorId ] . getDiffSelection ( ) , editors [ editorId ] . getDiffSelection ( ) === "" ) ;
1434
1474
1435
1475
const updateIcon = ( ) => {
1436
1476
const noDiff = editors [ editorId ] . getDiffSelection ( ) === "" ;
@@ -1449,11 +1489,4 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
1449
1489
}
1450
1490
}
1451
1491
diffEditor . onDidUpdateDiff ( updateIcon ) ;
1452
-
1453
- const updateMode = ( diffMode ) => {
1454
- diffEditor . updateOptions ( {
1455
- renderSideBySide : diffMode === 'side-by-side' ,
1456
- } ) ;
1457
- } ;
1458
- editors [ editorId ] . onDiffModeChange ( updateMode ) ;
1459
1492
}
0 commit comments