Skip to content

Commit 09a7246

Browse files
author
Philip Guo
committed
fixed an embarrassing but where left/right arrows are disabled in edit code textbox
1 parent 2733dfc commit 09a7246

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎edu-python.js‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
// back-end with a string representing the user's script POST['user_script']
2424
// and receives a complete execution trace, which it parses and displays to HTML.
2525

26+
var appMode = 'edit'; // 'edit' or 'visualize'
2627

2728
// set to true to use jsPlumb library to render connections between
2829
// stack and heap objects
@@ -214,6 +215,7 @@ function updateOutput() {
214215
$("#editCodeLinkOnError").click(function() {
215216
$("#pyInputPane").show();
216217
$("#pyOutputPane").hide();
218+
appMode = 'edit';
217219
return false; // to prevent page reload
218220
});
219221

@@ -1110,6 +1112,7 @@ $(document).ready(function() {
11101112

11111113
$("#pyInputPane").hide();
11121114
$("#pyOutputPane").show();
1115+
appMode = 'visualize';
11131116
}
11141117
else {
11151118
$('#executeBtn').html("Please wait ... processing your code");
@@ -1124,6 +1127,7 @@ $(document).ready(function() {
11241127

11251128
$("#pyInputPane").hide();
11261129
$("#pyOutputPane").show();
1130+
appMode = 'visualize';
11271131

11281132
$('#executeBtn').html("Visualize execution");
11291133
$('#executeBtn').attr('disabled', false);
@@ -1136,6 +1140,7 @@ $(document).ready(function() {
11361140
$("#editBtn").click(function() {
11371141
$("#pyInputPane").show();
11381142
$("#pyOutputPane").hide();
1143+
appMode = 'edit';
11391144
});
11401145

11411146

@@ -1287,16 +1292,19 @@ $(document).ready(function() {
12871292

12881293
// set keyboard event listeners ...
12891294
$(document).keydown(function(k) {
1290-
if (k.keyCode == 37) { // left arrow
1291-
if (!$("#vcrControls #jmpStepBack").attr("disabled")) {
1292-
$("#jmpStepBack").trigger('click');
1293-
k.preventDefault(); // don't horizontally scroll the display
1295+
// ONLY capture keys if we're in 'visualize code' mode:
1296+
if (appMode == 'visualize') {
1297+
if (k.keyCode == 37) { // left arrow
1298+
if (!$("#vcrControls #jmpStepBack").attr("disabled")) {
1299+
$("#jmpStepBack").trigger('click');
1300+
k.preventDefault(); // don't horizontally scroll the display
1301+
}
12941302
}
1295-
}
1296-
else if (k.keyCode == 39) { // right arrow
1297-
if (!$("#vcrControls #jmpStepFwd").attr("disabled")) {
1298-
$("#jmpStepFwd").trigger('click');
1299-
k.preventDefault(); // don't horizontally scroll the display
1303+
else if (k.keyCode == 39) { // right arrow
1304+
if (!$("#vcrControls #jmpStepFwd").attr("disabled")) {
1305+
$("#jmpStepFwd").trigger('click');
1306+
k.preventDefault(); // don't horizontally scroll the display
1307+
}
13001308
}
13011309
}
13021310
});

0 commit comments

Comments
 (0)