2012-08-28 02:36:36 +04:00
|
|
|
|
$ = require 'jquery'
|
|
|
|
|
fs = require 'fs'
|
2013-02-20 00:12:29 +04:00
|
|
|
|
Project = require 'project'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
RootView = require 'root-view'
|
|
|
|
|
Buffer = require 'buffer'
|
|
|
|
|
Editor = require 'editor'
|
2012-09-26 03:38:48 +04:00
|
|
|
|
{View, $$} = require 'space-pen'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "RootView", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
pathToOpen = null
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
beforeEach ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
project.setPath(project.resolve('dir'))
|
2013-02-20 00:12:29 +04:00
|
|
|
|
pathToOpen = project.resolve('a')
|
2013-02-20 04:18:25 +04:00
|
|
|
|
window.rootView = new RootView
|
2012-08-28 02:36:36 +04:00
|
|
|
|
rootView.enableKeymap()
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.open(pathToOpen)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
rootView.focus()
|
|
|
|
|
|
2013-02-21 03:43:29 +04:00
|
|
|
|
xdescribe "@deserialize()", ->
|
2013-01-18 04:30:09 +04:00
|
|
|
|
viewState = null
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
|
describe "when the serialized RootView has an unsaved buffer", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
it "constructs the view with the same panes", ->
|
2013-01-18 04:30:09 +04:00
|
|
|
|
rootView.open()
|
|
|
|
|
editor1 = rootView.getActiveEditor()
|
|
|
|
|
buffer = editor1.getBuffer()
|
|
|
|
|
editor1.splitRight()
|
2013-02-21 03:43:29 +04:00
|
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
|
viewState = rootView.serialize()
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.deactivate()
|
|
|
|
|
window.rootView = RootView.deserialize(viewState)
|
2013-02-21 03:43:29 +04:00
|
|
|
|
|
2013-02-20 00:12:29 +04:00
|
|
|
|
rootView.focus()
|
2013-01-18 04:30:09 +04:00
|
|
|
|
expect(rootView.getEditors().length).toBe 2
|
|
|
|
|
expect(rootView.getActiveEditor().getText()).toBe buffer.getText()
|
2013-02-20 00:12:29 +04:00
|
|
|
|
expect(rootView.getTitle()).toBe "untitled – #{project.getPath()}"
|
2013-01-18 04:30:09 +04:00
|
|
|
|
|
|
|
|
|
describe "when the serialized RootView has a project", ->
|
|
|
|
|
describe "when there are open editors", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
it "constructs the view with the same panes", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
|
editor1 = rootView.getActiveEditor()
|
2013-01-18 04:30:09 +04:00
|
|
|
|
editor2 = editor1.splitRight()
|
|
|
|
|
editor3 = editor2.splitRight()
|
|
|
|
|
editor4 = editor2.splitDown()
|
2013-02-17 02:00:29 +04:00
|
|
|
|
editor2.edit(project.buildEditSession('b'))
|
|
|
|
|
editor3.edit(project.buildEditSession('../sample.js'))
|
2013-01-18 04:30:09 +04:00
|
|
|
|
editor3.setCursorScreenPosition([2, 4])
|
2013-02-17 02:00:29 +04:00
|
|
|
|
editor4.edit(project.buildEditSession('../sample.txt'))
|
2013-01-18 04:30:09 +04:00
|
|
|
|
editor4.setCursorScreenPosition([0, 2])
|
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
editor2.focus()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
|
viewState = rootView.serialize()
|
|
|
|
|
rootView.deactivate()
|
|
|
|
|
window.rootView = RootView.deserialize(viewState)
|
2013-01-18 04:30:09 +04:00
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
|
|
expect(rootView.getEditors().length).toBe 4
|
|
|
|
|
editor1 = rootView.panes.find('.row > .pane .editor:eq(0)').view()
|
|
|
|
|
editor3 = rootView.panes.find('.row > .pane .editor:eq(1)').view()
|
|
|
|
|
editor2 = rootView.panes.find('.row > .column > .pane .editor:eq(0)').view()
|
|
|
|
|
editor4 = rootView.panes.find('.row > .column > .pane .editor:eq(1)').view()
|
|
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
|
expect(editor1.getPath()).toBe project.resolve('a')
|
|
|
|
|
expect(editor2.getPath()).toBe project.resolve('b')
|
|
|
|
|
expect(editor3.getPath()).toBe project.resolve('../sample.js')
|
2013-01-18 04:30:09 +04:00
|
|
|
|
expect(editor3.getCursorScreenPosition()).toEqual [2, 4]
|
2013-02-20 04:18:25 +04:00
|
|
|
|
expect(editor4.getPath()).toBe project.resolve('../sample.txt')
|
2013-01-18 04:30:09 +04:00
|
|
|
|
expect(editor4.getCursorScreenPosition()).toEqual [0, 2]
|
|
|
|
|
|
|
|
|
|
# ensure adjust pane dimensions is called
|
|
|
|
|
expect(editor1.width()).toBeGreaterThan 0
|
|
|
|
|
expect(editor2.width()).toBeGreaterThan 0
|
|
|
|
|
expect(editor3.width()).toBeGreaterThan 0
|
|
|
|
|
expect(editor4.width()).toBeGreaterThan 0
|
|
|
|
|
|
|
|
|
|
# ensure correct editor is focused again
|
|
|
|
|
expect(editor2.isFocused).toBeTruthy()
|
|
|
|
|
expect(editor1.isFocused).toBeFalsy()
|
|
|
|
|
expect(editor3.isFocused).toBeFalsy()
|
|
|
|
|
expect(editor4.isFocused).toBeFalsy()
|
|
|
|
|
|
2013-02-20 02:15:11 +04:00
|
|
|
|
expect(rootView.getTitle()).toBe "#{fs.base(editor2.getPath())} – #{project.getPath()}"
|
2013-01-18 04:30:09 +04:00
|
|
|
|
|
|
|
|
|
describe "where there are no open editors", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
it "constructs the view with no open editors", ->
|
|
|
|
|
rootView.getActiveEditor().remove()
|
2013-02-20 00:12:29 +04:00
|
|
|
|
expect(rootView.getEditors().length).toBe 0
|
2013-02-20 04:18:25 +04:00
|
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
|
viewState = rootView.serialize()
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.deactivate()
|
|
|
|
|
window.rootView = RootView.deserialize(viewState)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-02-20 00:12:29 +04:00
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
expect(rootView.getEditors().length).toBe 0
|
2013-01-11 04:24:36 +04:00
|
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
|
describe "when a pane's wrapped view cannot be deserialized", ->
|
2013-01-18 05:25:12 +04:00
|
|
|
|
it "renders an empty pane", ->
|
2013-01-18 04:30:09 +04:00
|
|
|
|
viewState =
|
|
|
|
|
panesViewState:
|
2013-02-19 06:04:14 +04:00
|
|
|
|
deserializer: "Pane",
|
2013-01-18 04:30:09 +04:00
|
|
|
|
wrappedView:
|
2013-02-19 06:04:14 +04:00
|
|
|
|
deserializer: "BogusView"
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.deactivate()
|
|
|
|
|
window.rootView = RootView.deserialize(viewState)
|
2013-01-18 04:30:09 +04:00
|
|
|
|
expect(rootView.find('.pane').length).toBe 1
|
|
|
|
|
expect(rootView.find('.pane').children().length).toBe 0
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "focus", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
|
describe "when there is an active view", ->
|
|
|
|
|
it "hands off focus to the active view", ->
|
|
|
|
|
editor = rootView.getActiveView()
|
|
|
|
|
editor.isFocused = false
|
2012-09-26 01:11:07 +04:00
|
|
|
|
rootView.focus()
|
2013-02-22 05:32:03 +04:00
|
|
|
|
expect(editor.isFocused).toBeTruthy()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-02-22 05:32:03 +04:00
|
|
|
|
describe "when there is no active view", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
|
beforeEach ->
|
2013-02-22 05:32:03 +04:00
|
|
|
|
rootView.getActivePane().remove()
|
|
|
|
|
expect(rootView.getActiveView()).toBeUndefined()
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.attachToDom()
|
2013-02-22 05:32:03 +04:00
|
|
|
|
expect(document.activeElement).toBe document.body
|
2013-02-20 04:18:25 +04:00
|
|
|
|
|
2012-09-26 03:38:48 +04:00
|
|
|
|
describe "when are visible focusable elements (with a -1 tabindex)", ->
|
|
|
|
|
it "passes focus to the first focusable element", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
|
focusable1 = $$ -> @div "One", id: 'one', tabindex: -1
|
|
|
|
|
focusable2 = $$ -> @div "Two", id: 'two', tabindex: -1
|
|
|
|
|
rootView.horizontal.append(focusable1, focusable2)
|
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-09-26 03:38:48 +04:00
|
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
|
rootView.focus()
|
2013-02-22 05:32:03 +04:00
|
|
|
|
expect(document.activeElement).toBe focusable1[0]
|
2012-09-26 00:22:06 +04:00
|
|
|
|
|
2012-09-26 01:11:07 +04:00
|
|
|
|
describe "when there are no visible focusable elements", ->
|
2013-02-09 02:56:55 +04:00
|
|
|
|
it "surrenders focus to the body", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
|
focusable = $$ -> @div "One", id: 'one', tabindex: -1
|
|
|
|
|
rootView.horizontal.append(focusable)
|
|
|
|
|
focusable.hide()
|
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-09-26 00:22:06 +04:00
|
|
|
|
|
2013-02-22 05:32:03 +04:00
|
|
|
|
rootView.focus()
|
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "keymap wiring", ->
|
|
|
|
|
commandHandler = null
|
|
|
|
|
beforeEach ->
|
|
|
|
|
commandHandler = jasmine.createSpy('commandHandler')
|
|
|
|
|
rootView.on('foo-command', commandHandler)
|
|
|
|
|
|
|
|
|
|
window.keymap.bindKeys('*', 'x': 'foo-command')
|
|
|
|
|
|
2013-02-22 05:22:55 +04:00
|
|
|
|
describe "when a keydown event is triggered on the RootView", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
|
it "triggers matching keybindings for that event", ->
|
|
|
|
|
event = keydownEvent 'x', target: rootView[0]
|
|
|
|
|
|
|
|
|
|
rootView.trigger(event)
|
|
|
|
|
expect(commandHandler).toHaveBeenCalled()
|
|
|
|
|
|
2013-02-22 05:22:55 +04:00
|
|
|
|
describe "title", ->
|
|
|
|
|
describe "when the project has no path", ->
|
|
|
|
|
it "sets the title to 'untitled'", ->
|
|
|
|
|
project.setPath(undefined)
|
|
|
|
|
expect(rootView.title).toBe 'untitled'
|
|
|
|
|
|
|
|
|
|
describe "when the project has a path", ->
|
|
|
|
|
describe "when there is no active pane item", ->
|
|
|
|
|
it "sets the title to the project's path", ->
|
|
|
|
|
rootView.getActivePane().remove()
|
|
|
|
|
expect(rootView.getActivePaneItem()).toBeUndefined()
|
|
|
|
|
expect(rootView.title).toBe project.getPath()
|
|
|
|
|
|
|
|
|
|
describe "when there is an active pane item", ->
|
|
|
|
|
it "sets the title to the pane item's title plus the project path", ->
|
|
|
|
|
item = rootView.getActivePaneItem()
|
|
|
|
|
expect(rootView.title).toBe "#{item.getTitle()} - #{project.getPath()}"
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "font size adjustment", ->
|
|
|
|
|
it "increases/decreases font size when increase/decrease-font-size events are triggered", ->
|
2013-02-22 05:30:25 +04:00
|
|
|
|
fontSizeBefore = config.get('editor.fontSize')
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger 'window:increase-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 1
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger 'window:increase-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 2
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 1
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
it "does not allow the font size to be less than 1", ->
|
2012-12-18 05:52:20 +04:00
|
|
|
|
config.set("editor.fontSize", 1)
|
2012-12-13 03:23:36 +04:00
|
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
|
expect(config.get('editor.fontSize')).toBe 1
|
2012-09-20 20:31:04 +04:00
|
|
|
|
|
2013-02-21 03:43:29 +04:00
|
|
|
|
describe ".open(path, options)", ->
|
2013-02-19 04:28:29 +04:00
|
|
|
|
describe "when there is no active pane", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
|
beforeEach ->
|
2013-02-19 04:28:29 +04:00
|
|
|
|
rootView.getActivePane().remove()
|
|
|
|
|
expect(rootView.getActivePane()).toBeUndefined()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "when called with no path", ->
|
|
|
|
|
it "opens / returns an edit session for an empty buffer in a new editor", ->
|
|
|
|
|
editSession = rootView.open()
|
2013-02-19 04:28:29 +04:00
|
|
|
|
expect(rootView.getActivePane().currentItem).toBe editSession
|
|
|
|
|
expect(editSession.getPath()).toBeUndefined()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "when called with a path", ->
|
|
|
|
|
it "opens a buffer with the given path in a new editor", ->
|
|
|
|
|
editSession = rootView.open('b')
|
2013-02-19 04:28:29 +04:00
|
|
|
|
expect(rootView.getActivePane().currentItem).toBe editSession
|
|
|
|
|
expect(editSession.getPath()).toBe require.resolve('fixtures/dir/b')
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
2013-02-19 04:28:29 +04:00
|
|
|
|
describe "when there is an active pane", ->
|
|
|
|
|
[activePane, initialItemCount] = []
|
2012-08-28 02:36:36 +04:00
|
|
|
|
beforeEach ->
|
2013-02-19 04:28:29 +04:00
|
|
|
|
activePane = rootView.getActivePane()
|
|
|
|
|
initialItemCount = activePane.getItems().length
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "when called with no path", ->
|
2013-02-19 04:28:29 +04:00
|
|
|
|
it "opens an edit session with an empty buffer in the active pane", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
|
editSession = rootView.open()
|
2013-02-19 04:28:29 +04:00
|
|
|
|
expect(activePane.getItems().length).toBe initialItemCount + 1
|
|
|
|
|
expect(activePane.currentItem).toBe editSession
|
|
|
|
|
expect(editSession.getPath()).toBeUndefined()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
|
|
describe "when called with a path", ->
|
2013-02-19 04:28:29 +04:00
|
|
|
|
describe "when the active pane already has an edit session item for the path being opened", ->
|
|
|
|
|
it "shows the existing edit session on the pane", ->
|
|
|
|
|
previousEditSession = activePane.currentItem
|
|
|
|
|
|
|
|
|
|
editSession = rootView.open('b')
|
|
|
|
|
expect(activePane.currentItem).toBe editSession
|
|
|
|
|
|
|
|
|
|
editSession = rootView.open('a')
|
|
|
|
|
expect(editSession).not.toBe previousEditSession
|
|
|
|
|
expect(activePane.currentItem).toBe editSession
|
|
|
|
|
|
|
|
|
|
describe "when the active pane does not have an edit session item for the path being opened", ->
|
|
|
|
|
it "creates a new edit session for the given path in the active editor", ->
|
|
|
|
|
editSession = rootView.open('b')
|
|
|
|
|
expect(activePane.items.length).toBe 2
|
|
|
|
|
expect(activePane.currentItem).toBe editSession
|
2012-09-20 03:53:24 +04:00
|
|
|
|
|
2012-09-20 04:07:51 +04:00
|
|
|
|
describe ".saveAll()", ->
|
2012-09-20 03:53:24 +04:00
|
|
|
|
it "saves all open editors", ->
|
2013-02-20 00:12:29 +04:00
|
|
|
|
project.setPath('/tmp')
|
2012-09-20 03:53:24 +04:00
|
|
|
|
file1 = '/tmp/atom-temp1.txt'
|
|
|
|
|
file2 = '/tmp/atom-temp2.txt'
|
|
|
|
|
fs.write(file1, "file1")
|
|
|
|
|
fs.write(file2, "file2")
|
2013-02-20 00:12:29 +04:00
|
|
|
|
rootView.open(file1)
|
2012-09-20 03:53:24 +04:00
|
|
|
|
|
2013-02-22 05:38:31 +04:00
|
|
|
|
editor1 = rootView.getActiveView()
|
2012-09-20 03:53:24 +04:00
|
|
|
|
buffer1 = editor1.activeEditSession.buffer
|
|
|
|
|
expect(buffer1.getText()).toBe("file1")
|
|
|
|
|
expect(buffer1.isModified()).toBe(false)
|
|
|
|
|
buffer1.setText('edited1')
|
|
|
|
|
expect(buffer1.isModified()).toBe(true)
|
|
|
|
|
|
|
|
|
|
editor2 = editor1.splitRight()
|
2013-02-17 02:00:29 +04:00
|
|
|
|
editor2.edit(project.buildEditSession('atom-temp2.txt'))
|
2012-09-20 03:53:24 +04:00
|
|
|
|
buffer2 = editor2.activeEditSession.buffer
|
|
|
|
|
expect(buffer2.getText()).toBe("file2")
|
|
|
|
|
expect(buffer2.isModified()).toBe(false)
|
|
|
|
|
buffer2.setText('edited2')
|
|
|
|
|
expect(buffer2.isModified()).toBe(true)
|
|
|
|
|
|
|
|
|
|
rootView.saveAll()
|
|
|
|
|
|
|
|
|
|
expect(buffer1.isModified()).toBe(false)
|
|
|
|
|
expect(fs.read(buffer1.getPath())).toBe("edited1")
|
|
|
|
|
expect(buffer2.isModified()).toBe(false)
|
|
|
|
|
expect(fs.read(buffer2.getPath())).toBe("edited2")
|
2012-10-19 01:44:21 +04:00
|
|
|
|
|
|
|
|
|
describe "window:toggle-invisibles event", ->
|
|
|
|
|
it "shows/hides invisibles in all open and future editors", ->
|
|
|
|
|
rootView.height(200)
|
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
rightEditor = rootView.getActiveEditor()
|
|
|
|
|
rightEditor.setText(" \t ")
|
|
|
|
|
leftEditor = rightEditor.splitLeft()
|
|
|
|
|
expect(rightEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
|
2012-12-21 03:42:38 +04:00
|
|
|
|
withInvisiblesShowing = "#{rightEditor.invisibles.space}#{rightEditor.invisibles.tab} #{rightEditor.invisibles.space}#{rightEditor.invisibles.eol}"
|
|
|
|
|
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger "window:toggle-invisibles"
|
2012-12-21 03:42:38 +04:00
|
|
|
|
expect(rightEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
2012-10-19 01:44:21 +04:00
|
|
|
|
|
|
|
|
|
lowerLeftEditor = leftEditor.splitDown()
|
2012-12-21 03:42:38 +04:00
|
|
|
|
expect(lowerLeftEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
2012-10-19 01:44:21 +04:00
|
|
|
|
|
2012-10-19 22:51:36 +04:00
|
|
|
|
rootView.trigger "window:toggle-invisibles"
|
2012-10-19 01:44:21 +04:00
|
|
|
|
expect(rightEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
|
|
|
|
|
lowerRightEditor = rightEditor.splitDown()
|
|
|
|
|
expect(lowerRightEditor.find(".line:first").text()).toBe " "
|
2013-01-10 01:18:10 +04:00
|
|
|
|
|
2012-10-11 05:43:56 +04:00
|
|
|
|
describe ".eachEditor(callback)", ->
|
2012-10-11 05:41:12 +04:00
|
|
|
|
beforeEach ->
|
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
|
|
it "invokes the callback for existing editor", ->
|
|
|
|
|
count = 0
|
|
|
|
|
callbackEditor = null
|
|
|
|
|
callback = (editor) ->
|
|
|
|
|
callbackEditor = editor
|
|
|
|
|
count++
|
|
|
|
|
rootView.eachEditor(callback)
|
|
|
|
|
expect(count).toBe 1
|
|
|
|
|
expect(callbackEditor).toBe rootView.getActiveEditor()
|
|
|
|
|
|
|
|
|
|
it "invokes the callback for new editor", ->
|
|
|
|
|
count = 0
|
|
|
|
|
callbackEditor = null
|
|
|
|
|
callback = (editor) ->
|
|
|
|
|
callbackEditor = editor
|
|
|
|
|
count++
|
|
|
|
|
|
|
|
|
|
rootView.eachEditor(callback)
|
|
|
|
|
count = 0
|
|
|
|
|
callbackEditor = null
|
|
|
|
|
rootView.getActiveEditor().splitRight()
|
|
|
|
|
expect(count).toBe 1
|
|
|
|
|
expect(callbackEditor).toBe rootView.getActiveEditor()
|
2012-10-12 20:16:46 +04:00
|
|
|
|
|
|
|
|
|
describe ".eachBuffer(callback)", ->
|
|
|
|
|
beforeEach ->
|
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
|
|
it "invokes the callback for existing buffer", ->
|
|
|
|
|
count = 0
|
|
|
|
|
callbackBuffer = null
|
|
|
|
|
callback = (buffer) ->
|
|
|
|
|
callbackBuffer = buffer
|
|
|
|
|
count++
|
|
|
|
|
rootView.eachBuffer(callback)
|
|
|
|
|
expect(count).toBe 1
|
|
|
|
|
expect(callbackBuffer).toBe rootView.getActiveEditor().getBuffer()
|
|
|
|
|
|
|
|
|
|
it "invokes the callback for new buffer", ->
|
|
|
|
|
count = 0
|
|
|
|
|
callbackBuffer = null
|
|
|
|
|
callback = (buffer) ->
|
|
|
|
|
callbackBuffer = buffer
|
|
|
|
|
count++
|
|
|
|
|
|
|
|
|
|
rootView.eachBuffer(callback)
|
|
|
|
|
count = 0
|
|
|
|
|
callbackBuffer = null
|
|
|
|
|
rootView.open(require.resolve('fixtures/sample.txt'))
|
|
|
|
|
expect(count).toBe 1
|
|
|
|
|
expect(callbackBuffer).toBe rootView.getActiveEditor().getBuffer()
|