mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Try to clean up to avoid memory leaks
This commit is contained in:
parent
f2b8a5971f
commit
9e4653d83c
5 changed files with 25 additions and 13 deletions
|
@ -82,7 +82,7 @@ define [
|
|||
|
||||
_unBindFromSocketEvents: () ->
|
||||
@ide.socket.removeListener "otUpdateApplied", @_onUpdateAppliedHandler
|
||||
@ide.socket.removeListener "otUpdateError", @_onUpdateErrorHandler
|
||||
@ide.socket.removeListener "otUpdateError", @_onErrorHandler
|
||||
@ide.socket.removeListener "disconnect", @_onDisconnectHandler
|
||||
|
||||
leaveAndCleanUp: () ->
|
||||
|
|
|
@ -107,6 +107,9 @@ define [
|
|||
session.setMode("ace/mode/latex")
|
||||
session.setAnnotations scope.annotations
|
||||
|
||||
emitChange = () ->
|
||||
scope.$emit "#{scope.name}:change"
|
||||
|
||||
attachToAce = (sharejs_doc) ->
|
||||
lines = sharejs_doc.getSnapshot().split("\n")
|
||||
editor.setSession(new EditSession(lines))
|
||||
|
@ -114,8 +117,7 @@ define [
|
|||
session = editor.getSession()
|
||||
|
||||
doc = session.getDocument()
|
||||
doc.on "change", () ->
|
||||
scope.$emit "#{scope.name}:change"
|
||||
doc.on "change", emitChange
|
||||
|
||||
sharejs_doc.on "remoteop.recordForUndo", () =>
|
||||
undoManager.nextUpdateIsRemote = true
|
||||
|
@ -128,6 +130,10 @@ define [
|
|||
sharejs_doc.detachFromAce()
|
||||
sharejs_doc.off "remoteop.recordForUndo"
|
||||
|
||||
session = editor.getSession()
|
||||
doc = session.getDocument()
|
||||
doc.off "change", emitChange
|
||||
|
||||
template: """
|
||||
<div class="ace-editor-wrapper">
|
||||
<div
|
||||
|
|
|
@ -24,8 +24,12 @@ define [
|
|||
else
|
||||
@disable()
|
||||
|
||||
onChange = (change) =>
|
||||
@onChange(change)
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
@bindToSession(e.session)
|
||||
e.oldSession.off "change", onChange
|
||||
e.session.on "change", onChange
|
||||
|
||||
enable: () ->
|
||||
@editor.setOptions({
|
||||
|
@ -45,9 +49,6 @@ define [
|
|||
enableSnippets: false
|
||||
})
|
||||
|
||||
bindToSession: (@aceSession) ->
|
||||
@aceSession.on "change", (change) => @onChange(change)
|
||||
|
||||
onChange: (change) ->
|
||||
cursorPosition = @editor.getCursorPosition()
|
||||
end = change.data.range.end
|
||||
|
@ -56,7 +57,7 @@ define [
|
|||
if end.row == cursorPosition.row and end.column == cursorPosition.column + 1
|
||||
if change.data.action == "insertText"
|
||||
range = new Range(end.row, 0, end.row, end.column)
|
||||
lineUpToCursor = @aceSession.getTextRange(range)
|
||||
lineUpToCursor = @editor.getSession().getTextRange(range)
|
||||
commandFragment = getLastCommandFragment(lineUpToCursor)
|
||||
|
||||
if commandFragment? and commandFragment.length > 2
|
||||
|
|
|
@ -2,6 +2,9 @@ define [], () ->
|
|||
class CursorPositionManager
|
||||
constructor: (@$scope, @editor, @element) ->
|
||||
|
||||
onChangeCursor = (e) =>
|
||||
@emitCursorUpdateEvent(e)
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
if e.oldSession?
|
||||
@storeCursorPosition(e.oldSession)
|
||||
|
@ -9,8 +12,8 @@ define [], () ->
|
|||
|
||||
@doc_id = @$scope.sharejsDoc?.doc_id
|
||||
|
||||
e.session.selection.on 'changeCursor', (e) =>
|
||||
@emitCursorUpdateEvent(e)
|
||||
e.oldSession?.selection.off 'changeCursor', onChangeCursor
|
||||
e.session.selection.on 'changeCursor', onChangeCursor
|
||||
|
||||
setTimeout () =>
|
||||
@gotoStoredPosition()
|
||||
|
|
|
@ -13,12 +13,14 @@ define [
|
|||
if language != oldLanguage and oldLanguage?
|
||||
@runFullCheck()
|
||||
|
||||
onChange = (e) =>
|
||||
@runCheckOnChange(e)
|
||||
|
||||
@editor.on "changeSession", (e) =>
|
||||
@runFullCheck()
|
||||
|
||||
doc = e.session.getDocument()
|
||||
doc.on "change", (e) =>
|
||||
@runCheckOnChange(e)
|
||||
e.oldSession?.getDocument().off "change", onChange
|
||||
e.session.getDocument().on "change", onChange
|
||||
|
||||
@$scope.spellingMenu = {left: '0px', top: '0px'}
|
||||
|
||||
|
|
Loading…
Reference in a new issue