From afc42459717e5176f212786678ca78a6daaaba47 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 22 Nov 2017 15:30:28 -0800 Subject: [PATCH] Make TokenizedBuffer behave consistently when tokenizeInBackground is mocked --- spec/spec-helper.coffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 7efad7dd4..f39c9a42f 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -7,6 +7,7 @@ fs = require 'fs-plus' Grim = require 'grim' pathwatcher = require 'pathwatcher' FindParentDir = require 'find-parent-dir' +{CompositeDisposable} = require 'event-kit' TextEditor = require '../src/text-editor' TextEditorElement = require '../src/text-editor-element' @@ -102,6 +103,18 @@ beforeEach -> TokenizedBuffer.prototype.chunkSize = Infinity spyOn(TokenizedBuffer.prototype, "tokenizeInBackground").andCallFake -> @tokenizeNextChunk() + # Without this spy, TextEditor.onDidTokenize callbacks would not be called + # after the buffer's language mode changed, because by the time the editor + # called its new language mode's onDidTokenize method, the language mode + # would already be fully tokenized. + spyOn(TextEditor.prototype, "onDidTokenize").andCallFake (callback) -> + new CompositeDisposable( + @emitter.on("did-tokenize", callback), + @onDidChangeGrammar => + if @buffer.getLanguageMode().tokenizeInBackground.originalValue + callback() + ) + clipboardContent = 'initial clipboard content' spyOn(clipboard, 'writeText').andCallFake (text) -> clipboardContent = text spyOn(clipboard, 'readText').andCallFake -> clipboardContent