mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Replace @buffer reference on Editor with @getBuffer method
This commit is contained in:
@@ -27,8 +27,8 @@ describe "Atom", ->
|
||||
runs ->
|
||||
expect(atom.windows.length).toBe previousWindowCount + 1
|
||||
newWindow = _.last(atom.windows)
|
||||
expect(newWindow.rootView.getActiveEditor().buffer.getPath()).toEqual filePath
|
||||
expect(newWindow.rootView.getActiveEditor().buffer.getText()).toEqual fs.read(filePath)
|
||||
expect(newWindow.rootView.getActiveEditor().getBuffer().getPath()).toEqual filePath
|
||||
expect(newWindow.rootView.getActiveEditor().getBuffer().getText()).toEqual fs.read(filePath)
|
||||
|
||||
describe ".windowOpened(window)", ->
|
||||
atom = null
|
||||
|
||||
@@ -24,10 +24,10 @@ describe "Editor", ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
project = rootView.project
|
||||
editor = rootView.getActiveEditor()
|
||||
buffer = editor.buffer
|
||||
buffer = editor.getBuffer()
|
||||
|
||||
editor.attachToDom = ({ heightInLines } = {}) ->
|
||||
heightInLines ?= this.buffer.getLineCount()
|
||||
heightInLines ?= this.getBuffer().getLineCount()
|
||||
this.height(getLineHeight() * heightInLines)
|
||||
$('#jasmine-content').append(this)
|
||||
|
||||
@@ -62,7 +62,7 @@ describe "Editor", ->
|
||||
expect(editor.serialize).toHaveBeenCalled()
|
||||
expect(Editor.deserialize).toHaveBeenCalled()
|
||||
|
||||
expect(newEditor.buffer).toBe editor.buffer
|
||||
expect(newEditor.getBuffer()).toBe editor.getBuffer()
|
||||
expect(newEditor.getCursorScreenPosition()).toEqual editor.getCursorScreenPosition()
|
||||
expect(newEditor.editSessions).toEqual(editor.editSessions)
|
||||
expect(newEditor.activeEditSession).toEqual(editor.activeEditSession)
|
||||
@@ -132,7 +132,7 @@ describe "Editor", ->
|
||||
editor.trigger "close"
|
||||
expect(editSession.destroy).toHaveBeenCalled()
|
||||
expect(editor.remove).not.toHaveBeenCalled()
|
||||
expect(editor.buffer).toBe buffer
|
||||
expect(editor.getBuffer()).toBe buffer
|
||||
|
||||
it "calls remove on the editor if there is one edit session and mini is false", ->
|
||||
editSession = editor.activeEditSession
|
||||
@@ -213,10 +213,10 @@ describe "Editor", ->
|
||||
expect(editor.scrollTop()).toBe 750
|
||||
|
||||
editor.setActiveEditSessionIndex(0)
|
||||
expect(editor.buffer).toBe session0.buffer
|
||||
expect(editor.getBuffer()).toBe session0.buffer
|
||||
|
||||
editor.setActiveEditSessionIndex(2)
|
||||
expect(editor.buffer).toBe session2.buffer
|
||||
expect(editor.getBuffer()).toBe session2.buffer
|
||||
expect(editor.getCursorScreenPosition()).toEqual [43, 1]
|
||||
expect(editor.verticalScrollbar.prop('scrollHeight')).toBe previousScrollHeight
|
||||
expect(editor.scrollTop()).toBe 750
|
||||
@@ -260,13 +260,13 @@ describe "Editor", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
project = rootView.project
|
||||
|
||||
expect(editor.buffer.getPath()).toBe tempFilePath
|
||||
expect(editor.getBuffer().getPath()).toBe tempFilePath
|
||||
|
||||
afterEach ->
|
||||
expect(fs.remove(tempFilePath))
|
||||
|
||||
it "saves the current buffer to disk", ->
|
||||
editor.buffer.setText 'Edited!'
|
||||
editor.getBuffer().setText 'Edited!'
|
||||
expect(fs.read(tempFilePath)).not.toBe "Edited!"
|
||||
|
||||
editor.save()
|
||||
@@ -279,8 +279,8 @@ describe "Editor", ->
|
||||
beforeEach ->
|
||||
editor.edit(rootView.project.open())
|
||||
|
||||
expect(editor.buffer.getPath()).toBeUndefined()
|
||||
editor.buffer.setText 'Save me to a new path'
|
||||
expect(editor.getBuffer().getPath()).toBeUndefined()
|
||||
editor.getBuffer().setText 'Save me to a new path'
|
||||
spyOn($native, 'saveDialog').andCallFake -> selectedFilePath
|
||||
|
||||
it "presents a 'save as' dialog", ->
|
||||
@@ -397,7 +397,7 @@ describe "Editor", ->
|
||||
it "emits event when buffer's path is changed", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on 'editor-path-change', eventHandler
|
||||
editor.buffer.saveAs(path)
|
||||
editor.getBuffer().saveAs(path)
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
it "emits event when editor receives a new buffer", ->
|
||||
@@ -408,7 +408,7 @@ describe "Editor", ->
|
||||
|
||||
it "stops listening to events on previously set buffers", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
oldBuffer = editor.buffer
|
||||
oldBuffer = editor.getBuffer()
|
||||
editor.on 'editor-path-change', eventHandler
|
||||
|
||||
editor.edit(rootView.project.open(path))
|
||||
@@ -419,7 +419,7 @@ describe "Editor", ->
|
||||
expect(eventHandler).not.toHaveBeenCalled()
|
||||
|
||||
eventHandler.reset()
|
||||
editor.buffer.saveAs("/tmp/atom-new.txt")
|
||||
editor.getBuffer().saveAs("/tmp/atom-new.txt")
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
describe "font size", ->
|
||||
@@ -1076,17 +1076,17 @@ describe "Editor", ->
|
||||
it "renders correctly when scrolling after text is added to the buffer", ->
|
||||
editor.insertText("1\n")
|
||||
_.times 4, -> editor.moveCursorDown()
|
||||
expect(editor.renderedLines.find('.line:eq(2)').text()).toBe editor.buffer.lineForRow(2)
|
||||
expect(editor.renderedLines.find('.line:eq(7)').text()).toBe editor.buffer.lineForRow(7)
|
||||
expect(editor.renderedLines.find('.line:eq(2)').text()).toBe editor.getBuffer().lineForRow(2)
|
||||
expect(editor.renderedLines.find('.line:eq(7)').text()).toBe editor.getBuffer().lineForRow(7)
|
||||
|
||||
it "renders correctly when scrolling after text is removed from buffer", ->
|
||||
editor.buffer.delete([[0,0],[1,0]])
|
||||
expect(editor.renderedLines.find('.line:eq(0)').text()).toBe editor.buffer.lineForRow(0)
|
||||
expect(editor.renderedLines.find('.line:eq(5)').text()).toBe editor.buffer.lineForRow(5)
|
||||
editor.getBuffer().delete([[0,0],[1,0]])
|
||||
expect(editor.renderedLines.find('.line:eq(0)').text()).toBe editor.getBuffer().lineForRow(0)
|
||||
expect(editor.renderedLines.find('.line:eq(5)').text()).toBe editor.getBuffer().lineForRow(5)
|
||||
|
||||
editor.scrollTop(3 * editor.lineHeight)
|
||||
expect(editor.renderedLines.find('.line:first').text()).toBe editor.buffer.lineForRow(1)
|
||||
expect(editor.renderedLines.find('.line:last').text()).toBe editor.buffer.lineForRow(10)
|
||||
expect(editor.renderedLines.find('.line:first').text()).toBe editor.getBuffer().lineForRow(1)
|
||||
expect(editor.renderedLines.find('.line:last').text()).toBe editor.getBuffer().lineForRow(10)
|
||||
|
||||
describe "when creating and destroying folds that are longer than the visible lines", ->
|
||||
describe "when the cursor precedes the fold when it is destroyed", ->
|
||||
|
||||
@@ -25,7 +25,7 @@ describe "RootView", ->
|
||||
expect(rootView.project.getPath()).toBe fs.directory(path)
|
||||
expect(rootView.getEditors().length).toBe 1
|
||||
expect(rootView.getEditors()[0]).toHaveClass 'active'
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe path
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe path
|
||||
expect(rootView.getActiveEditor().editSessions.length).toBe 1
|
||||
expect(document.title).toBe path
|
||||
|
||||
@@ -53,7 +53,7 @@ describe "RootView", ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
editor1 = rootView.getActiveEditor()
|
||||
buffer = editor1.buffer
|
||||
buffer = editor1.getBuffer()
|
||||
editor1.splitRight()
|
||||
viewState = rootView.serialize()
|
||||
|
||||
@@ -61,7 +61,7 @@ describe "RootView", ->
|
||||
rootView = RootView.deserialize(viewState)
|
||||
expect(rootView.project.getPath()?).toBeFalsy()
|
||||
expect(rootView.getEditors().length).toBe 2
|
||||
expect(rootView.getActiveEditor().buffer.getText()).toBe buffer.getText()
|
||||
expect(rootView.getActiveEditor().getBuffer().getText()).toBe buffer.getText()
|
||||
expect(document.title).toBe 'untitled'
|
||||
|
||||
describe "when the serialized RootView has a project", ->
|
||||
@@ -95,11 +95,11 @@ describe "RootView", ->
|
||||
editor2 = rootView.panes.find('.row > .column > .pane .editor:eq(0)').view()
|
||||
editor4 = rootView.panes.find('.row > .column > .pane .editor:eq(1)').view()
|
||||
|
||||
expect(editor1.buffer.getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
expect(editor2.buffer.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
expect(editor3.buffer.getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(editor1.getBuffer().getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
expect(editor2.getBuffer().getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
expect(editor3.getBuffer().getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(editor3.getCursorScreenPosition()).toEqual [2, 3]
|
||||
expect(editor4.buffer.getPath()).toBe require.resolve('fixtures/sample.txt')
|
||||
expect(editor4.getBuffer().getPath()).toBe require.resolve('fixtures/sample.txt')
|
||||
expect(editor4.getCursorScreenPosition()).toEqual [0, 2]
|
||||
|
||||
# ensure adjust pane dimensions is called
|
||||
@@ -114,7 +114,7 @@ describe "RootView", ->
|
||||
expect(editor3.isFocused).toBeFalsy()
|
||||
expect(editor4.isFocused).toBeFalsy()
|
||||
|
||||
expect(document.title).toBe editor2.buffer.getPath()
|
||||
expect(document.title).toBe editor2.getBuffer().getPath()
|
||||
|
||||
describe "when called with no pathToOpen", ->
|
||||
it "opens no buffer", ->
|
||||
@@ -460,7 +460,7 @@ describe "RootView", ->
|
||||
expect(document.title).toBe rootView.project.resolve(path)
|
||||
|
||||
pathChangeHandler.reset()
|
||||
editor1.buffer.saveAs("/tmp/should-not-be-title.txt")
|
||||
editor1.getBuffer().saveAs("/tmp/should-not-be-title.txt")
|
||||
expect(pathChangeHandler).not.toHaveBeenCalled()
|
||||
expect(document.title).toBe rootView.project.resolve(path)
|
||||
|
||||
@@ -469,7 +469,7 @@ describe "RootView", ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
expect(rootView.project.getPath()?).toBeFalsy()
|
||||
rootView.getActiveEditor().buffer.saveAs('/tmp/ignore-me')
|
||||
rootView.getActiveEditor().getBuffer().saveAs('/tmp/ignore-me')
|
||||
expect(rootView.project.getPath()).toBe '/tmp'
|
||||
|
||||
describe "when editors are focused", ->
|
||||
@@ -529,13 +529,13 @@ describe "RootView", ->
|
||||
it "opens an empty buffer in a new editor", ->
|
||||
rootView.open()
|
||||
expect(rootView.getActiveEditor()).toBeDefined()
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBeUndefined()
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBeUndefined()
|
||||
|
||||
describe "when called with a path", ->
|
||||
it "opens a buffer with the given path in a new editor", ->
|
||||
rootView.open('b')
|
||||
expect(rootView.getActiveEditor()).toBeDefined()
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
|
||||
describe "when there is an active editor", ->
|
||||
beforeEach ->
|
||||
@@ -544,7 +544,7 @@ describe "RootView", ->
|
||||
describe "when called with no path", ->
|
||||
it "opens an empty buffer in the active editor", ->
|
||||
rootView.open()
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBeUndefined()
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBeUndefined()
|
||||
|
||||
describe "when called with a path", ->
|
||||
[editor1, editor2] = []
|
||||
@@ -563,7 +563,7 @@ describe "RootView", ->
|
||||
|
||||
describe "when the active editor has an edit session for the given path", ->
|
||||
it "re-activates the existing edit session", ->
|
||||
expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
expect(activeEditor.getBuffer().getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
previousEditSession = activeEditor.activeEditSession
|
||||
|
||||
rootView.open('b')
|
||||
@@ -581,7 +581,7 @@ describe "RootView", ->
|
||||
describe "when the active editor has an edit session for the given path", ->
|
||||
it "re-activates the existing edit session regardless of whether any other editor also has an edit session for the path", ->
|
||||
activeEditor = rootView.getActiveEditor()
|
||||
expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
expect(activeEditor.getBuffer().getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
previousEditSession = activeEditor.activeEditSession
|
||||
|
||||
rootView.open('b')
|
||||
@@ -596,11 +596,11 @@ describe "RootView", ->
|
||||
expect(rootView.getActiveEditor()).toBe editor1
|
||||
rootView.open('b', allowActiveEditorChange: true)
|
||||
expect(rootView.getActiveEditor()).toBe editor2
|
||||
expect(editor2.buffer.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
expect(editor2.getBuffer().getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
|
||||
describe "when no other editor has an edit session for the path either", ->
|
||||
it "creates a new edit session for the path on the current active editor", ->
|
||||
path = require.resolve('fixtures/sample.js')
|
||||
rootView.open(path, allowActiveEditorChange: true)
|
||||
expect(rootView.getActiveEditor()).toBe editor1
|
||||
expect(editor1.buffer.getPath()).toBe path
|
||||
expect(editor1.getBuffer().getPath()).toBe path
|
||||
|
||||
@@ -61,4 +61,4 @@ describe "Window", ->
|
||||
|
||||
$(window).trigger 'beforeunload'
|
||||
|
||||
expect(editor1.buffer.subscriptionCount()).toBe 1 # buffer has a self-subscription for the undo manager
|
||||
expect(editor1.getBuffer().subscriptionCount()).toBe 1 # buffer has a self-subscription for the undo manager
|
||||
|
||||
Reference in New Issue
Block a user