Commit 6020e045 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Editor: replace onChangeSetup with switched/changed events

parent 0789f747
...@@ -277,6 +277,8 @@ var run = function () { ...@@ -277,6 +277,8 @@ var run = function () {
return false return false
}) })
editor.event.register('switched', updateFiles)
function switchToFile (file) { function switchToFile (file) {
editor.setCacheFile(file) editor.setCacheFile(file)
updateFiles() updateFiles()
...@@ -573,7 +575,9 @@ var run = function () { ...@@ -573,7 +575,9 @@ var run = function () {
compileTimeout = window.setTimeout(runCompiler, 300) compileTimeout = window.setTimeout(runCompiler, 300)
} }
editor.onChangeSetup(editorOnChange) editor.event.register('changed', editorOnChange)
// in order to save the file when switching
editor.event.register('switched', editorOnChange)
$('#compile').click(function () { $('#compile').click(function () {
runCompiler() runCompiler()
......
...@@ -26,10 +26,9 @@ function Debugger (id, editor, compiler, executionContextEvent, switchToFile, of ...@@ -26,10 +26,9 @@ function Debugger (id, editor, compiler, executionContextEvent, switchToFile, of
self.removeCurrentMarker() self.removeCurrentMarker()
}) })
this.editor.onChangeSetup(function () { // unload if a file has changed (but not if tabs were switched)
if (arguments.length > 0) { // if arguments.length === 0 this is a session change, we don't want to stop debugging in that case editor.event.register('changed', function () {
self.debugger.unLoad() self.debugger.unLoad()
}
}) })
// register selected code item, highlight the corresponding source location // register selected code item, highlight the corresponding source location
......
...@@ -149,14 +149,6 @@ function Editor (doNotLoadStorage, storage) { ...@@ -149,14 +149,6 @@ function Editor (doNotLoadStorage, storage) {
editor.getSession().setAnnotations(sourceAnnotations) editor.getSession().setAnnotations(sourceAnnotations)
} }
this.onChangeSetup = function (onChange) {
editor.getSession().on('change', onChange)
editor.on('changeSession', function () {
editor.getSession().on('change', onChange)
onChange()
})
}
this.handleErrorClick = function (errLine, errCol) { this.handleErrorClick = function (errLine, errCol) {
editor.focus() editor.focus()
editor.gotoLine(errLine + 1, errCol - 1, true) editor.gotoLine(errLine + 1, errCol - 1, true)
...@@ -172,6 +164,13 @@ function Editor (doNotLoadStorage, storage) { ...@@ -172,6 +164,13 @@ function Editor (doNotLoadStorage, storage) {
} }
// Do setup on initialisation here // Do setup on initialisation here
editor.on('changeSession', function () {
event.trigger('switched', [])
editor.getSession().on('change', function () {
event.trigger('changed', [])
})
})
// Unmap ctrl-t & ctrl-f // Unmap ctrl-t & ctrl-f
editor.commands.bindKeys({ 'ctrl-t': null }) editor.commands.bindKeys({ 'ctrl-t': null })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment