@@ -398,38 +398,6 @@ async function renderSidebarHTML() {
398398
399399 // if navigating in repository
400400 if ( repo != '' ) {
401-
402- // legacy modified file dir
403-
404- let modFilesChanged = false ;
405-
406- Object . values ( modifiedFiles ) . forEach ( modFile => {
407-
408- if ( modFile . dir ) {
409-
410- // map modified file location
411- let [ fileUser , fileRepo , fileDir ] = modFile . dir . split ( ',' ) ;
412-
413- // if modified file dosen't have a branch
414- // and is in current repo
415- if ( ! fileRepo . includes ( ':' )
416- && fileUser === user
417- && fileRepo === repoName ) {
418-
419- // append default branch to file
420- fileRepo = fileRepo + ':' + branch ;
421- modFile . dir = [ fileUser , fileRepo , fileDir ] . join ( ) ;
422-
423- modFilesChanged = true ;
424-
425- }
426-
427- }
428-
429- } ) ;
430-
431- if ( modFilesChanged ) updateModFilesLS ( ) ;
432-
433401
434402 // get all eclipsed files in directory
435403 eclipsedFiles = Object . values ( modifiedFiles ) . filter ( modFile => modFile . dir == treeLoc . join ( ) ) ;
@@ -463,8 +431,7 @@ async function renderSidebarHTML() {
463431
464432 // scroll to end of title
465433 sidebarLogo . scrollTo ( {
466- left : sidebarLogo . scrollWidth - sidebarLogo . offsetLeft //,
467- //behavior: 'smooth'
434+ left : sidebarLogo . scrollWidth - sidebarLogo . offsetLeft
468435 } ) ;
469436
470437 sidebarLogo . classList . add ( 'notransition' ) ;
@@ -832,6 +799,11 @@ async function renderSidebarHTML() {
832799 protectUnsavedCode ( ) ;
833800
834801 }
802+
803+
804+ // hide branch menu
805+ branchMenu . classList . remove ( 'visible' ) ;
806+ sidebarBranch . classList . remove ( 'active' ) ;
835807
836808}
837809
@@ -1341,10 +1313,104 @@ async function loadFileInHTML(fileEl, fileSha) {
13411313 startLoading ( ) ;
13421314 }
13431315
1316+
1317+ const fileDir = treeLoc . join ( ) ;
1318+
13441319 // get file from git
13451320 let resp = await git . getFile ( treeLoc , fileName ) ;
13461321
13471322
1323+ const currSelectedFileName = fileWrapper . querySelector ( '.selected .name' ) . textContent . replaceAll ( '\n' , '' ) ;
1324+
1325+ // if switched file or directory while loading, return
1326+ if ( treeLoc . join ( ) !== fileDir ||
1327+ currSelectedFileName !== fileName ) {
1328+
1329+ return ;
1330+
1331+ }
1332+
1333+
1334+ // if file dosen't exist
1335+ if ( resp . message && resp . message === 'Not Found' ) {
1336+
1337+ // stop loading
1338+ stopLoading ( ) ;
1339+
1340+ showMessage ( 'Hmm... that file dosen\'t exist.' , 5000 ) ;
1341+
1342+
1343+ // remove file from HTML
1344+ if ( fileEl ) fileEl . remove ( ) ;
1345+
1346+ // if previous file selection exists
1347+ if ( selectedFile . sha ) {
1348+
1349+ const prevSelFileEl = fileWrapper . querySelector ( '.item[sha="' + selectedFile . sha + '"]' ) ;
1350+
1351+ // if previous file selection exists in HTML
1352+ if ( prevSelFileEl ) {
1353+
1354+ // load previous selected file
1355+ loadFileInHTML ( prevSelFileEl , selectedFile . sha ) ;
1356+
1357+ } else {
1358+
1359+ // clear editor to protect unsaved code
1360+ clearEditor ( ) ;
1361+
1362+ }
1363+
1364+ } else {
1365+
1366+ // clear editor to protect unsaved code
1367+ clearEditor ( ) ;
1368+
1369+ }
1370+
1371+ function clearEditor ( ) {
1372+
1373+ // clear codeit contents
1374+ cd . textContent = '\r\n' ;
1375+
1376+ // change codeit lang
1377+ cd . lang = '' ;
1378+
1379+ // clear codeit history
1380+ cd . history . records = [ { html : cd . innerHTML , pos : cd . getSelection ( ) } ] ;
1381+ cd . history . pos = 0 ;
1382+
1383+ // update line numbers
1384+ updateLineNumbersHTML ( ) ;
1385+
1386+ // if on mobile, show sidebar
1387+ if ( isMobile ) {
1388+
1389+ // don't transition
1390+ body . classList . add ( 'notransition' ) ;
1391+
1392+ // show sidebar
1393+ toggleSidebar ( true ) ;
1394+ saveSidebarStateLS ( ) ;
1395+
1396+ onNextFrame ( ( ) => {
1397+
1398+ body . classList . remove ( 'notransition' ) ;
1399+
1400+ } ) ;
1401+
1402+ }
1403+
1404+ // change selected file to empty file
1405+ changeSelectedFile ( '' , '' , '' , '' , '' , [ 0 , 0 ] , [ 0 , 0 ] , false ) ;
1406+
1407+ }
1408+
1409+ return ;
1410+
1411+ }
1412+
1413+
13481414 // if file is over 1MB
13491415 if ( resp . size >= 1000000 && resp . content === '' ) {
13501416
@@ -1612,7 +1678,7 @@ async function renderBranchMenuHTML(renderAll) {
16121678 if ( getAttr ( branchMenu , 'tree' ) !== [ user , repoName , contents ] . join ( ) ) {
16131679
16141680 // show loading message
1615- branchMenu . innerHTML = '<div class="icon selected "><a>Loading...</a></div>' ;
1681+ branchMenu . innerHTML = '<div class="icon" style="pointer-events: none; opacity: .5; font-weight: 500; "><a>Loading...</a></div>' ;
16161682
16171683 setAttr ( branchMenu , 'tree' , [ user , repoName , contents ] . join ( ) ) ;
16181684
@@ -1723,7 +1789,7 @@ async function renderBranchMenuHTML(renderAll) {
17231789 // render show more button
17241790 if ( ! renderAll && branchResp . length > 1 ) {
17251791
1726- out += '<div class="icon see-more">' + moreIcon + '<a>see more</a></div>' ;
1792+ out += '<div class="icon see-more">' + moreIcon + '<a>more</a></div>' ;
17271793
17281794 }
17291795
@@ -2011,8 +2077,8 @@ sidebarBranch.addEventListener('click', () => {
20112077 moveElToEl ( branchMenu , sidebarBranch , 23 ) ;
20122078
20132079 }
2014-
2015- branchMenu . classList . add ( 'top-margin' ) ;
2080+
2081+ branchMenu . scrollTo ( 0 , 0 ) ;
20162082
20172083 }
20182084
@@ -2930,7 +2996,7 @@ function codeChange() {
29302996// protect unsaved code
29312997// if selected file is in current directory
29322998// but does not exist in the HTML
2933- function protectUnsavedCode ( ) {
2999+ async function protectUnsavedCode ( ) {
29343000
29353001 // map tree location
29363002 const [ user , repo , contents ] = treeLoc ;
@@ -2962,55 +3028,24 @@ function protectUnsavedCode() {
29623028 // if new version of selected file exists
29633029 if ( selectedElName !== null ) {
29643030
2965- // load file
2966- loadFileInHTML ( selectedElName , getAttr ( selectedElName , 'sha' ) ) ;
2967-
2968- } else {
2969-
2970- // if the selected file was deleted,
2971- // protect unsaved code by clearing codeit
2972-
2973- // clear codeit contents
2974- cd . textContent = '\r\n' ;
2975-
2976- // change codeit lang
2977- cd . lang = '' ;
3031+ const scrollPos = selectedFile . scrollPos ;
29783032
2979- // clear codeit history
2980- cd . history . records = [ { html : cd . innerHTML , pos : cd . getSelection ( ) } ] ;
2981- cd . history . pos = 0 ;
2982-
2983- // update line numbers
2984- updateLineNumbersHTML ( ) ;
2985-
2986- // if on mobile, show sidebar
2987- if ( isMobile ) {
2988-
2989- // don't transition
2990- body . classList . add ( 'notransition' ) ;
2991-
2992- // show sidebar
2993- toggleSidebar ( true ) ;
2994- saveSidebarStateLS ( ) ;
2995-
2996- onNextFrame ( ( ) => {
2997-
2998- body . classList . remove ( 'notransition' ) ;
2999-
3000- } ) ;
3001-
3002- }
3033+ // load file
3034+ await loadFileInHTML ( selectedElName , getAttr ( selectedElName , 'sha' ) ) ;
30033035
3004- // change selected file to empty file
3005- changeSelectedFile ( '' , '' , '' , '' , '' , [ 0 , 0 ] , [ 0 , 0 ] , false ) ;
3036+ // prevent bottom float disappearing on mobile
3037+ if ( isMobile ) lastScrollTop = scrollPos [ 1 ] ;
3038+
3039+ // scroll to pos in code
3040+ cd . scrollTo ( scrollPos [ 0 ] , scrollPos [ 1 ] ) ;
30063041
30073042 }
30083043
30093044 } else {
30103045
30113046 // if selected file isn't loaded
30123047 if ( selectedFile . sha !== getAttr ( selectedElSha , 'sha' ) ) {
3013-
3048+
30143049 // load file
30153050 loadFileInHTML ( selectedElSha , getAttr ( selectedElSha , 'sha' ) ) ;
30163051
0 commit comments