2017-11-20 20:46:32 +03:00
|
|
|
const TextEditorRegistry = require('../src/text-editor-registry')
|
|
|
|
const TextEditor = require('../src/text-editor')
|
|
|
|
const TextBuffer = require('text-buffer')
|
2019-02-22 10:55:17 +03:00
|
|
|
const { Point, Range } = TextBuffer
|
2019-02-22 11:55:30 +03:00
|
|
|
const { it } = require('./async-spec-helpers')
|
2017-11-20 20:46:32 +03:00
|
|
|
const dedent = require('dedent')
|
2016-07-06 21:54:30 +03:00
|
|
|
|
|
|
|
describe('TextEditorRegistry', function () {
|
2016-08-16 01:29:27 +03:00
|
|
|
let registry, editor, initialPackageActivation
|
2016-07-06 21:54:30 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2016-08-16 01:29:27 +03:00
|
|
|
initialPackageActivation = Promise.resolve()
|
|
|
|
|
2016-07-09 03:41:59 +03:00
|
|
|
registry = new TextEditorRegistry({
|
2016-08-12 22:21:51 +03:00
|
|
|
assert: atom.assert,
|
2016-07-15 21:46:00 +03:00
|
|
|
config: atom.config,
|
2016-08-16 01:29:27 +03:00
|
|
|
grammarRegistry: atom.grammars,
|
2019-02-22 10:55:17 +03:00
|
|
|
packageManager: { deferredActivationHooks: null }
|
2016-07-09 03:41:59 +03:00
|
|
|
})
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
editor = new TextEditor({ autoHeight: false })
|
|
|
|
expect(
|
|
|
|
atom.grammars.assignLanguageMode(editor, 'text.plain.null-grammar')
|
|
|
|
).toBe(true)
|
2016-07-09 03:41:59 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
registry.destroy()
|
2016-07-06 21:54:30 +03:00
|
|
|
})
|
|
|
|
|
2016-07-06 21:58:07 +03:00
|
|
|
describe('.add', function () {
|
|
|
|
it('adds an editor to the list of registered editors', function () {
|
2016-07-06 21:54:30 +03:00
|
|
|
registry.add(editor)
|
|
|
|
expect(editor.registered).toBe(true)
|
|
|
|
expect(registry.editors.size).toBe(1)
|
|
|
|
expect(registry.editors.has(editor)).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns a Disposable that can unregister the editor', function () {
|
|
|
|
const disposable = registry.add(editor)
|
|
|
|
expect(registry.editors.size).toBe(1)
|
|
|
|
disposable.dispose()
|
|
|
|
expect(registry.editors.size).toBe(0)
|
|
|
|
expect(editor.registered).toBe(false)
|
2016-08-10 23:54:27 +03:00
|
|
|
expect(retainedEditorCount(registry)).toBe(0)
|
2016-07-06 21:54:30 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-07-06 21:58:07 +03:00
|
|
|
describe('.observe', function () {
|
2016-07-06 21:54:30 +03:00
|
|
|
it('calls the callback for current and future editors until unsubscribed', function () {
|
|
|
|
const spy = jasmine.createSpy()
|
|
|
|
const [editor1, editor2, editor3] = [{}, {}, {}]
|
|
|
|
registry.add(editor1)
|
|
|
|
const subscription = registry.observe(spy)
|
|
|
|
expect(spy.calls.length).toBe(1)
|
|
|
|
|
|
|
|
registry.add(editor2)
|
|
|
|
expect(spy.calls.length).toBe(2)
|
|
|
|
expect(spy.argsForCall[0][0]).toBe(editor1)
|
|
|
|
expect(spy.argsForCall[1][0]).toBe(editor2)
|
|
|
|
subscription.dispose()
|
|
|
|
|
|
|
|
registry.add(editor3)
|
|
|
|
expect(spy.calls.length).toBe(2)
|
|
|
|
})
|
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
|
2016-08-12 22:21:51 +03:00
|
|
|
describe('.build', function () {
|
|
|
|
it('constructs a TextEditor with the right parameters based on its path and text', async function () {
|
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
await atom.packages.activatePackage('language-c')
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('editor.tabLength', 8, { scope: '.source.js' })
|
2016-08-12 22:21:51 +03:00
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
const editor = registry.build({
|
|
|
|
buffer: new TextBuffer({ filePath: 'test.js' })
|
|
|
|
})
|
2016-08-12 22:21:51 +03:00
|
|
|
expect(editor.getTabLength()).toBe(8)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-07-09 03:41:59 +03:00
|
|
|
describe('.maintainConfig(editor)', function () {
|
2016-08-08 22:10:56 +03:00
|
|
|
it('does not update the editor when config settings change for unrelated scope selectors', async function () {
|
2016-07-11 23:50:38 +03:00
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
|
2016-10-07 19:21:09 +03:00
|
|
|
const editor2 = new TextEditor()
|
2016-07-11 23:50:38 +03:00
|
|
|
|
2017-11-28 22:14:29 +03:00
|
|
|
atom.grammars.assignLanguageMode(editor2, 'source.js')
|
2016-07-11 23:50:38 +03:00
|
|
|
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
registry.maintainConfig(editor2)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 23:50:38 +03:00
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(editor.getRootScopeDescriptor().getScopesArray()).toEqual([
|
|
|
|
'text.plain.null-grammar'
|
|
|
|
])
|
|
|
|
expect(editor2.getRootScopeDescriptor().getScopesArray()).toEqual([
|
|
|
|
'source.js'
|
|
|
|
])
|
2016-07-11 23:50:38 +03:00
|
|
|
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
expect(editor2.getEncoding()).toBe('utf8')
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16le', {
|
|
|
|
scopeSelector: '.text.plain.null-grammar'
|
|
|
|
})
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16be', {
|
|
|
|
scopeSelector: '.source.js'
|
|
|
|
})
|
2016-07-11 23:50:38 +03:00
|
|
|
|
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
expect(editor2.getEncoding()).toBe('utf16be')
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('does not update the editor before the initial packages have loaded', async function () {
|
|
|
|
let didActivateInitialPackagesCallback
|
|
|
|
|
|
|
|
registry = new TextEditorRegistry({
|
|
|
|
assert: atom.assert,
|
|
|
|
config: atom.config,
|
|
|
|
grammarRegistry: atom.grammars,
|
|
|
|
packageManager: {
|
|
|
|
deferredActivationHooks: [],
|
|
|
|
|
|
|
|
onDidActivateInitialPackages (callback) {
|
|
|
|
didActivateInitialPackagesCallback = callback
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16le')
|
|
|
|
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16be')
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
|
|
|
didActivateInitialPackagesCallback()
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getEncoding()).toBe('utf16be')
|
|
|
|
})
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
it("updates the editor's settings when its grammar changes", async function () {
|
2016-08-08 22:10:56 +03:00
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
|
2016-08-09 01:02:01 +03:00
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-08-08 22:10:56 +03:00
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16be', {
|
|
|
|
scopeSelector: '.source.js'
|
|
|
|
})
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16le', {
|
|
|
|
scopeSelector: '.source.js'
|
|
|
|
})
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
2017-11-28 22:14:29 +03:00
|
|
|
atom.grammars.assignLanguageMode(editor, 'source.js')
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16be', {
|
|
|
|
scopeSelector: '.source.js'
|
|
|
|
})
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf16be')
|
|
|
|
|
2017-11-28 22:14:29 +03:00
|
|
|
atom.grammars.assignLanguageMode(editor, 'text.plain.null-grammar')
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
2016-08-09 01:02:01 +03:00
|
|
|
})
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
it("preserves editor settings that haven't changed between previous and current language modes", async function () {
|
2018-01-12 00:35:06 +03:00
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
editor.setEncoding('utf16le')
|
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
|
|
|
|
expect(editor.isSoftWrapped()).toBe(false)
|
|
|
|
editor.setSoftWrapped(true)
|
|
|
|
expect(editor.isSoftWrapped()).toBe(true)
|
|
|
|
|
|
|
|
atom.grammars.assignLanguageMode(editor, 'source.js')
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
expect(editor.isSoftWrapped()).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updates editor settings that have changed between previous and current language modes', async function () {
|
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
2019-02-22 10:55:17 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16be', {
|
|
|
|
scopeSelector: '.text.plain.null-grammar'
|
|
|
|
})
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16le', {
|
|
|
|
scopeSelector: '.source.js'
|
|
|
|
})
|
2018-01-12 00:35:06 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf16be')
|
|
|
|
|
|
|
|
editor.setEncoding('utf8')
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
|
|
|
atom.grammars.assignLanguageMode(editor, 'source.js')
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
})
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
it("returns a disposable that can be used to stop the registry from updating the editor's config", async function () {
|
2016-08-09 01:02:01 +03:00
|
|
|
await atom.packages.activatePackage('language-javascript')
|
|
|
|
|
|
|
|
const previousSubscriptionCount = getSubscriptionCount(editor)
|
|
|
|
const disposable = registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(getSubscriptionCount(editor)).toBeGreaterThan(
|
|
|
|
previousSubscriptionCount
|
|
|
|
)
|
2016-08-09 01:02:01 +03:00
|
|
|
expect(registry.editorsWithMaintainedConfig.size).toBe(1)
|
|
|
|
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16be')
|
|
|
|
expect(editor.getEncoding()).toBe('utf16be')
|
|
|
|
atom.config.set('core.fileEncoding', 'utf8')
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
2016-08-08 22:10:56 +03:00
|
|
|
|
|
|
|
disposable.dispose()
|
|
|
|
|
2016-08-09 01:02:01 +03:00
|
|
|
atom.config.set('core.fileEncoding', 'utf16be')
|
2016-08-08 22:10:56 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
2016-08-09 01:02:01 +03:00
|
|
|
expect(getSubscriptionCount(editor)).toBe(previousSubscriptionCount)
|
2016-08-10 23:54:27 +03:00
|
|
|
expect(retainedEditorCount(registry)).toBe(0)
|
2016-08-08 22:10:56 +03:00
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the encoding based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ encoding: 'utf8' })
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
|
|
|
|
|
|
|
atom.config.set('core.fileEncoding', 'utf16le')
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getEncoding()).toBe('utf16le')
|
|
|
|
|
|
|
|
atom.config.set('core.fileEncoding', 'utf8')
|
|
|
|
expect(editor.getEncoding()).toBe('utf8')
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the tab length based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ tabLength: 4 })
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getTabLength()).toBe(4)
|
|
|
|
|
|
|
|
atom.config.set('editor.tabLength', 8)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getTabLength()).toBe(8)
|
|
|
|
|
|
|
|
atom.config.set('editor.tabLength', 4)
|
|
|
|
expect(editor.getTabLength()).toBe(4)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables soft tabs when the tabType config setting is "soft"', async function () {
|
2016-07-11 22:43:18 +03:00
|
|
|
atom.config.set('editor.tabType', 'soft')
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('disables soft tabs when the tabType config setting is "hard"', async function () {
|
2016-07-11 22:43:18 +03:00
|
|
|
atom.config.set('editor.tabType', 'hard')
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the "tabType" config setting is "auto"', function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
it("enables or disables soft tabs based on the editor's content", async function () {
|
2018-08-24 20:07:36 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 02:57:08 +03:00
|
|
|
await atom.packages.activatePackage('language-javascript')
|
2017-11-28 22:14:29 +03:00
|
|
|
atom.grammars.assignLanguageMode(editor, 'source.js')
|
2016-07-11 22:43:18 +03:00
|
|
|
atom.config.set('editor.tabType', 'auto')
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 02:57:08 +03:00
|
|
|
|
|
|
|
editor.setText(dedent`
|
|
|
|
{
|
|
|
|
hello;
|
|
|
|
}
|
|
|
|
`)
|
2018-08-21 23:02:27 +03:00
|
|
|
let disposable = registry.maintainConfig(editor)
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
|
2016-07-12 02:57:08 +03:00
|
|
|
editor.setText(dedent`
|
|
|
|
{
|
|
|
|
hello;
|
|
|
|
}
|
|
|
|
`)
|
2018-08-21 23:02:27 +03:00
|
|
|
disposable.dispose()
|
|
|
|
disposable = registry.maintainConfig(editor)
|
2016-07-12 02:57:08 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.setTextInBufferRange(
|
|
|
|
new Range(Point.ZERO, Point.ZERO),
|
|
|
|
dedent`
|
2016-07-12 02:57:08 +03:00
|
|
|
/*
|
|
|
|
* Comment with a leading space.
|
|
|
|
*/
|
2019-02-22 10:55:17 +03:00
|
|
|
` + '\n'
|
|
|
|
)
|
2018-08-21 23:02:27 +03:00
|
|
|
disposable.dispose()
|
|
|
|
disposable = registry.maintainConfig(editor)
|
2016-07-12 02:57:08 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
|
|
|
|
|
|
|
editor.setText(dedent`
|
|
|
|
/*
|
|
|
|
* Comment with a leading space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
|
|
|
hello;
|
|
|
|
}
|
|
|
|
`)
|
2018-08-21 23:02:27 +03:00
|
|
|
disposable.dispose()
|
|
|
|
disposable = registry.maintainConfig(editor)
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
2016-07-12 02:57:08 +03:00
|
|
|
|
|
|
|
editor.setText(dedent`
|
|
|
|
/*
|
|
|
|
* Comment with a leading space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
|
|
|
hello;
|
|
|
|
}
|
|
|
|
`)
|
2018-08-21 23:02:27 +03:00
|
|
|
disposable.dispose()
|
|
|
|
disposable = registry.maintainConfig(editor)
|
2016-07-12 02:57:08 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the "tabType" config setting is "auto"', function () {
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables soft tabs based on the "softTabs" config setting', async function () {
|
2016-07-11 22:43:18 +03:00
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 22:43:18 +03:00
|
|
|
|
|
|
|
editor.setText('abc\ndef')
|
|
|
|
atom.config.set('editor.softTabs', true)
|
|
|
|
atom.config.set('editor.tabType', 'auto')
|
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.softTabs', false)
|
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables soft tabs based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ softTabs: true })
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.tabType', 'hard')
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getSoftTabs()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.tabType', 'soft')
|
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.tabType', 'auto')
|
|
|
|
atom.config.set('editor.softTabs', true)
|
|
|
|
expect(editor.getSoftTabs()).toBe(true)
|
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables atomic soft tabs based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ atomicSoftTabs: true })
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.hasAtomicSoftTabs()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.atomicSoftTabs', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.hasAtomicSoftTabs()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.atomicSoftTabs', true)
|
|
|
|
expect(editor.hasAtomicSoftTabs()).toBe(true)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
|
2017-01-20 06:30:06 +03:00
|
|
|
it('enables or disables cursor on selection visibility based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ showCursorOnSelection: true })
|
2017-01-20 06:30:06 +03:00
|
|
|
expect(editor.getShowCursorOnSelection()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.showCursorOnSelection', false)
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getShowCursorOnSelection()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.showCursorOnSelection', true)
|
|
|
|
expect(editor.getShowCursorOnSelection()).toBe(true)
|
|
|
|
})
|
|
|
|
|
2016-08-30 23:20:17 +03:00
|
|
|
it('enables or disables line numbers based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ showLineNumbers: true })
|
2016-08-30 23:20:17 +03:00
|
|
|
expect(editor.showLineNumbers).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.showLineNumbers', false)
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.showLineNumbers).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.showLineNumbers', true)
|
|
|
|
expect(editor.showLineNumbers).toBe(true)
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the invisibles based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
const invisibles1 = { tab: 'a', cr: false, eol: false, space: false }
|
|
|
|
const invisibles2 = { tab: 'b', cr: false, eol: false, space: false }
|
2016-07-09 03:41:59 +03:00
|
|
|
|
2016-08-12 01:34:54 +03:00
|
|
|
editor.update({
|
|
|
|
showInvisibles: true,
|
|
|
|
invisibles: invisibles1
|
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getInvisibles()).toEqual(invisibles1)
|
|
|
|
|
2016-08-12 01:34:54 +03:00
|
|
|
atom.config.set('editor.showInvisibles', true)
|
2016-07-09 03:41:59 +03:00
|
|
|
atom.config.set('editor.invisibles', invisibles2)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:41:59 +03:00
|
|
|
expect(editor.getInvisibles()).toEqual(invisibles2)
|
|
|
|
|
|
|
|
atom.config.set('editor.invisibles', invisibles1)
|
|
|
|
expect(editor.getInvisibles()).toEqual(invisibles1)
|
2016-08-13 00:31:07 +03:00
|
|
|
|
|
|
|
atom.config.set('editor.showInvisibles', false)
|
|
|
|
expect(editor.getInvisibles()).toEqual({})
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
2016-07-09 03:54:24 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables the indent guide based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ showIndentGuide: true })
|
2016-07-09 03:54:24 +03:00
|
|
|
expect(editor.doesShowIndentGuide()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.showIndentGuide', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:54:24 +03:00
|
|
|
expect(editor.doesShowIndentGuide()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.showIndentGuide', true)
|
|
|
|
expect(editor.doesShowIndentGuide()).toBe(true)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
2016-07-09 03:54:24 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables soft wrap based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ softWrapped: true })
|
2016-07-09 03:54:24 +03:00
|
|
|
expect(editor.isSoftWrapped()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.softWrap', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-09 03:54:24 +03:00
|
|
|
expect(editor.isSoftWrapped()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.softWrap', true)
|
|
|
|
expect(editor.isSoftWrapped()).toBe(true)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the soft wrap indent length based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ softWrapHangingIndentLength: 4 })
|
2016-08-12 02:38:31 +03:00
|
|
|
expect(editor.getSoftWrapHangingIndentLength()).toBe(4)
|
2016-07-11 22:43:18 +03:00
|
|
|
|
|
|
|
atom.config.set('editor.softWrapHangingIndent', 2)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-08-12 02:38:31 +03:00
|
|
|
expect(editor.getSoftWrapHangingIndentLength()).toBe(2)
|
2016-07-11 22:43:18 +03:00
|
|
|
|
|
|
|
atom.config.set('editor.softWrapHangingIndent', 4)
|
2016-08-12 02:38:31 +03:00
|
|
|
expect(editor.getSoftWrapHangingIndentLength()).toBe(4)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables preferred line length-based soft wrap based on the config', async function () {
|
2016-08-13 00:31:07 +03:00
|
|
|
editor.update({
|
|
|
|
softWrapped: true,
|
|
|
|
preferredLineLength: 80,
|
|
|
|
editorWidthInChars: 120,
|
2019-02-22 10:55:17 +03:00
|
|
|
softWrapAtPreferredLineLength: true
|
2016-08-13 00:31:07 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(editor.getSoftWrapColumn()).toBe(80)
|
2016-07-11 22:43:18 +03:00
|
|
|
|
2016-08-13 00:31:07 +03:00
|
|
|
atom.config.set('editor.softWrap', true)
|
2016-07-11 22:43:18 +03:00
|
|
|
atom.config.set('editor.softWrapAtPreferredLineLength', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-08-13 00:31:07 +03:00
|
|
|
expect(editor.getSoftWrapColumn()).toBe(120)
|
2016-07-11 22:43:18 +03:00
|
|
|
|
|
|
|
atom.config.set('editor.softWrapAtPreferredLineLength', true)
|
2016-08-13 00:31:07 +03:00
|
|
|
expect(editor.getSoftWrapColumn()).toBe(80)
|
2016-07-11 22:43:18 +03:00
|
|
|
})
|
|
|
|
|
2017-09-12 05:38:29 +03:00
|
|
|
it('allows for custom definition of maximum soft wrap based on config', async function () {
|
|
|
|
editor.update({
|
|
|
|
softWrapped: false,
|
2019-02-22 10:55:17 +03:00
|
|
|
maxScreenLineLength: 1500
|
2017-09-12 05:38:29 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(editor.getSoftWrapColumn()).toBe(1500)
|
|
|
|
|
|
|
|
atom.config.set('editor.softWrap', false)
|
|
|
|
atom.config.set('editor.maxScreenLineLength', 500)
|
|
|
|
registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
expect(editor.getSoftWrapColumn()).toBe(500)
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the preferred line length based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ preferredLineLength: 80 })
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getPreferredLineLength()).toBe(80)
|
|
|
|
|
|
|
|
atom.config.set('editor.preferredLineLength', 110)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-11 22:43:18 +03:00
|
|
|
expect(editor.getPreferredLineLength()).toBe(110)
|
|
|
|
|
|
|
|
atom.config.set('editor.preferredLineLength', 80)
|
|
|
|
expect(editor.getPreferredLineLength()).toBe(80)
|
|
|
|
})
|
2016-07-12 03:16:41 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables auto-indent based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ autoIndent: true })
|
2016-07-12 03:37:51 +03:00
|
|
|
expect(editor.shouldAutoIndent()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.autoIndent', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 03:37:51 +03:00
|
|
|
expect(editor.shouldAutoIndent()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.autoIndent', true)
|
|
|
|
expect(editor.shouldAutoIndent()).toBe(true)
|
|
|
|
})
|
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables auto-indent-on-paste based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ autoIndentOnPaste: true })
|
2016-07-12 03:37:51 +03:00
|
|
|
expect(editor.shouldAutoIndentOnPaste()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.autoIndentOnPaste', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 03:37:51 +03:00
|
|
|
expect(editor.shouldAutoIndentOnPaste()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.autoIndentOnPaste', true)
|
|
|
|
expect(editor.shouldAutoIndentOnPaste()).toBe(true)
|
|
|
|
})
|
2016-07-12 03:41:06 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('enables or disables scrolling past the end of the buffer based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ scrollPastEnd: true })
|
2016-07-12 03:41:06 +03:00
|
|
|
expect(editor.getScrollPastEnd()).toBe(true)
|
|
|
|
|
|
|
|
atom.config.set('editor.scrollPastEnd', false)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 03:41:06 +03:00
|
|
|
expect(editor.getScrollPastEnd()).toBe(false)
|
|
|
|
|
|
|
|
atom.config.set('editor.scrollPastEnd', true)
|
|
|
|
expect(editor.getScrollPastEnd()).toBe(true)
|
|
|
|
})
|
2016-07-12 03:47:40 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the undo grouping interval based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ undoGroupingInterval: 300 })
|
2016-07-12 03:47:40 +03:00
|
|
|
expect(editor.getUndoGroupingInterval()).toBe(300)
|
|
|
|
|
|
|
|
atom.config.set('editor.undoGroupingInterval', 600)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-12 03:47:40 +03:00
|
|
|
expect(editor.getUndoGroupingInterval()).toBe(600)
|
|
|
|
|
|
|
|
atom.config.set('editor.undoGroupingInterval', 300)
|
|
|
|
expect(editor.getUndoGroupingInterval()).toBe(300)
|
|
|
|
})
|
2016-07-12 21:30:41 +03:00
|
|
|
|
2016-08-16 01:29:27 +03:00
|
|
|
it('sets the scroll sensitivity based on the config', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ scrollSensitivity: 50 })
|
2016-08-12 01:34:54 +03:00
|
|
|
expect(editor.getScrollSensitivity()).toBe(50)
|
|
|
|
|
2016-07-28 01:39:03 +03:00
|
|
|
atom.config.set('editor.scrollSensitivity', 60)
|
|
|
|
registry.maintainConfig(editor)
|
2016-08-16 01:29:27 +03:00
|
|
|
await initialPackageActivation
|
2016-07-28 01:39:03 +03:00
|
|
|
expect(editor.getScrollSensitivity()).toBe(60)
|
|
|
|
|
|
|
|
atom.config.set('editor.scrollSensitivity', 70)
|
|
|
|
expect(editor.getScrollSensitivity()).toBe(70)
|
|
|
|
})
|
|
|
|
|
2016-10-05 22:03:53 +03:00
|
|
|
describe('when called twice with a given editor', function () {
|
|
|
|
it('does nothing the second time', async function () {
|
2019-02-22 10:55:17 +03:00
|
|
|
editor.update({ scrollSensitivity: 50 })
|
2016-10-05 22:03:53 +03:00
|
|
|
|
|
|
|
const disposable1 = registry.maintainConfig(editor)
|
|
|
|
const disposable2 = registry.maintainConfig(editor)
|
|
|
|
await initialPackageActivation
|
|
|
|
|
|
|
|
atom.config.set('editor.scrollSensitivity', 60)
|
|
|
|
expect(editor.getScrollSensitivity()).toBe(60)
|
|
|
|
|
|
|
|
disposable2.dispose()
|
|
|
|
atom.config.set('editor.scrollSensitivity', 70)
|
|
|
|
expect(editor.getScrollSensitivity()).toBe(70)
|
|
|
|
|
|
|
|
disposable1.dispose()
|
|
|
|
atom.config.set('editor.scrollSensitivity', 80)
|
|
|
|
expect(editor.getScrollSensitivity()).toBe(70)
|
|
|
|
})
|
|
|
|
})
|
2016-07-09 03:41:59 +03:00
|
|
|
})
|
2016-07-06 21:54:30 +03:00
|
|
|
})
|
2016-08-09 01:02:01 +03:00
|
|
|
|
|
|
|
function getSubscriptionCount (editor) {
|
2019-02-22 10:55:17 +03:00
|
|
|
return (
|
|
|
|
editor.emitter.getTotalListenerCount() +
|
2016-08-09 01:02:01 +03:00
|
|
|
editor.tokenizedBuffer.emitter.getTotalListenerCount() +
|
|
|
|
editor.buffer.emitter.getTotalListenerCount() +
|
|
|
|
editor.displayLayer.emitter.getTotalListenerCount()
|
2019-02-22 10:55:17 +03:00
|
|
|
)
|
2016-08-09 01:02:01 +03:00
|
|
|
}
|
2016-08-10 23:54:27 +03:00
|
|
|
|
|
|
|
function retainedEditorCount (registry) {
|
|
|
|
const editors = new Set()
|
|
|
|
registry.editors.forEach(e => editors.add(e))
|
|
|
|
registry.editorsWithMaintainedConfig.forEach(e => editors.add(e))
|
|
|
|
registry.editorsWithMaintainedGrammar.forEach(e => editors.add(e))
|
|
|
|
return editors.size
|
|
|
|
}
|