mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Move grammar override logic into TextEditorRegistry
Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
committed by
Nathan Sobo
parent
455d3213ed
commit
a44d5833a8
@@ -85,6 +85,27 @@ describe('TextEditorRegistry', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('.setGrammarOverride and .clearGrammarOverride', function () {
|
||||
it('sets the editor\'s grammar and does not update it based on other criteria until the override is cleared', async function () {
|
||||
registry.maintainGrammar(editor)
|
||||
await atom.packages.activatePackage('language-c')
|
||||
expect(editor.getGrammar().name).toBe('Null Grammar')
|
||||
|
||||
registry.setGrammarOverride(editor, atom.grammars.grammarForScopeName('source.c'))
|
||||
expect(editor.getGrammar().name).toBe('C')
|
||||
|
||||
editor.getBuffer().setPath('file-1.js')
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
expect(editor.getGrammar().name).toBe('C')
|
||||
|
||||
editor.getBuffer().setPath('file-2.js')
|
||||
expect(editor.getGrammar().name).toBe('C')
|
||||
|
||||
registry.clearGrammarOverride(editor)
|
||||
expect(editor.getGrammar().name).toBe('JavaScript')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.maintainConfig(editor)', function () {
|
||||
it('does not update editors when config settings change for unrelated scope selectors', async function () {
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
|
||||
@@ -5225,24 +5225,8 @@ describe "TextEditor", ->
|
||||
editor.setIndentationForBufferRow(0, 2.1)
|
||||
expect(editor.getText()).toBe(" 1\n\t2")
|
||||
|
||||
describe ".reloadGrammar()", ->
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('language-coffee-script')
|
||||
|
||||
it "updates the grammar based on grammar overrides", ->
|
||||
expect(editor.getGrammar().name).toBe 'JavaScript'
|
||||
atom.grammars.setGrammarOverrideForPath(editor.getPath(), 'source.coffee')
|
||||
callback = jasmine.createSpy('callback')
|
||||
editor.onDidChangeGrammar(callback)
|
||||
editor.reloadGrammar()
|
||||
expect(editor.getGrammar().name).toBe 'CoffeeScript'
|
||||
expect(callback.callCount).toBe 1
|
||||
expect(callback.argsForCall[0][0]).toBe atom.grammars.grammarForScopeName('source.coffee')
|
||||
|
||||
describe "when the editor's grammar has an injection selector", ->
|
||||
beforeEach ->
|
||||
|
||||
waitsForPromise ->
|
||||
atom.packages.activatePackage('language-text')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user