@@ -7,7 +7,7 @@ const clientId = '7ede3eed3185e59c042d';
77
88let githubToken , treeLoc ;
99
10- window . onload = ( ) => {
10+ window . onload = async ( ) => {
1111
1212 githubToken = getStorage ( 'token' ) ;
1313
@@ -22,7 +22,77 @@ window.onload = () => {
2222
2323 if ( urlQuery ) {
2424
25- treeLoc = urlQuery . split ( ',' ) ;
25+ toggleSidebar ( false ) ;
26+ saveSidebarStateLS ( ) ;
27+
28+ treeLoc = urlQuery . split ( '+' ) [ 0 ] . split ( ',' ) ;
29+
30+ // change selected file
31+ changeSelectedFile ( treeLoc . join ( ) , fileSha , fileName , '\n\r' , getFileLang ( fileName ) ,
32+ [ 0 , 0 ] , [ 0 , 0 ] , false ) ;
33+
34+ const fileName = urlQuery . split ( '+' ) [ 1 ] . split ( ',' ) [ 0 ] ;
35+ const fileSha = urlQuery . split ( '+' ) [ 1 ] . split ( ',' ) [ 1 ] ;
36+
37+ // if file is not modified; fetch from Git
38+ if ( ! modifiedFiles [ fileSha ] ) {
39+
40+ // start loading
41+ startLoading ( ) ;
42+
43+ // get file from git
44+ const resp = await git . getFile ( treeLoc , fileName ) ;
45+
46+ // change selected file
47+ changeSelectedFile ( treeLoc . join ( ) , fileSha , fileName , resp . content , getFileLang ( fileName ) ,
48+ [ 0 , 0 ] , [ 0 , 0 ] , false ) ;
49+
50+ // stop loading
51+ stopLoading ( ) ;
52+
53+ } else { // else, load file from modifiedFiles object
54+
55+ const modFile = modifiedFiles [ fileSha ] ;
56+
57+ changeSelectedFile ( modFile . dir , modFile . sha , modFile . name , modFile . content , modFile . lang ,
58+ modFile . caretPos , modFile . scrollPos , false ) ;
59+
60+ }
61+
62+ // expand bottom float
63+ bottomWrapper . classList . add ( 'expanded' ) ;
64+ toggleLiveView ( selectedFile ) ;
65+
66+ // show file content in codeit
67+ cd . textContent = decodeUnicode ( selectedFile . content ) ;
68+
69+ // change codeit lang
70+ cd . lang = selectedFile . lang ;
71+
72+ // set caret pos in codeit
73+ cd . setSelection ( selectedFile . caretPos [ 0 ] , selectedFile . caretPos [ 1 ] ) ;
74+
75+ // set scroll pos in codeit
76+ cd . scrollTo ( selectedFile . scrollPos [ 0 ] , selectedFile . scrollPos [ 1 ] ) ;
77+
78+ // clear codeit history
79+ cd . history = [ ] ;
80+
81+ // update line numbers
82+ updateLineNumbersHTML ( ) ;
83+
84+ // if on mobile device
85+ if ( isMobile ) {
86+
87+ // update bottom float
88+ updateFloat ( ) ;
89+
90+ } else { // if on desktop
91+
92+ // check codeit scrollbar
93+ checkScrollbarArrow ( ) ;
94+
95+ }
2696
2797 }
2898
0 commit comments