@@ -33,21 +33,29 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3333
3434/* TODOs:
3535
36- - detect exact position of syntax error and put a squiggly line below it
37- with something like:
36+ - [later] detect exact position of syntax error and put a squiggly line below
37+ it with something like:
3838
3939 File "<string>", line 1
4040 x~=1
4141 ^
42+ - make Ace editor resizable width-wise using jQuery resizable
43+ (stackoverflow has some tips for how to do that)
4244
43- - [later] add a codeopticon-style history slider of the user's past
44- edits
45+ - add toggles for language choices
46+
47+ - support pasting in code via URL, which will be important for
48+ transporting the user from regular OPT to live mode
4549
46- - slightly gray out the visualization when there's a syntax error, to
47- indicate to user that it's not indicative of the current code
50+ - make sure server logging works properly, esp. session and user IDs,
51+ and slider interactions
52+ - have separate web_exec_live executor scripts for logging live mode
4853
49- - display run-time exceptions properly -- right now display-mode code is
50- hidden, so no exceptions displayed either
54+ - if these Ace enhancements look good, then I can also use them for
55+ Codeopticon as well!
56+
57+ - [later] add a codeopticon-style history slider of the user's past
58+ edits (but that might be confusing)
5159
5260*/
5361
@@ -60,28 +68,42 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6068
6169var originFrontendJsFile = 'opt-live.js' ;
6270
71+ var prevVisualizer = null ; // the visualizer object from the previous execution
72+
73+ var aceEditorWidth = '600px' ;
74+
75+ var allMarkerIds = [ ] ;
76+
6377function removeAllGutterDecorations ( ) {
6478 var s = pyInputAceEditor . getSession ( ) ;
6579 var d = s . getDocument ( ) ;
6680
6781 for ( var i = 0 ; i < d . getLength ( ) ; i ++ ) {
6882 s . removeGutterDecoration ( i , 'curLineStepGutter' ) ;
6983 s . removeGutterDecoration ( i , 'prevLineStepGutter' ) ;
84+ s . removeGutterDecoration ( i , 'curPrevOverlapLineStepGutter' ) ;
7085 }
7186}
7287
73-
7488function updateStepLabels ( ) {
7589 assert ( myVisualizer ) ;
90+ myVisualizer . updateCurPrevLines ( ) ; // do this first to update the right fields
91+
92+ var s = pyInputAceEditor . getSession ( ) ;
93+ allMarkerIds . forEach ( function ( e ) {
94+ s . removeMarker ( e ) ;
95+ } ) ;
96+ allMarkerIds = [ ] ;
97+
7698 var totalInstrs = myVisualizer . curTrace . length ;
77- var isLastInstr = myVisualizer . curInstr == ( totalInstrs - 1 ) ;
99+ var isLastInstr = myVisualizer . curInstr === ( totalInstrs - 1 ) ;
78100 if ( isLastInstr ) {
79101 if ( myVisualizer . promptForUserInput || myVisualizer . promptForMouseInput ) {
80102 $ ( "#curInstr" ) . html ( '<b><font color="' + brightRed + '">Enter user input:</font></b>' ) ;
81103 } else if ( myVisualizer . instrLimitReached ) {
82- $ ( "#curInstr" ) . html ( "Instruction limit reached" ) ;
104+ $ ( "#curInstr" ) . html ( "Instruction limit reached (" + String ( totalInstrs - 1 ) + " steps) ") ;
83105 } else {
84- $ ( "#curInstr" ) . html ( "Program terminated" ) ;
106+ $ ( "#curInstr" ) . html ( "Program terminated (" + String ( totalInstrs - 1 ) + " steps) ") ;
85107 }
86108 } else {
87109 $ ( "#curInstr" ) . html ( "Step " + String ( myVisualizer . curInstr + 1 ) + " of " + String ( totalInstrs - 1 ) ) ;
@@ -98,20 +120,32 @@ function updateStepLabels() {
98120 $ ( "#frontendErrorOutput" ) . html ( htmlspecialchars ( curEntry . exception_msg ) ) ;
99121 }
100122 $ ( "#frontendErrorOutput" ) . show ( ) ;
123+
124+ if ( myVisualizer . curLineNumber ) {
125+ var Range = ace . require ( 'ace/range' ) . Range ;
126+ var markerId = s . addMarker ( new Range ( myVisualizer . curLineNumber - 1 , 0 ,
127+ myVisualizer . curLineNumber - 1 , 1 ) , "errorLine" , "fullLine" ) ;
128+ allMarkerIds . push ( markerId ) ;
129+ }
130+ } else {
131+ $ ( "#frontendErrorOutput" ) . html ( '' ) ; // clear it
101132 }
102133
103134 removeAllGutterDecorations ( ) ;
104135
105- // update gutter arrows
106- myVisualizer . updateCurPrevLines ( ) ;
107-
108- var s = pyInputAceEditor . getSession ( ) ;
109- if ( myVisualizer . curLineNumber ) {
110- s . addGutterDecoration ( myVisualizer . curLineNumber - 1 , 'curLineStepGutter' ) ;
111- }
112-
113- if ( myVisualizer . prevLineNumber ) {
114- s . addGutterDecoration ( myVisualizer . prevLineNumber - 1 , 'prevLineStepGutter' ) ;
136+ // special case if both arrows overlap
137+ if ( myVisualizer . curLineNumber &&
138+ ( myVisualizer . curLineNumber === myVisualizer . prevLineNumber ) ) {
139+ s . addGutterDecoration ( myVisualizer . curLineNumber - 1 ,
140+ 'curPrevOverlapLineStepGutter' ) ;
141+ } else {
142+ // render separately
143+ if ( myVisualizer . curLineNumber ) {
144+ s . addGutterDecoration ( myVisualizer . curLineNumber - 1 , 'curLineStepGutter' ) ;
145+ }
146+ if ( myVisualizer . prevLineNumber ) {
147+ s . addGutterDecoration ( myVisualizer . prevLineNumber - 1 , 'prevLineStepGutter' ) ;
148+ }
115149 }
116150}
117151
@@ -120,7 +154,7 @@ function optliveFinishSuccessfulExecution() {
120154 $ ( "#pyOutputPane" ) . show ( ) ;
121155 doneExecutingCode ( ) ;
122156
123- $ ( "#dataViz" ) . removeClass ( 'dimmed' ) ; // un-dim the visualization
157+ $ ( "#dataViz,#curInstr " ) . removeClass ( 'dimmed' ) ; // un-dim the visualization
124158
125159 // set up execution slider, code inspired by pytutor.js:
126160 var sliderDiv = $ ( '#executionSlider' ) ;
@@ -154,7 +188,25 @@ function optliveFinishSuccessfulExecution() {
154188
155189 // do this AFTER making #pyOutputPane visible, or else
156190 // jsPlumb connectors won't render properly
157- myVisualizer . updateOutput ( ) ;
191+
192+ // try to "match" the same position as the previous visualizer so that
193+ // the display isn't jerky
194+ if ( prevVisualizer ) {
195+ var prevVizInstr = prevVisualizer . curInstr ;
196+ var prevVizIsFinalInstr = ( prevVisualizer . curInstr === ( prevVisualizer . curTrace . length - 1 ) ) ;
197+
198+ // match the previous step if it we weren't on the last one, and the new
199+ // trace is at least as long
200+ if ( ! prevVizIsFinalInstr &&
201+ ( myVisualizer . curTrace . length >= prevVisualizer . curTrace . length ) ) {
202+ myVisualizer . renderStep ( prevVizInstr ) ;
203+ } else {
204+ myVisualizer . updateOutput ( ) ;
205+ }
206+ } else {
207+ myVisualizer . updateOutput ( ) ;
208+ }
209+
158210 updateStepLabels ( ) ; // do it once
159211}
160212
@@ -163,7 +215,12 @@ function optliveHandleUncaughtExceptionFunc(trace) {
163215 var errorLineNo = trace [ 0 ] . line - 1 ; /* CodeMirror lines are zero-indexed */
164216 if ( errorLineNo !== undefined && errorLineNo != NaN ) {
165217 removeAllGutterDecorations ( ) ;
166- $ ( "#dataViz" ) . addClass ( 'dimmed' ) ; // dim the visualization until we fix the error
218+
219+ if ( myVisualizer ) {
220+ $ ( "#dataViz,#curInstr" ) . addClass ( 'dimmed' ) ; // dim the visualization until we fix the error
221+ myVisualizer . updateOutput ( ) ; // to update arrows
222+ }
223+
167224 var s = pyInputAceEditor . getSession ( ) ;
168225 s . setAnnotations ( [ { row : errorLineNo ,
169226 type : 'error' ,
@@ -195,9 +252,9 @@ function initAceEditor(height) {
195252 pyInputAceEditor . $blockScrolling = Infinity ; // kludgy to shut up weird warnings
196253
197254 // auto-grow height as fit
198- pyInputAceEditor . setOptions ( { minLines : 18 , maxLines : 1000 } ) ;
255+ pyInputAceEditor . setOptions ( { minLines : 20 , maxLines : 20 } ) ;
199256
200- $ ( '# codeInputPane' ) . css ( 'width' , '450px' ) ;
257+ $ ( "#pyInputPane,# codeInputPane" ) . css ( 'width' , aceEditorWidth ) ;
201258 $ ( '#codeInputPane' ) . css ( 'height' , height + 'px' ) ; // VERY IMPORTANT so that it works on I.E., ugh!
202259
203260 pyInputAceEditor . on ( 'change' , function ( e ) {
@@ -259,6 +316,7 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
259316 }
260317 }
261318 else {
319+ prevVisualizer = myVisualizer ;
262320 myVisualizer = new ExecutionVisualizer ( outputDiv , dataFromBackend , frontendOptionsObj ) ;
263321 handleSuccessFunc ( ) ;
264322 }
@@ -303,7 +361,6 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
303361 var startingInstruction = forceStartingInstr ? forceStartingInstr : 0 ;
304362 var frontendOptionsObj = { startingInstruction : startingInstruction ,
305363 executeCodeWithRawInputFunc : executeCodeWithRawInput ,
306- updateOutputCallback : function ( ) { $ ( '#urlOutput,#embedCodeOutput' ) . val ( '' ) ; } ,
307364 hideCode : true ,
308365 jumpToEnd : true ,
309366 }
0 commit comments