Try to clean up to avoid memory leaks

This commit is contained in:
James Allen 2014-07-09 20:49:10 +01:00
parent f2b8a5971f
commit 9e4653d83c
5 changed files with 25 additions and 13 deletions

View file

@ -82,7 +82,7 @@ define [
_unBindFromSocketEvents: () -> _unBindFromSocketEvents: () ->
@ide.socket.removeListener "otUpdateApplied", @_onUpdateAppliedHandler @ide.socket.removeListener "otUpdateApplied", @_onUpdateAppliedHandler
@ide.socket.removeListener "otUpdateError", @_onUpdateErrorHandler @ide.socket.removeListener "otUpdateError", @_onErrorHandler
@ide.socket.removeListener "disconnect", @_onDisconnectHandler @ide.socket.removeListener "disconnect", @_onDisconnectHandler
leaveAndCleanUp: () -> leaveAndCleanUp: () ->

View file

@ -107,6 +107,9 @@ define [
session.setMode("ace/mode/latex") session.setMode("ace/mode/latex")
session.setAnnotations scope.annotations session.setAnnotations scope.annotations
emitChange = () ->
scope.$emit "#{scope.name}:change"
attachToAce = (sharejs_doc) -> attachToAce = (sharejs_doc) ->
lines = sharejs_doc.getSnapshot().split("\n") lines = sharejs_doc.getSnapshot().split("\n")
editor.setSession(new EditSession(lines)) editor.setSession(new EditSession(lines))
@ -114,8 +117,7 @@ define [
session = editor.getSession() session = editor.getSession()
doc = session.getDocument() doc = session.getDocument()
doc.on "change", () -> doc.on "change", emitChange
scope.$emit "#{scope.name}:change"
sharejs_doc.on "remoteop.recordForUndo", () => sharejs_doc.on "remoteop.recordForUndo", () =>
undoManager.nextUpdateIsRemote = true undoManager.nextUpdateIsRemote = true
@ -128,6 +130,10 @@ define [
sharejs_doc.detachFromAce() sharejs_doc.detachFromAce()
sharejs_doc.off "remoteop.recordForUndo" sharejs_doc.off "remoteop.recordForUndo"
session = editor.getSession()
doc = session.getDocument()
doc.off "change", emitChange
template: """ template: """
<div class="ace-editor-wrapper"> <div class="ace-editor-wrapper">
<div <div

View file

@ -24,8 +24,12 @@ define [
else else
@disable() @disable()
onChange = (change) =>
@onChange(change)
@editor.on "changeSession", (e) => @editor.on "changeSession", (e) =>
@bindToSession(e.session) e.oldSession.off "change", onChange
e.session.on "change", onChange
enable: () -> enable: () ->
@editor.setOptions({ @editor.setOptions({
@ -45,9 +49,6 @@ define [
enableSnippets: false enableSnippets: false
}) })
bindToSession: (@aceSession) ->
@aceSession.on "change", (change) => @onChange(change)
onChange: (change) -> onChange: (change) ->
cursorPosition = @editor.getCursorPosition() cursorPosition = @editor.getCursorPosition()
end = change.data.range.end end = change.data.range.end
@ -56,7 +57,7 @@ define [
if end.row == cursorPosition.row and end.column == cursorPosition.column + 1 if end.row == cursorPosition.row and end.column == cursorPosition.column + 1
if change.data.action == "insertText" if change.data.action == "insertText"
range = new Range(end.row, 0, end.row, end.column) range = new Range(end.row, 0, end.row, end.column)
lineUpToCursor = @aceSession.getTextRange(range) lineUpToCursor = @editor.getSession().getTextRange(range)
commandFragment = getLastCommandFragment(lineUpToCursor) commandFragment = getLastCommandFragment(lineUpToCursor)
if commandFragment? and commandFragment.length > 2 if commandFragment? and commandFragment.length > 2

View file

@ -2,6 +2,9 @@ define [], () ->
class CursorPositionManager class CursorPositionManager
constructor: (@$scope, @editor, @element) -> constructor: (@$scope, @editor, @element) ->
onChangeCursor = (e) =>
@emitCursorUpdateEvent(e)
@editor.on "changeSession", (e) => @editor.on "changeSession", (e) =>
if e.oldSession? if e.oldSession?
@storeCursorPosition(e.oldSession) @storeCursorPosition(e.oldSession)
@ -9,8 +12,8 @@ define [], () ->
@doc_id = @$scope.sharejsDoc?.doc_id @doc_id = @$scope.sharejsDoc?.doc_id
e.session.selection.on 'changeCursor', (e) => e.oldSession?.selection.off 'changeCursor', onChangeCursor
@emitCursorUpdateEvent(e) e.session.selection.on 'changeCursor', onChangeCursor
setTimeout () => setTimeout () =>
@gotoStoredPosition() @gotoStoredPosition()

View file

@ -13,12 +13,14 @@ define [
if language != oldLanguage and oldLanguage? if language != oldLanguage and oldLanguage?
@runFullCheck() @runFullCheck()
onChange = (e) =>
@runCheckOnChange(e)
@editor.on "changeSession", (e) => @editor.on "changeSession", (e) =>
@runFullCheck() @runFullCheck()
doc = e.session.getDocument() e.oldSession?.getDocument().off "change", onChange
doc.on "change", (e) => e.session.getDocument().on "change", onChange
@runCheckOnChange(e)
@$scope.spellingMenu = {left: '0px', top: '0px'} @$scope.spellingMenu = {left: '0px', top: '0px'}