Skip to content

Commit dddaed7

Browse files
author
Philip Guo
committed
adapted and simplified david pritchard's patch for enabling
multiple steps when left or right arrow key is held down
1 parent 7483927 commit dddaed7

2 files changed

Lines changed: 24 additions & 22 deletions

File tree

‎v3/js/iframe-embed.js‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $(document).ready(function() {
8080
}
8181

8282

83+
// David Pritchard's code for resizeContainer option ...
8384
var resizeContainer = ($.bbq.getState('resizeContainer') == 'true');
8485

8586
if (resizeContainer) {
@@ -99,9 +100,6 @@ $(document).ready(function() {
99100
function resizeContainerNow() {
100101
$(container).height($("#vizDiv").height()+20);
101102
};
102-
103-
$("body").on("click", "button", resizeContainerNow);
104-
$("body").on("slide", ".ui-slider", resizeContainerNow);
105103
}
106104

107105

@@ -143,9 +141,23 @@ $(document).ready(function() {
143141
drawParentPointers: drawParentPointerBool,
144142
textualMemoryLabels: textRefsBool,
145143
showOnlyOutputs: showOnlyOutputsBool,
146-
highlightLines: typeof $.bbq.getState("highlightLines") !== "undefined"
144+
highlightLines: typeof $.bbq.getState("highlightLines") !== "undefined",
145+
updateOutputCallback: (resizeContainer ? resizeContainerNow : null)
147146
});
148-
if (resizeContainer) resizeContainerNow();
147+
148+
// set keyboard bindings
149+
$(document).keydown(function(k) {
150+
if (k.keyCode == 37) { // left arrow
151+
if (myVisualizer.stepBack()) {
152+
k.preventDefault(); // don't horizontally scroll the display
153+
}
154+
}
155+
else if (k.keyCode == 39) { // right arrow
156+
if (myVisualizer.stepForward()) {
157+
k.preventDefault(); // don't horizontally scroll the display
158+
}
159+
}
160+
});
149161
}
150162
},
151163
"json");

‎v3/js/opt-frontend.js‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ var rawInputLst = []; // a list of strings inputted by the user in response to r
5050

5151
var myVisualizer = null; // singleton ExecutionVisualizer instance
5252

53-
var keyStuckDown = false;
5453

5554
function enterEditMode() {
5655
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
@@ -229,27 +228,18 @@ $(document).ready(function() {
229228

230229
// set keyboard bindings
231230
$(document).keydown(function(k) {
232-
if (!keyStuckDown) {
233-
if (k.keyCode == 37) { // left arrow
234-
if (myVisualizer.stepBack()) {
235-
k.preventDefault(); // don't horizontally scroll the display
236-
keyStuckDown = true;
237-
}
231+
if (k.keyCode == 37) { // left arrow
232+
if (myVisualizer.stepBack()) {
233+
k.preventDefault(); // don't horizontally scroll the display
238234
}
239-
else if (k.keyCode == 39) { // right arrow
240-
if (myVisualizer.stepForward()) {
241-
k.preventDefault(); // don't horizontally scroll the display
242-
keyStuckDown = true;
243-
}
235+
}
236+
else if (k.keyCode == 39) { // right arrow
237+
if (myVisualizer.stepForward()) {
238+
k.preventDefault(); // don't horizontally scroll the display
244239
}
245240
}
246241
});
247242

248-
$(document).keyup(function(k) {
249-
keyStuckDown = false;
250-
});
251-
252-
253243
// also scroll to top to make the UI more usable on smaller monitors
254244
$(document).scrollTop(0);
255245

0 commit comments

Comments
 (0)