@@ -1362,6 +1362,33 @@ function initDiffEditor(editorId) {
13621362 const element = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] . querySelector ( '.fa-fw' ) ;
13631363 element . className = 'fas fa-fw fa-' + icon ;
13641364 } ,
1365+ 'renamedFrom' : ( rank , oldName ) => {
1366+ const navItem = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] ;
1367+ let renamedFromName = navItem . querySelector ( '.renamed' ) ;
1368+ let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1369+ if ( oldName === undefined ) {
1370+ if ( renamedFromName ) {
1371+ navItem . removeChild ( renamedFromName ) ;
1372+ }
1373+ if ( arrow ) {
1374+ navItem . removeChild ( arrow ) ;
1375+ }
1376+ return ;
1377+ }
1378+
1379+ if ( ! renamedFromName ) {
1380+ renamedFromName = document . createElement ( 'span' ) ;
1381+ renamedFromName . className = 'renamed' ;
1382+ navItem . insertBefore ( renamedFromName , navItem . childNodes [ 1 ] ) ;
1383+ }
1384+ renamedFromName . innerText = ` ${ oldName } ` ;
1385+
1386+ if ( ! arrow ) {
1387+ arrow = document . createElement ( 'i' ) ;
1388+ arrow . className = 'fas fa-arrow-right' ;
1389+ navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1390+ }
1391+ } ,
13651392 'onDiffModeChange' : ( f ) => {
13661393 radios . change ( ( e ) => {
13671394 const diffMode = e . target . value ;
@@ -1424,16 +1451,20 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14241451 editors [ editorId ] . onDiffModeChange ( updateMode ) ;
14251452
14261453 const updateSelect = ( submitId , noDiff ) => {
1454+ const model = models [ submitId ] ??= { 'model' : empty } ;
14271455 if ( ! noDiff ) {
1428- const model = models [ submitId ] ;
1429- if ( model === undefined ) {
1430- models [ submitId ] = { 'model' : empty } ;
1431- } else if ( model !== undefined && ! model [ 'model' ] ) {
1456+ if ( ! model [ 'model' ] ) {
14321457 // TODO: show source code instead of diff to empty file?
14331458 model [ 'model' ] = monaco . editor . createModel ( model [ 'source' ] , undefined , monaco . Uri . file ( "test/" + submitId + "/" + model [ 'filename' ] ) ) ;
14341459 }
14351460 }
14361461
1462+ if ( noDiff || ! model [ 'renamedFrom' ] ) {
1463+ editors [ editorId ] . renamedFrom ( rank , undefined ) ;
1464+ } else {
1465+ editors [ editorId ] . renamedFrom ( rank , model [ 'renamedFrom' ] ) ;
1466+ }
1467+
14371468 diffEditor . updateOptions ( {
14381469 renderOverviewRuler : ! noDiff ,
14391470 } ) ;
@@ -1445,7 +1476,6 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14451476 // Reset the diff mode to the currently selected mode.
14461477 updateMode ( editors [ editorId ] . getDiffMode ( ) )
14471478 }
1448- // TODO: handle single-file submission case with renamed file.
14491479 const oldViewState = diffEditor . saveViewState ( ) ;
14501480 diffEditor . setModel ( {
14511481 original : noDiff ? modifiedModel : models [ submitId ] [ 'model' ] ,
0 commit comments