@@ -82,26 +82,42 @@ class Editor extends EventTarget {
8282 height = 18 ;
8383 charWidth = 18 ;
8484 postDraw : ( ( ) => void ) [ ] = [ ] ;
85+ focusedLine ?: number ;
86+ focusLine ( index ?: number ) {
87+ this . focusedLine = index ;
88+ const linedown = Math . floor ( this . scroll . linedown ) ;
89+ if ( index !== undefined ) {
90+ console . log ( index , linedown , this . height ) ;
91+ if ( index < linedown ) {
92+ this . scroll . linedown = index ;
93+ }
94+ if ( index > linedown + this . height ) {
95+ this . scroll . linedown = this . height + index ;
96+ }
97+ }
98+
99+ this . forceCanvasUpdate ( ) ;
100+ }
85101 renderToCanvas ( ctx : CanvasRenderingContext2D ) {
86102 ctx . clearRect ( 0 , 0 , ctx . canvas . width , ctx . canvas . height ) ;
87103 const fontSize = this . fontSize ;
88104 const height = Math . floor ( ctx . canvas . height / this . fontSize ) ;
89- this . height = height ;
105+ this . height = height || this . height ;
90106 ctx . font = `${ fontSize } px monospace` ;
91107 const charWidth = ctx . measureText ( "a" ) . width ;
92108 this . charWidth = charWidth ;
93109 ctx . textBaseline = "hanging" ;
94110 const linedown = Math . floor ( this . scroll . linedown ) ;
95111 const widthNeeded = this . widthNeeded ( ) ;
112+ const theme = ( localStorage . getItem ( "theme" ) || "dark" ) as "light" | "dark" ;
96113 for ( let i = linedown ; i < height + linedown ; i ++ ) {
97114 const line = this . lines [ i ] ;
98- if ( line && line . errored ) {
99- ctx . fillStyle = " lemonchiffon";
115+ if ( ( line && line . errored ) || this . focusedLine === i ) {
116+ ctx . fillStyle = theme == "light" ? " lemonchiffon" : "yellowgreen ";
100117 const y = ( i - linedown ) * fontSize ;
101118 ctx . fillRect ( widthNeeded + 10 , y , ctx . canvas . width , this . fontSize ) ;
102119 }
103120 }
104- const theme = ( localStorage . getItem ( "theme" ) || "dark" ) as "light" | "dark" ;
105121
106122 if ( "highlights" in this . cursor ) {
107123 ctx . fillStyle = theme == "light" ? "LightBlue" : "darkblue" ;
@@ -538,10 +554,14 @@ class Editor extends EventTarget {
538554 }
539555 return strings ;
540556 }
557+ forceCanvasUpdate = ( ) => { } ;
541558 ownCanvas ( c : HTMLCanvasElement ) {
542559 let lastClicked = 0 ;
543560 const ctx = c . getContext ( "2d" ) ;
544561 if ( ! ctx ) throw Error ( "Unable to get canvas context 2d" ) ;
562+ this . forceCanvasUpdate = ( ) => {
563+ this . renderToCanvas ( ctx ) ;
564+ } ;
545565 const mut = new ResizeObserver ( ( e ) => {
546566 for ( const _ of e ) {
547567 }
@@ -943,34 +963,33 @@ class Editor extends EventTarget {
943963 try {
944964 this . console . addMessage ( "\n" + I18n . startingAssembly ( ) + "\n\n" ) ;
945965 let emu : Symstem ;
966+ const asm : [ string , string ] [ ] = [ ] ;
946967 if ( this . dir && this . fileDir ) {
947968 const dirL = this . fileDir . split ( "/" ) ;
948969 dirL . pop ( ) ;
949970 const dir = dirL . join ( "/" ) + "/" ;
950- const build : [ string , string ] [ ] = [ [ this . string ( ) , this . fileDir ] ] ;
971+ asm . push ( [ this . string ( ) , this . fileDir ] ) ;
951972 for await ( const [ name , thing ] of this . dir . getAllInDir ( ) ) {
952973 if ( thing instanceof Directory ) continue ;
953974 if ( ! name . endsWith ( ".asm" ) ) continue ;
954975 const thisDir = dir + name ;
955976 if ( thisDir === this . fileDir ) continue ;
956977 const editor = Editor . editMap . get ( thisDir ) ;
957978 if ( editor ) {
958- build . push ( [ editor . string ( ) , thisDir ] ) ;
979+ asm . push ( [ editor . string ( ) , thisDir ] ) ;
959980 } else {
960- build . push ( [ await thing . text ( ) , thisDir ] ) ;
981+ asm . push ( [ await thing . text ( ) , thisDir ] ) ;
961982 }
962983 }
963- const [ ram , pc ] = assemble ( build ) ;
964- emu = new Symstem ( ram , this . console ) ;
965- emu . pc = pc ;
966984 } else {
967- const [ ram , pc ] = assemble ( [ [ this . string ( ) , this . fileDir || this . fileName ] ] ) ;
968- emu = new Symstem ( ram , this . console ) ;
969- emu . pc = pc ;
985+ asm . push ( [ this . string ( ) , this . fileDir || this . fileName ] ) ;
970986 }
987+ const [ ram , pc , instMap ] = assemble ( asm ) ;
988+ emu = new Symstem ( ram , this . console ) ;
989+ emu . pc = pc ;
971990 emu . intRegis [ 2 ] = 0x7fffeffcn ;
972991 this . console . addMessage ( "\n" + I18n . finishedAssembly ( ) + "\n\n" ) ;
973- this . dispatchEvent ( new AssembleEvent ( "Assemble" , emu ) ) ;
992+ this . dispatchEvent ( new AssembleEvent ( "Assemble" , { emu, instMap , asm } ) ) ;
974993 } catch ( e ) {
975994 if ( e instanceof AssemblError ) {
976995 this . dispatchEvent ( new AssembleEvent ( "Assemble" , e ) ) ;
@@ -989,8 +1008,15 @@ class Editor extends EventTarget {
9891008 }
9901009}
9911010class AssembleEvent extends Event {
992- sys : Symstem | AssemblError ;
993- constructor ( code : string , sys : Symstem | AssemblError ) {
1011+ sys :
1012+ | { emu : Symstem ; instMap : Map < number , { file : string ; line : number } > ; asm : [ string , string ] [ ] }
1013+ | AssemblError ;
1014+ constructor (
1015+ code : string ,
1016+ sys :
1017+ | { emu : Symstem ; instMap : Map < number , { file : string ; line : number } > ; asm : [ string , string ] [ ] }
1018+ | AssemblError ,
1019+ ) {
9941020 super ( code ) ;
9951021 this . sys = sys ;
9961022 }
0 commit comments