@@ -25,9 +25,21 @@ export default class TraceVisualization extends Morph {
2525
2626 this . entries = [ ] ;
2727
28- let debounced = _ . debounce ( ( ) => this . editor . currentEditor ( ) . listSelections ( ) [ 0 ] . openInInspector ( ) , 500 ) ;
29-
30- this . editor . awaitEditor ( ) . then ( ( ) => {
28+ let debounced = _ . debounce ( ( ) => {
29+ const selection = this . editor . currentEditor ( ) . listSelections ( ) [ 0 ] ;
30+ const position = {
31+ filename : this . currentURL ,
32+ startLine : selection . anchor . line ,
33+ endLine : selection . head . line ,
34+ startColumn : selection . anchor . ch ,
35+ endColumn : selection . head . ch
36+ } ;
37+ this . markInRange ( position ) ;
38+ } , 500 ) ;
39+
40+ const cm = await this . editor . awaitEditor ( ) ;
41+
42+ cm . on ( "beforeSelectionChange" , ( ) => {
3143 debounced . cancel ( ) ;
3244 debounced ( ) ;
3345 } ) ;
@@ -130,11 +142,19 @@ export default class TraceVisualization extends Morph {
130142 } )
131143 }
132144
133- createSectionElement ( section , path = [ section ] ) {
145+ createSectionElement ( section , path = [ ] ) {
134146 const className = `entry ${ section . hasChanges ? 'changing' : '' } `
135147 const header = < div class = { className } > +{ section . name } < / div > ;
136148 const body = < div > < / div > ;
137149 const entry = < div > { header } { body } < / div > ;
150+
151+ entry.data = { } ;
152+ entry.data.traverse = function(fn){
153+ fn ( header , section ) ;
154+ for ( const child of body . children ) {
155+ child . data . traverse ( fn ) ;
156+ }
157+ }
138158
139159
140160 let isTriggered = false ;
@@ -148,14 +168,22 @@ export default class TraceVisualization extends Morph {
148168 visitEvent ( event ) {
149169 const className = `entry sub ${ elm . hasChanges ? 'changing' : '' } ` ;
150170 const subEntry = < div class = { className } > { event . type } < / div > ;
171+
172+ subEntry.data = { } ;
173+ subEntry.data.traverse = function(fn) {
174+ fn ( subEntry , elm ) ;
175+ }
151176
152177 body.appendChild(subEntry);
153- me.setSubEntryEventListener(subEntry, elm, path);
178+ me.setSubEntryEventListener(subEntry, elm, [... path, section] );
154179 } ,
155180 visitErrorEvent ( errorEvent ) {
156181 const className = `entry sub ${ elm . hasChanges ? 'changing' : '' } ` ;
157182 const subEntry = < div class = { className } style =
158183 "background: red; color: #eee" > { errorEvent . type } < / div > ;
184+
185+ subEntry.data = { } ;
186+ subEntry.data.traverse = function(fn) { }
159187
160188 body.appendChild(subEntry);
161189 subEntry.addEventListener('mouseover', e => {
@@ -164,15 +192,10 @@ export default class TraceVisualization extends Morph {
164192 } );
165193 } ,
166194 visitTraceSection ( traceSection ) {
167- const subEntry = me . createSectionElement ( traceSection , [ ...path ,
168- traceSection
169- ] ) ;
195+ const subEntry = me . createSectionElement ( traceSection , [ ...path , section ] ) ;
170196 subEntry . className += ' sub' ;
171197
172198 body . appendChild ( subEntry ) ;
173-
174- const header = subEntry . children [ 0 ] ;
175- me . setSubEntryEventListener ( header , elm , path ) ;
176199 }
177200 } ) ;
178201 }
@@ -183,7 +206,7 @@ export default class TraceVisualization extends Morph {
183206
184207 } );
185208
186- this.setSubEntryEventListener(header, section, [] );
209+ this.setSubEntryEventListener(header, section, path );
187210
188211 entry.select = function() {
189212 section . position
@@ -200,11 +223,47 @@ export default class TraceVisualization extends Morph {
200223 }
201224
202225 updateList() {
226+ this . entries = [ ] ;
203227 this . clearList ( ) ;
204228 for ( const section of this . trace . sections ) {
205229 this . addListItem ( section ) ;
206230 }
207231 }
232+
233+ /*MD ## Highlighting MD*/
234+ isInRange ( given , toTest ) {
235+ if ( given . filename !== toTest . filename ) {
236+ return false ;
237+ }
238+
239+ if(given.startLine >= toTest . startLine && given . endLine <= toTest . endLine ) {
240+ if ( given . startLine === toTest . startLine && given . startColumn < toTest . startColumn ) {
241+ return false ;
242+ }
243+
244+ if(given.endLine === toTest.endLine && given . endColumn > toTest . endColumn ) {
245+ return false ;
246+ }
247+
248+ return true;
249+ }
250+
251+ return false ;
252+ }
253+
254+ markInRange ( position ) {
255+ for ( const entry of this . entries ) {
256+ entry . data . traverse ( ( elm , item ) => {
257+ if ( ! item . position ) {
258+ return ;
259+ }
260+ if ( this . isInRange ( position , this . trace . resolve ( item . position ) ) ) {
261+ debugger
262+ elm . classList . add ( 'marked' ) ;
263+ }
264+ } )
265+ }
266+ }
208267
209268 /*MD ## Update AST MD*/
210269
0 commit comments