Skip to content

Commit

Permalink
Fix empty sandbox bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
omphalos committed Dec 22, 2013
1 parent 75b9a55 commit caca279
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
5 changes: 3 additions & 2 deletions earhorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
bufferSize: 100,
flushInterval: 25,
handleErrors: true,
logModifiedCode: true
logModifiedCode: true,
quiet: true
}

localStorage.setItem('earhorn-settings', JSON.stringify(target))
Expand Down Expand Up @@ -58,7 +59,7 @@
else if(record.type === 'edit') {

localStorage.setItem('earhorn-script-' + record.script, record.body)
// console.log('applying edit', record.script, record.body)

if(record.reload) // TODO: could do hot code-swapping instead ...
location.reload(true)

Expand Down
5 changes: 3 additions & 2 deletions instrumentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
bufferSize: 100,
flushInterval: 25,
handleErrors: true,
logModifiedCode: true
logModifiedCode: true,
quiet: true
}

localStorage.setItem('earhorn-settings', JSON.stringify(target))
Expand Down Expand Up @@ -58,7 +59,7 @@
else if(record.type === 'edit') {

localStorage.setItem('earhorn-script-' + record.script, record.body)
// console.log('applying edit', record.script, record.body)

if(record.reload) // TODO: could do hot code-swapping instead ...
location.reload(true)

Expand Down
51 changes: 26 additions & 25 deletions modules/main/MainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('app').config(['$routeProvider', function($routeProvider) {
}])

angular.module('main').controller('MainCtrl', [
'$scope',
'$scope',
'$location',
'logClient',
'timeline',
Expand Down Expand Up @@ -36,10 +36,6 @@ angular.module('main').controller('MainCtrl', [
play: true,
formatDigits: 2
},
main: {
autosave: false,
autoNavigateWhenPlaying: false
},
keys: {
'mod+p': 'play()',
'mod+m': 'timeline.fastBackward()',
Expand Down Expand Up @@ -86,20 +82,30 @@ angular.module('main').controller('MainCtrl', [
}

function updateCode() {

if($scope.editing) return

$scope.code = getEditScript().body
}

function updateLocation() {
if($scope.editing || !programState.currentLoc) return
if(
timeline.isPlaying() &&
!settings.main.autoNavigateWhenPlaying &&
$scope.editScript) return
var location = programState.currentLoc.split(',')
function updateLocation() {

// Don't auto-navigate when editng or there's nowhere to navigate to.
// Don't auto-navigate when playing if we're showing a script.
// (If we're playing and not showing a script,
// we can autonavigate to initialize editScript.)
if($scope.editing || (timeline.isPlaying() && $scope.editScript)) return

$scope.editScript = programState.currentScript
$scope.currentLine = +location[2]
$scope.currentCh = +location[3]

if(programState.currentLoc) {
var location = programState.currentLoc.split(',')
$scope.currentLine = +location[2]
$scope.currentCh = +location[3]
} else {
$scope.currentLine = 0
$scope.currentCh = 0
}
}

$scope.getBookmarks = function() {
Expand Down Expand Up @@ -139,6 +145,7 @@ angular.module('main').controller('MainCtrl', [

$scope.$watch('getEditScript().body', updateCode)
$scope.$watch('programState.currentLoc', updateLocation)
$scope.$watch('getScriptCount()', updateLocation)

///////////
// Mode. //
Expand All @@ -158,10 +165,6 @@ angular.module('main').controller('MainCtrl', [

$scope.editing = false

var debouncedEdit = _.debounce(function(newVal) {
logClient.edit($scope.editScript, newVal)
})

var debouncedValidate = _.debounce(function(newVal) {

try {
Expand Down Expand Up @@ -208,15 +211,12 @@ angular.module('main').controller('MainCtrl', [

debouncedValidate(newVal)

if(newVal !== getEditScript().body)
$scope.editing = true
else return
if(newVal === getEditScript().body) return

$scope.editing = true

timeline.pause()
timeline.clear()

if(settings.main.autosave)
debouncedEdit(newVal)
})

$scope.reset = function(script) {
Expand All @@ -225,7 +225,8 @@ angular.module('main').controller('MainCtrl', [

$scope.play = function() {
timeline.clear()
debouncedEdit($scope.code)
getEditScript().body = $scope.code
logClient.edit($scope.editScript, $scope.code)
timeline.play()
}

Expand Down
2 changes: 1 addition & 1 deletion modules/main/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ angular.module('main').directive('editor', [
// Cursor.
var oldCursor = editor.getCursor()
, line = pending.line ? scope.$eval(attr.line) : oldCursor.line
, ch = pending.ch ? scope.$eval(attr.ch) : oldCursor.ch
, ch = pending.ch ? scope.$eval(attr.ch) || 0 : oldCursor.ch
, cursorUpdating = line !== oldCursor.line || ch !== oldCursor.ch

if(cursorUpdating) {
Expand Down
2 changes: 2 additions & 0 deletions modules/main/logClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ angular.module('main').factory('logClient', [

logClient.edit = function(script, code) {

if(!script) throw 'no script'

localStorage.removeItem('earhorn-listener')
localStorage.setItem('earhorn-listener', JSON.stringify({
type: 'edit',
Expand Down
4 changes: 3 additions & 1 deletion sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<head>
</head>
<body>
<!-- These scripts are bundled together by bundle.sh into earhorn.js. -->
<!-- We don't care about the bundle when we're using the sandbox. -->
<script src="components/esprima/esprima.js"></script>
<script src="components/umd-falafel/index.js"></script>
<script src="earhorn.js"></script>
<script src="instrumentor.js"></script>
<script>earhorn$('sandbox', function() {})()</script>
</body></html>
3 changes: 3 additions & 0 deletions todo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_ stuff required for release
_ bugs
_ fix empty sandbox isnt editable because editScript is missing
_ fix mouse update demo
_ set bookmarks during timeline update event (?)
_ consolidate 'current' detection
Expand Down Expand Up @@ -238,3 +239,5 @@ x set up esprima error notification
x nodemon cat earhorn-core.js umd-falafel esprima > esprima.js
x change mouse to use just earhorn.js
x fix small width styling

12-22-13 ~33

0 comments on commit caca279

Please sign in to comment.