More performance tweaks

This commit is contained in:
James Allen 2014-07-09 16:07:42 +01:00
parent b0f43eab19
commit 51d0026b74
4 changed files with 30 additions and 32 deletions

View file

@ -38,7 +38,7 @@ define [
done = () =>
if options.gotoLine?
@$scope.editor.gotoLine = options.gotoLine
@$scope.$broadcast "editor:gotoLine", options.gotoLine
if doc.id == @$scope.editor.open_doc_id and !options.forceReopen
@$scope.$apply () =>

View file

@ -46,8 +46,8 @@ define [
scope.name = attrs.aceEditor
# autoCompleteManager = new AutoCompleteManager(scope, editor, element)
# spellCheckManager = new SpellCheckManager(scope, editor, element)
autoCompleteManager = new AutoCompleteManager(scope, editor, element)
spellCheckManager = new SpellCheckManager(scope, editor, element)
undoManager = new UndoManager(scope, editor, element)
highlightsManager = new HighlightsManager(scope, editor, element)
cursorPositionManager = new CursorPositionManager(scope, editor, element)

View file

@ -3,47 +3,49 @@ define [], () ->
constructor: (@$scope, @editor, @element) ->
@editor.on "changeSession", (e) =>
e.session.on "changeScrollTop", (e) =>
@onScrollTopChange(e)
if e.oldSession?
@storeCursorPosition(e.oldSession)
@storeScrollTopPosition(e.oldSession)
@doc_id = @$scope.sharejsDoc?.doc_id
e.session.selection.on 'changeCursor', (e) =>
@onCursorChange(e)
@emitCursorUpdateEvent(e)
@gotoStoredPosition()
setTimeout () =>
@gotoStoredPosition()
, 0
@$scope.$watch "gotoLine", (value) =>
$(window).on "unload", () =>
@storeCursorPosition(@editor.getSession())
@storeScrollTopPosition(@editor.getSession())
@$scope.$on "#{@$scope.name}:gotoLine", (editor, value) =>
console.log "Going to line", value
if value?
setTimeout () =>
@gotoLine(value)
@$scope.$apply () =>
@$scope.gotoLine = null
, 0
onScrollTopChange: (event) ->
if !@ignoreCursorPositionChanges and doc_id = @$scope.sharejsDoc?.doc_id
docPosition = $.localStorage("doc.position.#{doc_id}") || {}
docPosition.scrollTop = @editor.getSession().getScrollTop()
$.localStorage("doc.position.#{doc_id}", docPosition)
storeScrollTopPosition: (session) ->
if @doc_id?
docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
docPosition.scrollTop = session.getScrollTop()
$.localStorage("doc.position.#{@doc_id}", docPosition)
storeCursorPosition: (session) ->
if @doc_id?
docPosition = $.localStorage("doc.position.#{@doc_id}") || {}
docPosition.cursorPosition = session.selection.getCursor()
$.localStorage("doc.position.#{@doc_id}", docPosition)
onCursorChange: (event) ->
@storeCursorPosition()
@emitCursorUpdateEvent()
storeCursorPosition: () ->
if !@ignoreCursorPositionChanges and doc_id = @$scope.sharejsDoc?.doc_id
docPosition = $.localStorage("doc.position.#{doc_id}") || {}
docPosition.cursorPosition = @editor.getCursorPosition()
$.localStorage("doc.position.#{doc_id}", docPosition)
emitCursorUpdateEvent: () ->
cursor = @editor.getCursorPosition()
@$scope.$emit "cursor:#{@$scope.name}:update", cursor
gotoStoredPosition: () ->
doc_id = @$scope.sharejsDoc?.doc_id
return if !doc_id?
pos = $.localStorage("doc.position.#{doc_id}") || {}
return if !@doc_id?
pos = $.localStorage("doc.position.#{@doc_id}") || {}
@ignoreCursorPositionChanges = true
@editor.moveCursorToPosition(pos.cursorPosition or {row: 0, column: 0})
@editor.getSession().setScrollTop(pos.scrollTop or 0)

View file

@ -29,8 +29,6 @@ define [
$(document).on "click", (e) =>
@closeContextMenu(e)
return true
# $(document).on "contextmenu", (e) =>
# @closeContextMenu(e)
@$scope.replaceWord = (highlight, suggestion) =>
@replaceWord(highlight, suggestion)
@ -39,13 +37,11 @@ define [
@learnWord(highlight)
runFullCheck: () ->
console.log "Running full check"
@highlightedWordManager.clearRows()
if @$scope.spellCheckLanguage and @$scope.spellCheckLanguage != ""
@runSpellCheck()
runCheckOnChange: (e) ->
console.log "Checking change", e.data
if @$scope.spellCheckLanguage and @$scope.spellCheckLanguage != ""
@highlightedWordManager.applyChange(e.data)
@markLinesAsUpdated(e.data)