@@ -1369,6 +1369,33 @@ function initDiffEditor(editorId) {
13691369 const element = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] . querySelector ( '.fa-fw' ) ;
13701370 element . className = 'fas fa-fw fa-' + icon ;
13711371 } ,
1372+ 'renamedFrom' : ( rank , oldName ) => {
1373+ const navItem = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] ;
1374+ let renamed = navItem . querySelector ( '.renamed' ) ;
1375+ let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1376+ if ( oldName === undefined ) {
1377+ if ( renamed ) {
1378+ navItem . removeChild ( renamed ) ;
1379+ }
1380+ if ( arrow ) {
1381+ navItem . removeChild ( arrow ) ;
1382+ }
1383+ return ;
1384+ }
1385+
1386+ if ( ! renamed ) {
1387+ renamed = document . createElement ( 'span' ) ;
1388+ renamed . className = 'renamed' ;
1389+ navItem . insertBefore ( renamed , navItem . childNodes [ 1 ] ) ;
1390+ }
1391+ renamed . innerText = ` ${ oldName } ` ;
1392+
1393+ if ( ! arrow ) {
1394+ arrow = document . createElement ( 'i' ) ;
1395+ arrow . className = 'fas fa-arrow-right' ;
1396+ navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1397+ }
1398+ } ,
13721399 'onDiffModeChange' : ( f ) => {
13731400 radios . change ( ( e ) => {
13741401 const diffMode = e . target . value ;
@@ -1431,16 +1458,20 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14311458 editors [ editorId ] . onDiffModeChange ( updateMode ) ;
14321459
14331460 const updateSelect = ( submitId , noDiff ) => {
1461+ const model = models [ submitId ] ??= { 'model' : empty } ;
14341462 if ( ! noDiff ) {
1435- const model = models [ submitId ] ;
1436- if ( model === undefined ) {
1437- models [ submitId ] = { 'model' : empty } ;
1438- } else if ( model !== undefined && ! model [ 'model' ] ) {
1463+ if ( ! model [ 'model' ] ) {
14391464 // TODO: show source code instead of diff to empty file?
14401465 model [ 'model' ] = monaco . editor . createModel ( model [ 'source' ] , undefined , monaco . Uri . file ( "test/" + submitId + "/" + model [ 'filename' ] ) ) ;
14411466 }
14421467 }
14431468
1469+ if ( noDiff || ! model [ 'renamedFrom' ] ) {
1470+ editors [ editorId ] . renamedFrom ( rank , undefined ) ;
1471+ } else {
1472+ editors [ editorId ] . renamedFrom ( rank , model [ 'renamedFrom' ] ) ;
1473+ }
1474+
14441475 diffEditor . updateOptions ( {
14451476 renderOverviewRuler : ! noDiff ,
14461477 } ) ;
@@ -1452,7 +1483,6 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14521483 // Reset the diff mode to the currently selected mode.
14531484 updateMode ( editors [ editorId ] . getDiffMode ( ) )
14541485 }
1455- // TODO: handle single-file submission case with renamed file.
14561486 const oldViewState = diffEditor . saveViewState ( ) ;
14571487 diffEditor . setModel ( {
14581488 original : noDiff ? modifiedModel : models [ submitId ] [ 'model' ] ,
0 commit comments