From 558eb1bb8c7156fa437675d0e0c5749d8d4ac197 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Mon, 20 Jul 2015 15:41:13 -0700 Subject: [PATCH 01/14] Use mutation observer for document changes --- src/view-registry.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/view-registry.coffee b/src/view-registry.coffee index 24c53bd57..285c715dd 100644 --- a/src/view-registry.coffee +++ b/src/view-registry.coffee @@ -55,6 +55,8 @@ class ViewRegistry @documentReaders = [] @documentPollers = [] + @observer = new MutationObserver(@performDocumentPoll) + # Essential: Add a provider that will be used to construct views in the # workspace's view layer based on model objects in its model layer. # @@ -208,10 +210,10 @@ class ViewRegistry writer() while writer = @documentWriters.shift() startPollingDocument: -> - @pollIntervalHandle = window.setInterval(@performDocumentPoll, @documentPollingInterval) + @observer.observe(document, {subtree: true, childList: true, attributes: true}) stopPollingDocument: -> - window.clearInterval(@pollIntervalHandle) + @observer.disconnect() performDocumentPoll: => if @documentUpdateRequested From 21c91b9bf390979c092e8d417dfcee3e2ff92fdd Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Mon, 20 Jul 2015 16:14:50 -0700 Subject: [PATCH 02/14] Check if cursor is blinking before pausing --- src/text-editor-presenter.coffee | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 8eb80275a..7bb84bd1a 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -1386,12 +1386,15 @@ class TextEditorPresenter @emitDidUpdateState() startBlinkingCursors: -> - unless @toggleCursorBlinkHandle + unless @isCursorBlinking() @state.content.cursorsVisible = true @toggleCursorBlinkHandle = setInterval(@toggleCursorBlink.bind(this), @getCursorBlinkPeriod() / 2) + isCursorBlinking: -> + @toggleCursorBlinkHandle? + stopBlinkingCursors: (visible) -> - if @toggleCursorBlinkHandle + if @isCursorBlinking() @state.content.cursorsVisible = visible clearInterval(@toggleCursorBlinkHandle) @toggleCursorBlinkHandle = null @@ -1401,7 +1404,8 @@ class TextEditorPresenter @emitDidUpdateState() pauseCursorBlinking: -> - @stopBlinkingCursors(true) - @startBlinkingCursorsAfterDelay ?= _.debounce(@startBlinkingCursors, @getCursorBlinkResumeDelay()) - @startBlinkingCursorsAfterDelay() - @emitDidUpdateState() + if @isCursorBlinking() + @stopBlinkingCursors(true) + @startBlinkingCursorsAfterDelay ?= _.debounce(@startBlinkingCursors, @getCursorBlinkResumeDelay()) + @startBlinkingCursorsAfterDelay() + @emitDidUpdateState() From 3715e05bedf601d35a9665f24fe135f50996444a Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Mon, 20 Jul 2015 16:37:56 -0700 Subject: [PATCH 03/14] Change spec to test on DOM mutation rather than interval --- spec/view-registry-spec.coffee | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index df822309e..cb8a4d148 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -183,7 +183,10 @@ describe "ViewRegistry", -> expect(events).toEqual ['write', 'read', 'poll'] describe "::pollDocument(fn)", -> - it "calls all registered reader functions on an interval until they are disabled via a returned disposable", -> + it "calls all registered polling functions after document changes until they are disabled via a returned disposable", -> + testElement = document.createElement('div') + document.getElementById('jasmine-content').appendChild(testElement) + spyOn(window, 'setInterval').andCallFake(fakeSetInterval) events = [] @@ -192,16 +195,18 @@ describe "ViewRegistry", -> expect(events).toEqual [] - advanceClock(registry.documentPollingInterval) - expect(events).toEqual ['poll 1', 'poll 2'] + testElement.style.height = '400px' - advanceClock(registry.documentPollingInterval) - expect(events).toEqual ['poll 1', 'poll 2', 'poll 1', 'poll 2'] + waitsFor "events to occur", -> events.length > 0 - disposable1.dispose() - advanceClock(registry.documentPollingInterval) - expect(events).toEqual ['poll 1', 'poll 2', 'poll 1', 'poll 2', 'poll 2'] + runs -> + expect(events).toEqual ['poll 1', 'poll 2'] + events.length = 0 - disposable2.dispose() - advanceClock(registry.documentPollingInterval) - expect(events).toEqual ['poll 1', 'poll 2', 'poll 1', 'poll 2', 'poll 2'] + disposable1.dispose() + testElement.style.color = '#fff' + + waitsFor "more events to occur", -> events.length > 0 + + runs -> + expect(events).toEqual ['poll 2'] From ba586319848de249d17c8da3b40c16827b9f86b3 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 10:21:06 -0700 Subject: [PATCH 04/14] Update all text editor styles in one batch This allows DOM mutation observers to detect changes to the global styles. --- src/workspace-element.coffee | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/workspace-element.coffee b/src/workspace-element.coffee index 028a6e561..e07d9c90f 100644 --- a/src/workspace-element.coffee +++ b/src/workspace-element.coffee @@ -12,7 +12,6 @@ class WorkspaceElement extends HTMLElement createdCallback: -> @subscriptions = new CompositeDisposable - @initializeGlobalTextEditorStyleSheet() @initializeContent() @observeScrollbarStyle() @observeTextEditorFontConfig() @@ -26,10 +25,6 @@ class WorkspaceElement extends HTMLElement @subscriptions.dispose() @model.destroy() - initializeGlobalTextEditorStyleSheet: -> - atom.styles.addStyleSheet('atom-text-editor {}', sourcePath: 'global-text-editor-styles') - @globalTextEditorStyleSheet = document.head.querySelector('style[source-path="global-text-editor-styles"]').sheet - initializeContent: -> @classList.add 'workspace' @setAttribute 'tabindex', -1 @@ -54,9 +49,20 @@ class WorkspaceElement extends HTMLElement @classList.add("scrollbars-visible-when-scrolling") observeTextEditorFontConfig: -> - @subscriptions.add atom.config.observe 'editor.fontSize', @setTextEditorFontSize.bind(this) - @subscriptions.add atom.config.observe 'editor.fontFamily', @setTextEditorFontFamily.bind(this) - @subscriptions.add atom.config.observe 'editor.lineHeight', @setTextEditorLineHeight.bind(this) + @updateGlobalTextEditorStyleSheet() + @subscriptions.add atom.config.onDidChange 'editor.fontSize', @updateGlobalTextEditorStyleSheet.bind(this) + @subscriptions.add atom.config.onDidChange 'editor.fontFamily', @updateGlobalTextEditorStyleSheet.bind(this) + @subscriptions.add atom.config.onDidChange 'editor.lineHeight', @updateGlobalTextEditorStyleSheet.bind(this) + + updateGlobalTextEditorStyleSheet: -> + styleSheetSource = """ + atom-text-editor { + font-size: #{atom.config.get('editor.fontSize')}px; + font-family: #{atom.config.get('editor.fontFamily')}; + line-height: #{atom.config.get('editor.lineHeight')}; + } + """ + atom.styles.addStyleSheet(styleSheetSource, sourcePath: 'global-text-editor-styles') createSpacePenShim: -> WorkspaceView ?= require './workspace-view' @@ -87,20 +93,6 @@ class WorkspaceElement extends HTMLElement getModel: -> @model - setTextEditorFontSize: (fontSize) -> - @updateGlobalEditorStyle('font-size', fontSize + 'px') - - setTextEditorFontFamily: (fontFamily) -> - @updateGlobalEditorStyle('font-family', fontFamily) - - setTextEditorLineHeight: (lineHeight) -> - @updateGlobalEditorStyle('line-height', lineHeight) - - updateGlobalEditorStyle: (property, value) -> - editorRule = @globalTextEditorStyleSheet.cssRules[0] - editorRule.style[property] = value - atom.themes.emitter.emit 'did-update-stylesheet', @globalTextEditorStyleSheet - handleFocus: (event) -> @model.getActivePane().activate() From 2f11b86a341a38e697e8158ce57388b643b118fa Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 10:22:31 -0700 Subject: [PATCH 05/14] Ensure document polling functions run when stylesheets change --- spec/view-registry-spec.coffee | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index cb8a4d148..94af1e9fc 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -183,9 +183,13 @@ describe "ViewRegistry", -> expect(events).toEqual ['write', 'read', 'poll'] describe "::pollDocument(fn)", -> - it "calls all registered polling functions after document changes until they are disabled via a returned disposable", -> + it "calls all registered polling functions after document or stylesheet changes until they are disabled via a returned disposable", -> testElement = document.createElement('div') - document.getElementById('jasmine-content').appendChild(testElement) + testStyleSheet = document.createElement('style') + testStyleSheet.textContent = 'body {}' + jasmineContent = document.getElementById('jasmine-content') + jasmineContent.appendChild(testElement) + jasmineContent.appendChild(testStyleSheet) spyOn(window, 'setInterval').andCallFake(fakeSetInterval) @@ -197,7 +201,15 @@ describe "ViewRegistry", -> testElement.style.height = '400px' - waitsFor "events to occur", -> events.length > 0 + waitsFor "events to occur in response to DOM mutation", -> events.length > 0 + + runs -> + expect(events).toEqual ['poll 1', 'poll 2'] + events.length = 0 + + testStyleSheet.textContent = 'body {color: #333;}' + + waitsFor "events to occur in reponse to style mutation", -> events.length > 0 runs -> expect(events).toEqual ['poll 1', 'poll 2'] @@ -206,7 +218,7 @@ describe "ViewRegistry", -> disposable1.dispose() testElement.style.color = '#fff' - waitsFor "more events to occur", -> events.length > 0 + waitsFor "more events to occur in response to DOM mutation", -> events.length > 0 runs -> expect(events).toEqual ['poll 2'] From 39749ac70a799a200a23ab6ef83d13b5d0bd85f9 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 11:07:54 -0700 Subject: [PATCH 06/14] Remove unused spy for intervals --- spec/view-registry-spec.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index 94af1e9fc..a2a78b370 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -191,8 +191,6 @@ describe "ViewRegistry", -> jasmineContent.appendChild(testElement) jasmineContent.appendChild(testStyleSheet) - spyOn(window, 'setInterval').andCallFake(fakeSetInterval) - events = [] disposable1 = registry.pollDocument -> events.push('poll 1') disposable2 = registry.pollDocument -> events.push('poll 2') From fb7304a3d7d515d63089d3c0b7b1f3c21237a5c2 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 11:09:23 -0700 Subject: [PATCH 07/14] Remove event listeners after each test --- spec/view-registry-spec.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index a2a78b370..e5153647d 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -7,6 +7,9 @@ describe "ViewRegistry", -> beforeEach -> registry = new ViewRegistry + afterEach -> + registry.clearDocumentRequests() + describe "::getView(object)", -> describe "when passed a DOM node", -> it "returns the given DOM node", -> From 96874d68d8f5fe58ea2df605ef9372be09dd5fcf Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 11:10:35 -0700 Subject: [PATCH 08/14] Run polling functions when windows resizes --- spec/view-registry-spec.coffee | 12 +++++++++++- src/view-registry.coffee | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index e5153647d..10ad0f7eb 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -186,7 +186,9 @@ describe "ViewRegistry", -> expect(events).toEqual ['write', 'read', 'poll'] describe "::pollDocument(fn)", -> - it "calls all registered polling functions after document or stylesheet changes until they are disabled via a returned disposable", -> + [testElement, testStyleSheet, disposable1, disposable2, events] = [] + + beforeEach -> testElement = document.createElement('div') testStyleSheet = document.createElement('style') testStyleSheet.textContent = 'body {}' @@ -198,6 +200,7 @@ describe "ViewRegistry", -> disposable1 = registry.pollDocument -> events.push('poll 1') disposable2 = registry.pollDocument -> events.push('poll 2') + it "calls all registered polling functions after document or stylesheet changes until they are disabled via a returned disposable", -> expect(events).toEqual [] testElement.style.height = '400px' @@ -223,3 +226,10 @@ describe "ViewRegistry", -> runs -> expect(events).toEqual ['poll 2'] + + it "calls all registered polling functions when the window resizes", -> + expect(events).toEqual [] + + window.dispatchEvent(new UIEvent('resize')) + + expect(events).toEqual ['poll 1', 'poll 2'] diff --git a/src/view-registry.coffee b/src/view-registry.coffee index 285c715dd..4c98bb153 100644 --- a/src/view-registry.coffee +++ b/src/view-registry.coffee @@ -210,9 +210,11 @@ class ViewRegistry writer() while writer = @documentWriters.shift() startPollingDocument: -> + window.addEventListener('resize', @performDocumentPoll) @observer.observe(document, {subtree: true, childList: true, attributes: true}) stopPollingDocument: -> + window.removeEventListener('resize', @performDocumentPoll) @observer.disconnect() performDocumentPoll: => From 40ba0da4f5515e11e83aa4aaf80b3170f732aa2c Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Tue, 21 Jul 2015 11:19:54 -0700 Subject: [PATCH 09/14] Remove resize listeners from editor pollDOM will always be called when window is resized --- src/text-editor-component.coffee | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index 45591c195..8a1469bb9 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -107,7 +107,6 @@ class TextEditorComponent @disposables.dispose() @presenter.destroy() @gutterContainerComponent?.destroy() - window.removeEventListener 'resize', @requestHeightAndWidthMeasurement getDomNode: -> @domNode @@ -224,7 +223,6 @@ class TextEditorComponent @domNode.addEventListener 'textInput', @onTextInput @scrollViewNode.addEventListener 'mousedown', @onMouseDown @scrollViewNode.addEventListener 'scroll', @onScrollViewScroll - window.addEventListener 'resize', @requestHeightAndWidthMeasurement @listenForIMEEvents() @trackSelectionClipboard() if process.platform is 'linux' @@ -589,15 +587,6 @@ class TextEditorComponent else @wasVisible = false - requestHeightAndWidthMeasurement: => - return if @heightAndWidthMeasurementRequested - - @heightAndWidthMeasurementRequested = true - requestAnimationFrame => - @heightAndWidthMeasurementRequested = false - @measureDimensions() - @measureWindowSize() - # Measure explicitly-styled height and width and relay them to the model. If # these values aren't explicitly styled, we assume the editor is unconstrained # and use the scrollHeight / scrollWidth as its height and width in From b2fb7e6e7a9de1ea68004aa5d9239b2204d2c88d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Jul 2015 14:03:12 -0600 Subject: [PATCH 10/14] Remove unused prototype properties --- src/view-registry.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/view-registry.coffee b/src/view-registry.coffee index 4c98bb153..20c88394e 100644 --- a/src/view-registry.coffee +++ b/src/view-registry.coffee @@ -42,11 +42,9 @@ Grim = require 'grim' # ``` module.exports = class ViewRegistry - documentPollingInterval: 200 documentUpdateRequested: false documentReadInProgress: false performDocumentPollAfterUpdate: false - pollIntervalHandle: null constructor: -> @views = new WeakMap From 2869d66de0ba7ee28855fd05654b34b765022ac8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Jul 2015 14:04:30 -0600 Subject: [PATCH 11/14] Trigger polling in spec via window resize instead of advancing clock --- spec/view-registry-spec.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index 10ad0f7eb..2077b5d9b 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -1,7 +1,7 @@ ViewRegistry = require '../src/view-registry' {View} = require '../src/space-pen-extensions' -describe "ViewRegistry", -> +fdescribe "ViewRegistry", -> registry = null beforeEach -> @@ -161,13 +161,13 @@ describe "ViewRegistry", -> registry.updateDocument -> events.push('write') registry.readDocument -> events.push('read') - advanceClock(registry.documentPollingInterval) + window.dispatchEvent(new UIEvent('resize')) expect(events).toEqual [] frameRequests[0]() expect(events).toEqual ['write', 'read', 'poll'] - advanceClock(registry.documentPollingInterval) + window.dispatchEvent(new UIEvent('resize')) expect(events).toEqual ['write', 'read', 'poll', 'poll'] it "polls the document after updating when ::pollAfterNextUpdate() has been called", -> From fb9d15e03e4e763ffd3bcd35c264dbdacc30aede Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 22 Jul 2015 16:03:39 -0600 Subject: [PATCH 12/14] Throttle document polling --- src/view-registry.coffee | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/view-registry.coffee b/src/view-registry.coffee index 20c88394e..58b2bf7c0 100644 --- a/src/view-registry.coffee +++ b/src/view-registry.coffee @@ -1,6 +1,7 @@ {find} = require 'underscore-plus' Grim = require 'grim' {Disposable} = require 'event-kit' +_ = require 'underscore-plus' # Essential: `ViewRegistry` handles the association between model and view # types in Atom. We call this association a View Provider. As in, for a given @@ -45,6 +46,8 @@ class ViewRegistry documentUpdateRequested: false documentReadInProgress: false performDocumentPollAfterUpdate: false + debouncedPerformDocumentPoll: null + minimumPollInterval: 200 constructor: -> @views = new WeakMap @@ -53,7 +56,8 @@ class ViewRegistry @documentReaders = [] @documentPollers = [] - @observer = new MutationObserver(@performDocumentPoll) + @observer = new MutationObserver(@requestDocumentPoll) + @debouncedPerformDocumentPoll = _.throttle(@performDocumentPoll, @minimumPollInterval).bind(this) # Essential: Add a provider that will be used to construct views in the # workspace's view layer based on model objects in its model layer. @@ -208,16 +212,19 @@ class ViewRegistry writer() while writer = @documentWriters.shift() startPollingDocument: -> - window.addEventListener('resize', @performDocumentPoll) + window.addEventListener('resize', @requestDocumentPoll) @observer.observe(document, {subtree: true, childList: true, attributes: true}) stopPollingDocument: -> - window.removeEventListener('resize', @performDocumentPoll) + window.removeEventListener('resize', @requestDocumentPoll) @observer.disconnect() - performDocumentPoll: => + requestDocumentPoll: => if @documentUpdateRequested @performDocumentPollAfterUpdate = true else - poller() for poller in @documentPollers - return + @debouncedPerformDocumentPoll() + + performDocumentPoll: -> + poller() for poller in @documentPollers + return From 92f1a800e20c59ce6e4da351dd7c3ab93c1f63fe Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 23 Jul 2015 12:03:11 -0600 Subject: [PATCH 13/14] Unfocus spec --- spec/view-registry-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index 2077b5d9b..61952e63a 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -1,7 +1,7 @@ ViewRegistry = require '../src/view-registry' {View} = require '../src/space-pen-extensions' -fdescribe "ViewRegistry", -> +describe "ViewRegistry", -> registry = null beforeEach -> From c18db48f54c466acee8aa843e4d33c9f11128dbe Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 23 Jul 2015 12:03:20 -0600 Subject: [PATCH 14/14] Fix specs --- spec/text-editor-component-spec.coffee | 15 ++++++++++----- spec/view-registry-spec.coffee | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 826affb42..74cdfd7b2 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -280,6 +280,7 @@ describe "TextEditorComponent", -> expect(tileNode.style.backgroundColor).toBe(backgroundColor) wrapperNode.style.backgroundColor = 'rgb(255, 0, 0)' + atom.views.performDocumentPoll() advanceClock(atom.views.documentPollingInterval) nextAnimationFrame() @@ -701,7 +702,8 @@ describe "TextEditorComponent", -> # favor gutter color if it's assigned gutterNode.style.backgroundColor = 'rgb(255, 0, 0)' - advanceClock(atom.views.documentPollingInterval) + atom.views.performDocumentPoll() + nextAnimationFrame() expect(lineNumbersNode.style.backgroundColor).toBe 'rgb(255, 0, 0)' for tileNode in lineNumbersNode.querySelectorAll(".tile") @@ -800,6 +802,7 @@ describe "TextEditorComponent", -> describe "when the component is destroyed", -> it "stops listening for folding events", -> + nextAnimationFrame() component.destroy() lineNumber = component.lineNumberNodeForScreenRow(1) @@ -824,6 +827,8 @@ describe "TextEditorComponent", -> expect(lineNumberHasClass(1, 'folded')).toBe false it "does not fold when the line number componentNode is clicked", -> + nextAnimationFrame() # clear pending frame request + lineNumber = component.lineNumberNodeForScreenRow(1) lineNumber.dispatchEvent(buildClickEvent(lineNumber)) expect(nextAnimationFrame).toBe noAnimationFrame @@ -2600,7 +2605,7 @@ describe "TextEditorComponent", -> expect(componentNode.querySelectorAll('.line').length).toBe 0 hiddenParent.style.display = 'block' - advanceClock(atom.views.documentPollingInterval) + atom.views.performDocumentPoll() expect(componentNode.querySelectorAll('.line').length).toBeGreaterThan 0 @@ -2710,13 +2715,13 @@ describe "TextEditorComponent", -> expect(parseInt(newHeight)).toBeLessThan wrapperNode.offsetHeight wrapperNode.style.height = newHeight - advanceClock(atom.views.documentPollingInterval) + atom.views.performDocumentPoll() nextAnimationFrame() expect(componentNode.querySelectorAll('.line')).toHaveLength(6) gutterWidth = componentNode.querySelector('.gutter').offsetWidth componentNode.style.width = gutterWidth + 14 * charWidth + editor.getVerticalScrollbarWidth() + 'px' - advanceClock(atom.views.documentPollingInterval) + atom.views.performDocumentPoll() nextAnimationFrame() expect(componentNode.querySelector('.line').textContent).toBe "var quicksort " @@ -2725,7 +2730,7 @@ describe "TextEditorComponent", -> scrollViewNode.style.paddingLeft = 20 + 'px' componentNode.style.width = 30 * charWidth + 'px' - advanceClock(atom.views.documentPollingInterval) + atom.views.performDocumentPoll() nextAnimationFrame() expect(component.lineNodeForScreenRow(0).textContent).toBe "var quicksort = " diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee index 61952e63a..a12d46dde 100644 --- a/spec/view-registry-spec.coffee +++ b/spec/view-registry-spec.coffee @@ -201,9 +201,10 @@ describe "ViewRegistry", -> disposable2 = registry.pollDocument -> events.push('poll 2') it "calls all registered polling functions after document or stylesheet changes until they are disabled via a returned disposable", -> + jasmine.useRealClock() expect(events).toEqual [] - testElement.style.height = '400px' + testElement.style.width = '400px' waitsFor "events to occur in response to DOM mutation", -> events.length > 0 @@ -213,7 +214,7 @@ describe "ViewRegistry", -> testStyleSheet.textContent = 'body {color: #333;}' - waitsFor "events to occur in reponse to style mutation", -> events.length > 0 + waitsFor "events to occur in reponse to style sheet mutation", -> events.length > 0 runs -> expect(events).toEqual ['poll 1', 'poll 2']