Only tokenize in background if when a buffer is visible in an editor

This will prevent running a bunch of background tokenization when Atom is reloaded. We only perform tokenization to support content that is actually on screen.
This commit is contained in:
Nathan Sobo
2012-11-23 12:14:46 -07:00
parent f28cedea7d
commit a1ae819908
5 changed files with 12 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ describe "TokenizedBuffer", ->
editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false)
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
editSession.setVisible(true)
changeHandler = jasmine.createSpy('changeHandler')
tokenizedBuffer.on "change", changeHandler
@@ -289,6 +290,7 @@ describe "TokenizedBuffer", ->
editSession = fixturesProject.buildEditSessionForPath('sample-with-tabs.coffee', { tabLength })
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
editSession.setVisible(true)
afterEach ->
editSession.destroy()

View File

@@ -27,6 +27,8 @@ class DisplayBuffer
@buildLineMap()
@tokenizedBuffer.on 'change', (e) => @handleTokenizedBufferChange(e)
setVisible: (visible) -> @tokenizedBuffer.setVisible(visible)
buildLineMap: ->
@lineMap = new LineMap
@lineMap.insertAtScreenRow 0, @buildLinesForBufferRows(0, @buffer.getLastRow())

View File

@@ -91,6 +91,8 @@ class EditSession
@scrollLeft == other.getScrollLeft() and
@getCursorScreenPosition().isEqual(other.getCursorScreenPosition())
setVisible: (visible) -> @displayBuffer.setVisible(visible)
setScrollTop: (@scrollTop) ->
getScrollTop: -> @scrollTop

View File

@@ -422,6 +422,7 @@ class Editor extends View
@activeEditSession.off()
@activeEditSession = @editSessions[index]
@activeEditSession.setVisible(true)
@activeEditSession.on "buffer-contents-change-on-disk", =>
@showBufferConflictAlert(@activeEditSession)

View File

@@ -16,6 +16,7 @@ class TokenizedBuffer
screenLines: null
chunkSize: 50
invalidRows: null
visible: false
constructor: (@buffer, { @languageMode, @tabLength }) ->
@tabLength ?= 2
@@ -25,6 +26,9 @@ class TokenizedBuffer
@invalidateRow(0)
@buffer.on "change.tokenized-buffer#{@id}", (e) => @handleBufferChange(e)
setVisible: (@visible) ->
@tokenizeInBackground() if @visible
getTabLength: ->
@tabLength
@@ -35,7 +39,7 @@ class TokenizedBuffer
@trigger "change", { start: 0, end: lastRow, delta: 0 }
tokenizeInBackground: ->
return if @pendingChunk
return if not @visible or @pendingChunk
@pendingChunk = true
_.defer =>
@pendingChunk = false