|
|
@@ -10,13 +10,14 @@ define [
|
|
|
"ide/editor/directives/aceEditor/spell-check/SpellCheckAdapter"
|
|
|
"ide/editor/directives/aceEditor/highlights/HighlightsManager"
|
|
|
"ide/editor/directives/aceEditor/cursor-position/CursorPositionManager"
|
|
|
+ "ide/editor/directives/aceEditor/cursor-position/CursorPositionAdapter"
|
|
|
"ide/editor/directives/aceEditor/track-changes/TrackChangesManager"
|
|
|
"ide/editor/directives/aceEditor/metadata/MetadataManager"
|
|
|
"ide/metadata/services/metadata"
|
|
|
"ide/graphics/services/graphics"
|
|
|
"ide/preamble/services/preamble"
|
|
|
- "ide/files/services/files"
|
|
|
-], (App, Ace, SearchBox, Vim, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, SpellCheckAdapter, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager) ->
|
|
|
+ "ide/files/services/files"
|
|
|
+], (App, Ace, SearchBox, Vim, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, SpellCheckAdapter, HighlightsManager, CursorPositionManager, CursorPositionAdapter, TrackChangesManager, MetadataManager) ->
|
|
|
EditSession = ace.require('ace/edit_session').EditSession
|
|
|
ModeList = ace.require('ace/ext/modelist')
|
|
|
Vim = ace.require('ace/keyboard/vim').Vim
|
|
|
@@ -108,7 +109,7 @@ define [
|
|
|
|
|
|
undoManager = new UndoManager(scope, editor, element)
|
|
|
highlightsManager = new HighlightsManager(scope, editor, element)
|
|
|
- cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)
|
|
|
+ cursorPositionManager = new CursorPositionManager(scope, new CursorPositionAdapter(editor), localStorage)
|
|
|
trackChangesManager = new TrackChangesManager(scope, editor, element)
|
|
|
metadataManager = new MetadataManager(scope, editor, element, metadata)
|
|
|
autoCompleteManager = new AutoCompleteManager(scope, editor, element, metadataManager, graphics, preamble, files)
|
|
|
@@ -308,10 +309,12 @@ define [
|
|
|
|
|
|
scope.$watch "sharejsDoc", (sharejs_doc, old_sharejs_doc) ->
|
|
|
if old_sharejs_doc?
|
|
|
+ scope.$broadcast('beforeChangeDocument')
|
|
|
detachFromAce(old_sharejs_doc)
|
|
|
-
|
|
|
if sharejs_doc?
|
|
|
attachToAce(sharejs_doc)
|
|
|
+ if sharejs_doc? and old_sharejs_doc?
|
|
|
+ scope.$broadcast('afterChangeDocument')
|
|
|
|
|
|
scope.$watch "text", (text) ->
|
|
|
if text?
|
|
|
@@ -380,6 +383,30 @@ define [
|
|
|
editor.off 'changeSession', onSessionChangeForSpellCheck
|
|
|
editor.off 'nativecontextmenu', spellCheckManager.onContextMenu
|
|
|
|
|
|
+ onSessionChangeForCursorPosition = (e) ->
|
|
|
+ e.oldSession?.selection.off 'changeCursor', cursorPositionManager.onCursorChange
|
|
|
+ e.session.selection.on 'changeCursor', cursorPositionManager.onCursorChange
|
|
|
+
|
|
|
+ onUnloadForCursorPosition = () ->
|
|
|
+ cursorPositionManager.onUnload(editor.getSession())
|
|
|
+
|
|
|
+ initCursorPosition = () ->
|
|
|
+ editor.on 'changeSession', onSessionChangeForCursorPosition
|
|
|
+ onSessionChangeForCursorPosition({ session: editor.getSession() }) # Force initial setup
|
|
|
+ $(window).on "unload", onUnloadForCursorPosition
|
|
|
+
|
|
|
+ tearDownCursorPosition = () ->
|
|
|
+ editor.off 'changeSession', onSessionChangeForCursorPosition
|
|
|
+ $(window).off "unload", onUnloadForCursorPosition
|
|
|
+
|
|
|
+ initCursorPosition()
|
|
|
+
|
|
|
+ # Trigger the event once *only* - this is called after Ace is connected
|
|
|
+ # to the ShareJs instance but this event should only be triggered the
|
|
|
+ # first time the editor is opened. Not every time the docs opened
|
|
|
+ triggerEditorInitEvent = _.once () ->
|
|
|
+ scope.$broadcast('editorInit')
|
|
|
+
|
|
|
attachToAce = (sharejs_doc) ->
|
|
|
lines = sharejs_doc.getSnapshot().split("\n")
|
|
|
session = editor.getSession()
|
|
|
@@ -425,6 +452,7 @@ define [
|
|
|
editor.initing = false
|
|
|
# now ready to edit document
|
|
|
editor.setReadOnly(scope.readOnly) # respect the readOnly setting, normally false
|
|
|
+ triggerEditorInitEvent()
|
|
|
initSpellCheck()
|
|
|
|
|
|
resetScrollMargins()
|
|
|
@@ -489,6 +517,7 @@ define [
|
|
|
scope.$on '$destroy', () ->
|
|
|
if scope.sharejsDoc?
|
|
|
tearDownSpellCheck()
|
|
|
+ tearDownCursorPosition()
|
|
|
detachFromAce(scope.sharejsDoc)
|
|
|
session = editor.getSession()
|
|
|
session?.destroy()
|