|
|
@ -7,6 +7,8 @@ var ace = require('brace') |
|
|
|
|
|
|
|
|
|
|
|
require('brace/theme/tomorrow_night_blue') |
|
|
|
require('brace/theme/tomorrow_night_blue') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var globalRegistry = require('../../global/registry') |
|
|
|
|
|
|
|
|
|
|
|
var Range = ace.acequire('ace/range').Range |
|
|
|
var Range = ace.acequire('ace/range').Range |
|
|
|
require('brace/ext/language_tools') |
|
|
|
require('brace/ext/language_tools') |
|
|
|
require('brace/ext/searchbox') |
|
|
|
require('brace/ext/searchbox') |
|
|
@ -63,13 +65,19 @@ document.head.appendChild(yo` |
|
|
|
</style> |
|
|
|
</style> |
|
|
|
`)
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
|
|
function Editor (opts = {}) { |
|
|
|
function Editor (opts = {}, localRegistry) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
var el = yo`<div id="input"></div>` |
|
|
|
var el = yo`<div id="input"></div>` |
|
|
|
var editor = ace.edit(el) |
|
|
|
var editor = ace.edit(el) |
|
|
|
if (styles.appProperties.aceTheme) { |
|
|
|
if (styles.appProperties.aceTheme) { |
|
|
|
editor.setTheme('ace/theme/' + styles.appProperties.aceTheme) |
|
|
|
editor.setTheme('ace/theme/' + styles.appProperties.aceTheme) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self._components = {} |
|
|
|
|
|
|
|
self._components.registry = localRegistry || globalRegistry |
|
|
|
|
|
|
|
self._deps = { |
|
|
|
|
|
|
|
fileManager: self._components.registry.get('filemanager').api, |
|
|
|
|
|
|
|
config: self._components.registry.get('config').api |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ace.acequire('ace/ext/language_tools') |
|
|
|
ace.acequire('ace/ext/language_tools') |
|
|
|
editor.setOptions({ |
|
|
|
editor.setOptions({ |
|
|
@ -275,11 +283,15 @@ function Editor (opts = {}) { |
|
|
|
|
|
|
|
|
|
|
|
this.find = (string) => editor.find(string) |
|
|
|
this.find = (string) => editor.find(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.previousInput = '' |
|
|
|
|
|
|
|
this.saveTimeout = null |
|
|
|
// Do setup on initialisation here
|
|
|
|
// Do setup on initialisation here
|
|
|
|
editor.on('changeSession', function () { |
|
|
|
editor.on('changeSession', function () { |
|
|
|
|
|
|
|
editorOnChange(self) |
|
|
|
event.trigger('sessionSwitched', []) |
|
|
|
event.trigger('sessionSwitched', []) |
|
|
|
|
|
|
|
|
|
|
|
editor.getSession().on('change', function () { |
|
|
|
editor.getSession().on('change', function () { |
|
|
|
|
|
|
|
editorOnChange(self) |
|
|
|
event.trigger('contentChanged', []) |
|
|
|
event.trigger('contentChanged', []) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -290,4 +302,29 @@ function Editor (opts = {}) { |
|
|
|
editor.resize(true) |
|
|
|
editor.resize(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function editorOnChange (self) { |
|
|
|
|
|
|
|
var currentFile = self._deps.config.get('currentFile') |
|
|
|
|
|
|
|
if (!currentFile) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var input = self.get(currentFile) |
|
|
|
|
|
|
|
if (!input) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// if there's no change, don't do anything
|
|
|
|
|
|
|
|
if (input === self.previousInput) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.previousInput = input |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fire storage update
|
|
|
|
|
|
|
|
// NOTE: save at most once per 5 seconds
|
|
|
|
|
|
|
|
if (self.saveTimeout) { |
|
|
|
|
|
|
|
window.clearTimeout(self.saveTimeout) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.saveTimeout = window.setTimeout(() => { |
|
|
|
|
|
|
|
self._deps.fileManager.saveCurrentFile() |
|
|
|
|
|
|
|
}, 5000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Editor |
|
|
|
module.exports = Editor |
|
|
|