Code tidy up of ace editor directive

This commit is contained in:
James Allen
2014-06-25 16:46:28 +01:00
parent 5922ed45ee
commit 703a4faa0e
5 changed files with 35 additions and 29 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ block content
.ui-layout-center
.loading(ng-show="!editor.sharejs_doc || editor.opening")
i.fa.fa-spin.fa-refresh
| Loading...
|   Loading...
#editor(
ace-editor,
ng-show="!!editor.sharejs_doc && !editor.opening"
@@ -26,7 +26,7 @@ define [
return null
class AutoCompleteManager
constructor: (@editor) ->
constructor: (@$scope, @editor) ->
@suggestionManager = new SuggestionManager()
insertMatch = Autocomplete::insertMatch
@@ -43,6 +43,17 @@ define [
insertMatch.call editor.completer, data
@$scope.$watch "autoComplete", (autocomplete) =>
console.log "autocomplete change", autocomplete
if autocomplete
@enable()
else
@disable()
@editor.on "changeSession", (e) =>
@bindToSession(e.session)
enable: () ->
@editor.setOptions({
enableBasicAutocompletion: true,
@@ -25,12 +25,11 @@ define [
spellCheckLanguage: "="
}
link: (scope, element, attrs) ->
editor = window.editor = Ace.edit(element.find(".ace-editor-body")[0])
scope.undo =
show_remote_warning: false
editor = Ace.edit(element.find(".ace-editor-body")[0])
autoCompleteManager = new AutoCompleteManager(editor)
autoCompleteManager = new AutoCompleteManager(scope, editor)
spellCheckManager = new SpellCheckManager(scope, editor, element)
undoManager = new UndoManager(scope, editor)
# Prevert Ctrl|Cmd-S from triggering save dialog
editor.commands.addCommand
@@ -66,14 +65,6 @@ define [
if sharejs_doc?
attachToAce(sharejs_doc)
scope.$watch "autoComplete", (autocomplete) ->
if autocomplete
console.log "Enabling auto complete"
autoCompleteManager.enable()
else
console.log "Disabling auto complete"
autoCompleteManager.disable()
attachToAce = (sharejs_doc) ->
lines = sharejs_doc.getSnapshot().split("\n")
editor.setSession(new EditSession(lines))
@@ -88,18 +79,6 @@ define [
scope.$apply () ->
scope.lastUpdated = new Date()
undoManager = new UndoManager({
showUndoConflictWarning: () ->
scope.$apply () ->
scope.undo.show_remote_warning = true
$timeout () ->
scope.undo.show_remote_warning = false
, 4000
})
session.setUndoManager(undoManager)
sharejs_doc.on "remoteop.recordForUndo", () =>
undoManager.nextUpdateIsRemote = true
@@ -8,10 +8,26 @@ define [
Doc = require("ace/document").Document
class UndoManager
constructor: (@manager) ->
constructor: (@$scope, @editor) ->
@$scope.undo =
show_remote_warning: false
@reset()
@nextUpdateIsRemote = false
@editor.on "changeSession", (e) =>
console.log "setting undo manager", e.session
e.session.setUndoManager(@)
showUndoConflictWarning: () ->
@$scope.$apply () =>
@$scope.undo.show_remote_warning = true
setTimeout () =>
@$scope.$apply () =>
@$scope.undo.show_remote_warning = false
, 4000
reset: () ->
@undoStack = []
@redoStack = []
@@ -39,7 +55,7 @@ define [
return if !update?
if update.remote
@manager.showUndoConflictWarning()
@showUndoConflictWarning()
lines = @session.getDocument().getAllLines()
linesBeforeDelta = @_revertSimpleDeltaSetsOnDocLines(update.deltaSets, lines)
@@ -8,7 +8,7 @@ define [
ide.$http = $http
ide.pushEvent = () ->
console.log "PUSHING EVENT STUB", arguments
#console.log "PUSHING EVENT STUB", arguments
ide.reportError = () ->
console.log "REPORTING ERROR STUB", arguments