Update EditSession to Editor in method references

This commit is contained in:
Kevin Sawicki 2013-11-26 12:39:27 -08:00
parent 19dc6b3523
commit 48692e5127
4 changed files with 61 additions and 61 deletions

View File

@ -126,11 +126,11 @@ describe "EditorView", ->
expect(editorView.editor.destroyed).toBeTruthy()
describe ".edit(editor)", ->
[newEditSession, newBuffer] = []
[newEditor, newBuffer] = []
beforeEach ->
newEditSession = atom.project.openSync('two-hundred.txt')
newBuffer = newEditSession.buffer
newEditor = atom.project.openSync('two-hundred.txt')
newBuffer = newEditor.buffer
it "updates the rendered lines, cursors, selections, scroll position, and event subscriptions to match the given edit session", ->
editorView.attachToDom(heightInLines: 5, widthInChars: 30)
@ -141,10 +141,10 @@ describe "EditorView", ->
previousScrollTop = editorView.scrollTop()
previousScrollLeft = editorView.scrollLeft()
newEditSession.setScrollTop(900)
newEditSession.setSelectedBufferRange([[40, 0], [43, 1]])
newEditor.setScrollTop(900)
newEditor.setSelectedBufferRange([[40, 0], [43, 1]])
editorView.edit(newEditSession)
editorView.edit(newEditor)
{ firstRenderedScreenRow, lastRenderedScreenRow } = editorView
expect(editorView.lineElementForScreenRow(firstRenderedScreenRow).text()).toBe newBuffer.lineForRow(firstRenderedScreenRow)
expect(editorView.lineElementForScreenRow(lastRenderedScreenRow).text()).toBe newBuffer.lineForRow(editorView.lastRenderedScreenRow)
@ -168,14 +168,14 @@ describe "EditorView", ->
it "triggers alert if edit session's buffer goes into conflict with changes on disk", ->
filePath = path.join(temp.dir, 'atom-changed-file.txt')
fs.writeFileSync(filePath, "")
tempEditSession = atom.project.openSync(filePath)
editorView.edit(tempEditSession)
tempEditSession.insertText("a buffer change")
tempEditor = atom.project.openSync(filePath)
editorView.edit(tempEditor)
tempEditor.insertText("a buffer change")
spyOn(atom, "confirm")
contentsConflictedHandler = jasmine.createSpy("contentsConflictedHandler")
tempEditSession.on 'contents-conflicted', contentsConflictedHandler
tempEditor.on 'contents-conflicted', contentsConflictedHandler
fs.writeFileSync(filePath, "a file change")
waitsFor ->
contentsConflictedHandler.callCount > 0
@ -1736,9 +1736,9 @@ describe "EditorView", ->
expect(editorView.bufferPositionForScreenPosition(editorView.getCursorScreenPosition())).toEqual [3, 60]
it "does not wrap the lines of any newly assigned buffers", ->
otherEditSession = atom.project.openSync()
otherEditSession.buffer.setText([1..100].join(''))
editorView.edit(otherEditSession)
otherEditor = atom.project.openSync()
otherEditor.buffer.setText([1..100].join(''))
editorView.edit(otherEditor)
expect(editorView.renderedLines.find('.line').length).toBe(1)
it "unwraps lines when softwrap is disabled", ->
@ -1894,14 +1894,14 @@ describe "EditorView", ->
describe "when the switching from an edit session for a long buffer to an edit session for a short buffer", ->
it "updates the line numbers to reflect the shorter buffer", ->
emptyEditSession = atom.project.openSync(null)
editorView.edit(emptyEditSession)
emptyEditor = atom.project.openSync(null)
editorView.edit(emptyEditor)
expect(editorView.gutter.lineNumbers.find('.line-number').length).toBe 1
editorView.edit(editor)
expect(editorView.gutter.lineNumbers.find('.line-number').length).toBeGreaterThan 1
editorView.edit(emptyEditSession)
editorView.edit(emptyEditor)
expect(editorView.gutter.lineNumbers.find('.line-number').length).toBe 1
describe "when the editor view is mini", ->

View File

@ -39,15 +39,15 @@ describe "Project", ->
describe "when an edit session is destroyed", ->
it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", ->
editor = atom.project.openSync("a")
anotherEditSession = atom.project.openSync("a")
anotherEditor = atom.project.openSync("a")
expect(atom.project.editors.length).toBe 2
expect(editor.buffer).toBe anotherEditSession.buffer
expect(editor.buffer).toBe anotherEditor.buffer
editor.destroy()
expect(atom.project.editors.length).toBe 1
anotherEditSession.destroy()
anotherEditor.destroy()
expect(atom.project.editors.length).toBe 0
describe "when an edit session is saved and the project has no path", ->
@ -66,14 +66,14 @@ describe "Project", ->
editor1 = atom.project.openSync("a")
expect(handler.callCount).toBe 1
expect(atom.project.getEditSessions().length).toBe 1
expect(atom.project.getEditSessions()[0]).toBe editor1
expect(atom.project.getEditors().length).toBe 1
expect(atom.project.getEditors()[0]).toBe editor1
editor2 = atom.deserializers.deserialize(editor1.serialize())
expect(handler.callCount).toBe 2
expect(atom.project.getEditSessions().length).toBe 2
expect(atom.project.getEditSessions()[0]).toBe editor1
expect(atom.project.getEditSessions()[1]).toBe editor2
expect(atom.project.getEditors().length).toBe 2
expect(atom.project.getEditors()[0]).toBe editor1
expect(atom.project.getEditors()[1]).toBe editor2
describe "when an edit session is copied", ->
it "emits an 'editor-created' event and stores the edit session", ->
@ -82,23 +82,23 @@ describe "Project", ->
editor1 = atom.project.openSync("a")
expect(handler.callCount).toBe 1
expect(atom.project.getEditSessions().length).toBe 1
expect(atom.project.getEditSessions()[0]).toBe editor1
expect(atom.project.getEditors().length).toBe 1
expect(atom.project.getEditors()[0]).toBe editor1
editor2 = editor1.copy()
expect(handler.callCount).toBe 2
expect(atom.project.getEditSessions().length).toBe 2
expect(atom.project.getEditSessions()[0]).toBe editor1
expect(atom.project.getEditSessions()[1]).toBe editor2
expect(atom.project.getEditors().length).toBe 2
expect(atom.project.getEditors()[0]).toBe editor1
expect(atom.project.getEditors()[1]).toBe editor2
describe ".openSync(path)", ->
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditSessionHandler] = []
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditorHandler] = []
beforeEach ->
absolutePath = require.resolve('./fixtures/dir/a')
newBufferHandler = jasmine.createSpy('newBufferHandler')
atom.project.on 'buffer-created', newBufferHandler
newEditSessionHandler = jasmine.createSpy('newEditSessionHandler')
atom.project.on 'editor-created', newEditSessionHandler
newEditorHandler = jasmine.createSpy('newEditorHandler')
atom.project.on 'editor-created', newEditorHandler
fooOpener = (pathToOpen, options) -> { foo: pathToOpen, options } if pathToOpen?.match(/\.foo/)
barOpener = (pathToOpen) -> { bar: pathToOpen } if pathToOpen?.match(/^bar:\/\//)
@ -115,14 +115,14 @@ describe "Project", ->
editor = atom.project.openSync(absolutePath)
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when given a relative path that hasn't been opened previously", ->
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created' and 'editor-created' events", ->
editor = atom.project.openSync('a')
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when passed the path to a buffer that has already been opened", ->
it "returns a new edit session containing previously opened buffer and emits a 'editor-created' event", ->
@ -131,14 +131,14 @@ describe "Project", ->
expect(atom.project.openSync(absolutePath).buffer).toBe editor.buffer
expect(atom.project.openSync('a').buffer).toBe editor.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when not passed a path", ->
it "returns a new edit session and emits 'buffer-created' and 'editor-created' events", ->
editor = atom.project.openSync()
expect(editor.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when passed a path that matches a custom opener", ->
it "returns the resource returned by the custom opener", ->
@ -147,14 +147,14 @@ describe "Project", ->
expect(atom.project.openSync("bar://baz")).toEqual { bar: "bar://baz" }
describe ".open(path)", ->
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditSessionHandler] = []
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditorHandler] = []
beforeEach ->
absolutePath = require.resolve('./fixtures/dir/a')
newBufferHandler = jasmine.createSpy('newBufferHandler')
atom.project.on 'buffer-created', newBufferHandler
newEditSessionHandler = jasmine.createSpy('newEditSessionHandler')
atom.project.on 'editor-created', newEditSessionHandler
newEditorHandler = jasmine.createSpy('newEditorHandler')
atom.project.on 'editor-created', newEditorHandler
fooOpener = (pathToOpen, options) -> { foo: pathToOpen, options } if pathToOpen?.match(/\.foo/)
barOpener = (pathToOpen) -> { bar: pathToOpen } if pathToOpen?.match(/^bar:\/\//)
@ -175,7 +175,7 @@ describe "Project", ->
runs ->
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when given a relative path that isn't currently opened", ->
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created' and 'editor-created' events", ->
@ -186,7 +186,7 @@ describe "Project", ->
runs ->
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when passed the path to a buffer that is currently opened", ->
it "returns a new edit session containing currently opened buffer and emits a 'editor-created' event", ->
@ -199,7 +199,7 @@ describe "Project", ->
expect(atom.project.openSync(absolutePath).buffer).toBe editor.buffer
expect(atom.project.openSync('a').buffer).toBe editor.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when not passed a path", ->
it "returns a new edit session and emits 'buffer-created' and 'editor-created' events", ->
@ -210,7 +210,7 @@ describe "Project", ->
runs ->
expect(editor.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editor
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "when passed a path that matches a custom opener", ->
it "returns the resource returned by the custom opener", ->

View File

@ -267,14 +267,14 @@ describe "WorkspaceView", ->
describe "when called with a path", ->
describe "when the active pane already has an edit session item for the path being opened", ->
it "shows the existing edit session in the pane", ->
previousEditSession = activePane.activeItem
previousEditor = activePane.activeItem
editor = atom.workspaceView.openSync('b')
expect(activePane.activeItem).toBe editor
expect(editor).not.toBe previousEditSession
expect(editor).not.toBe previousEditor
editor = atom.workspaceView.openSync(previousEditSession.getPath())
expect(editor).toBe previousEditSession
editor = atom.workspaceView.openSync(previousEditor.getPath())
expect(editor).toBe previousEditor
expect(activePane.activeItem).toBe editor
expect(activePane.focus).toHaveBeenCalled()
@ -431,7 +431,7 @@ describe "WorkspaceView", ->
describe "when called with a path", ->
describe "when the active pane already has an item for the given path", ->
it "shows the existing edit session in the pane", ->
previousEditSession = activePane.activeItem
previousEditor = activePane.activeItem
editor = null
waitsForPromise ->
@ -439,13 +439,13 @@ describe "WorkspaceView", ->
runs ->
expect(activePane.activeItem).toBe editor
expect(editor).not.toBe previousEditSession
expect(editor).not.toBe previousEditor
waitsForPromise ->
atom.workspaceView.open(previousEditSession.getPath()).then (o) -> editor = o
atom.workspaceView.open(previousEditor.getPath()).then (o) -> editor = o
runs ->
expect(editor).toBe previousEditSession
expect(editor).toBe previousEditor
expect(activePane.activeItem).toBe editor
expect(activePane.focus).toHaveBeenCalled()

View File

@ -27,7 +27,7 @@ TextMateScopeSelector = require('first-mate').ScopeSelector
#
# ## Example
# ```coffeescript
# global.workspaceView.eachEditSession (editor) ->
# global.workspaceView.eachEditor (editor) ->
# editor.insertText('Hello World')
# ```
#
@ -75,7 +75,7 @@ class Editor
@addSelection(marker)
@setScrollTop(@state.get('scrollTop'))
@setScrollLeft(@state.get('scrollLeft'))
registerEditSession = true
registerEditor = true
else
{buffer, displayBuffer, tabLength, softTabs, softWrap, suppressCursorCreation, initialLine} = optionsOrState
@id = guid.create().toString()
@ -107,7 +107,7 @@ class Editor
when 'scrollLeft'
@emit 'scroll-left-changed', newValue
atom.project.addEditSession(this) if registerEditSession
atom.project.addEditor(this) if registerEditor
# Private:
setBuffer: (@buffer) ->
@ -143,7 +143,7 @@ class Editor
@buffer.release()
@displayBuffer.destroy()
@languageMode.destroy()
atom.project?.removeEditSession(this)
atom.project?.removeEditor(this)
@emit 'destroyed'
@off()
@ -158,13 +158,13 @@ class Editor
tabLength = @getTabLength()
displayBuffer = @displayBuffer.copy()
softTabs = @getSoftTabs()
newEditSession = new Editor({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true})
newEditSession.setScrollTop(@getScrollTop())
newEditSession.setScrollLeft(@getScrollLeft())
newEditor = new Editor({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true})
newEditor.setScrollTop(@getScrollTop())
newEditor.setScrollLeft(@getScrollLeft())
for marker in @findMarkers(editorId: @id)
marker.copy(editorId: newEditSession.id, preserveFolds: true)
atom.project.addEditSession(newEditSession)
newEditSession
marker.copy(editorId: newEditor.id, preserveFolds: true)
atom.project.addEditor(newEditor)
newEditor
# Public: Retrieves the filename of the open file.
#