From 17f4d6f0645871a8fb59ca4f6efda5f45e4b9874 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 7 Mar 2013 14:25:14 -0800 Subject: [PATCH] EditSession reloads its grammar on the 'grammars-loaded' event --- spec/app/edit-session-spec.coffee | 13 +++++++++++++ src/app/edit-session.coffee | 2 ++ 2 files changed, 15 insertions(+) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 1a4d3754d..023700307 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -2033,6 +2033,19 @@ describe "EditSession", -> editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] + describe "when the 'grammars-loaded' event is triggered on the syntax global", -> + it "reloads the edit session's grammar and re-tokenizes the buffer if it changes", -> + editSession.destroy() + grammarToReturn = syntax.grammarByFileTypeSuffix('txt') + spyOn(syntax, 'grammarForFilePath').andCallFake -> grammarToReturn + + editSession = project.buildEditSession('sample.js', autoIndent: false) + expect(editSession.lineForScreenRow(0).tokens).toHaveLength 1 + + grammarToReturn = syntax.grammarByFileTypeSuffix('js') + syntax.trigger 'grammars-loaded' + expect(editSession.lineForScreenRow(0).tokens.length).toBeGreaterThan 1 + describe "auto-indent", -> describe "editor.autoIndent", -> it "auto-indents newlines if editor.autoIndent is true", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 0d48a1f4e..6b5964ca1 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -61,6 +61,8 @@ class EditSession @subscribe @displayBuffer, "changed", (e) => @trigger 'screen-lines-changed', e + @subscribe syntax, 'grammars-loaded', => @reloadGrammar() + getViewClass: -> require 'editor'