mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05: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
|
||||
|
||||
@@ -52,7 +52,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when no text is selected", ->
|
||||
it 'autocompletes word when there is only a prefix', ->
|
||||
editor.buffer.insert([10,0] ,"extra:s:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:s:extra")
|
||||
editor.setCursorBufferPosition([10,7])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -65,7 +65,7 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.matchesList.find('li:eq(1)')).toHaveText('shift')
|
||||
|
||||
it 'autocompletes word when there is only a suffix', ->
|
||||
editor.buffer.insert([10,0] ,"extra:e:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:e:extra")
|
||||
editor.setCursorBufferPosition([10,6])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -77,7 +77,7 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.matchesList.find('li:eq(0)')).toHaveText('while')
|
||||
|
||||
it 'autocompletes word when there is a prefix and suffix', ->
|
||||
editor.buffer.insert([8,43] ,"q")
|
||||
editor.getBuffer().insert([8,43] ,"q")
|
||||
editor.setCursorBufferPosition([8,44])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -97,7 +97,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when text is selected", ->
|
||||
it 'autocompletes word when there is only a prefix', ->
|
||||
editor.buffer.insert([10,0] ,"extra:sort:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:sort:extra")
|
||||
editor.setSelectedBufferRange [[10,7], [10,10]]
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -109,7 +109,7 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.matchesList.find('li:eq(0)')).toHaveText('shift')
|
||||
|
||||
it 'autocompletes word when there is only a suffix', ->
|
||||
editor.buffer.insert([10,0] ,"extra:current:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:current:extra")
|
||||
editor.setSelectedBufferRange [[10,6],[10,12]]
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -133,7 +133,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe 'autocomplete:confirm event', ->
|
||||
it 'replaces selection with selected match, moves the cursor to the end of the match, and removes the autocomplete menu', ->
|
||||
editor.buffer.insert([10,0] ,"extra:sort:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:sort:extra")
|
||||
editor.setSelectedBufferRange [[10,7], [10,9]]
|
||||
autocomplete.attach()
|
||||
miniEditor.trigger "autocomplete:confirm"
|
||||
@@ -145,7 +145,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when there are no matches", ->
|
||||
it "closes the menu without changing the buffer", ->
|
||||
editor.buffer.insert([10,0] ,"xxx")
|
||||
editor.getBuffer().insert([10,0] ,"xxx")
|
||||
editor.setCursorBufferPosition [10, 3]
|
||||
autocomplete.attach()
|
||||
expect(autocomplete.matchesList.find('li').length).toBe 1
|
||||
@@ -160,7 +160,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe 'autocomplete:cancel event', ->
|
||||
it 'does not replace selection, removes autocomplete view and returns focus to editor', ->
|
||||
editor.buffer.insert([10,0] ,"extra:so:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:so:extra")
|
||||
editor.setSelectedBufferRange [[10,7], [10,8]]
|
||||
originalSelectionBufferRange = editor.getSelection().getBufferRange()
|
||||
|
||||
@@ -173,7 +173,7 @@ describe "Autocomplete", ->
|
||||
expect(editor.find('.autocomplete')).not.toExist()
|
||||
|
||||
it "does not clear out a previously confirmed selection when canceling with an empty list", ->
|
||||
editor.buffer.insert([10, 0], "sort\n")
|
||||
editor.getBuffer().insert([10, 0], "sort\n")
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
|
||||
autocomplete.attach()
|
||||
@@ -187,7 +187,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe 'move-up event', ->
|
||||
it "highlights the previous match and replaces the selection with it", ->
|
||||
editor.buffer.insert([10,0] ,"extra:t:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:t:extra")
|
||||
editor.setCursorBufferPosition([10,6])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -204,7 +204,7 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.find('li:eq(6)')).toHaveClass('selected')
|
||||
|
||||
it "scrolls to the selected match if it is out of view", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
editor.attachToDom()
|
||||
autocomplete.attach()
|
||||
@@ -222,7 +222,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe 'move-down event', ->
|
||||
it "highlights the next match and replaces the selection with it", ->
|
||||
editor.buffer.insert([10,0] ,"extra:s:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:s:extra")
|
||||
editor.setCursorBufferPosition([10,7])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -237,7 +237,7 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.find('li:eq(1)')).not.toHaveClass('selected')
|
||||
|
||||
it "scrolls to the selected match if it is out of view", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
editor.attachToDom()
|
||||
autocomplete.attach()
|
||||
@@ -255,7 +255,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when a match is clicked in the match list", ->
|
||||
it "selects and confirms the match", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -268,7 +268,7 @@ describe "Autocomplete", ->
|
||||
expect(editor.lineForBufferRow(10)).toBe matchToSelect.text()
|
||||
|
||||
it "cancels the autocomplete when clicking on the 'No matches found' li", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -281,7 +281,7 @@ describe "Autocomplete", ->
|
||||
describe "when the mini-editor receives keyboard input", ->
|
||||
describe "when text is removed from the mini-editor", ->
|
||||
it "reloads the match list based on the mini-editor's text", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10,0])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -293,7 +293,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when the text contains only word characters", ->
|
||||
it "narrows the list of completions with the fuzzy match algorithm", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10,0])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -314,7 +314,7 @@ describe "Autocomplete", ->
|
||||
|
||||
describe "when a non-word character is typed in the mini-editor", ->
|
||||
it "immediately confirms the current completion choice and inserts that character into the buffer", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.getBuffer().insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10,0])
|
||||
autocomplete.attach()
|
||||
|
||||
@@ -339,12 +339,12 @@ describe "Autocomplete", ->
|
||||
describe "when the autocomplete menu is detached", ->
|
||||
it 'updates word list', ->
|
||||
spyOn(autocomplete, 'buildWordList')
|
||||
editor.buffer.change([[0,4],[0,13]], "sauron")
|
||||
editor.getBuffer().change([[0,4],[0,13]], "sauron")
|
||||
expect(autocomplete.buildWordList).toHaveBeenCalled()
|
||||
|
||||
describe "when the autocomplete menu is attached and the change was caused by autocomplete itself", ->
|
||||
it 'does not rebuild the word list', ->
|
||||
editor.buffer.insert([10,0] ,"extra:s:extra")
|
||||
editor.getBuffer().insert([10,0] ,"extra:s:extra")
|
||||
|
||||
spyOn(autocomplete, 'buildWordList')
|
||||
editor.setCursorBufferPosition([10,7])
|
||||
@@ -364,7 +364,7 @@ describe "Autocomplete", ->
|
||||
expect(wordList).toContain "Some"
|
||||
|
||||
it 'stops listening to previous buffers change events', ->
|
||||
previousBuffer = editor.buffer
|
||||
previousBuffer = editor.getBuffer()
|
||||
editor.edit(fixturesProject.open('sample.txt'))
|
||||
spyOn(autocomplete, "buildWordList")
|
||||
|
||||
@@ -375,12 +375,12 @@ describe "Autocomplete", ->
|
||||
describe 'when the editor is removed', ->
|
||||
it 'removes event listeners from its buffer', ->
|
||||
spyOn(autocomplete, 'buildWordList').andCallThrough()
|
||||
editor.buffer.insert([0,0], "s")
|
||||
editor.getBuffer().insert([0,0], "s")
|
||||
expect(autocomplete.buildWordList).toHaveBeenCalled()
|
||||
|
||||
autocomplete.buildWordList.reset()
|
||||
editor.remove()
|
||||
editor.buffer.insert([0,0], "s")
|
||||
editor.getBuffer().insert([0,0], "s")
|
||||
expect(autocomplete.buildWordList).not.toHaveBeenCalled()
|
||||
|
||||
describe ".attach()", ->
|
||||
@@ -416,10 +416,10 @@ describe "Autocomplete", ->
|
||||
describe ".detach()", ->
|
||||
it "clears the mini-editor and unbinds autocomplete event handlers for move-up and move-down", ->
|
||||
autocomplete.attach()
|
||||
miniEditor.buffer.setText('foo')
|
||||
miniEditor.getBuffer().setText('foo')
|
||||
|
||||
autocomplete.detach()
|
||||
expect(miniEditor.buffer.getText()).toBe ''
|
||||
expect(miniEditor.getBuffer().getText()).toBe ''
|
||||
|
||||
editor.trigger 'move-down'
|
||||
expect(editor.getCursorBufferPosition().row).toBe 1
|
||||
|
||||
@@ -49,7 +49,7 @@ describe "CommandPanel", ->
|
||||
rootView.trigger 'command-panel:toggle'
|
||||
expect(rootView.find('.command-panel').view()).toBe commandPanel
|
||||
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
|
||||
expect(commandPanel.miniEditor.buffer.getText()).toBe ''
|
||||
expect(commandPanel.miniEditor.getBuffer().getText()).toBe ''
|
||||
expect(commandPanel.miniEditor.getCursorScreenPosition()).toEqual [0, 0]
|
||||
|
||||
describe "when command-panel:repeat-relative-address is triggered on the root view", ->
|
||||
|
||||
@@ -71,14 +71,14 @@ describe 'FuzzyFinder', ->
|
||||
selectedLi = finder.find('li:eq(1)')
|
||||
|
||||
expectedPath = rootView.project.resolve(selectedLi.text())
|
||||
expect(editor1.buffer.getPath()).not.toBe expectedPath
|
||||
expect(editor2.buffer.getPath()).not.toBe expectedPath
|
||||
expect(editor1.getBuffer().getPath()).not.toBe expectedPath
|
||||
expect(editor2.getBuffer().getPath()).not.toBe expectedPath
|
||||
|
||||
finder.trigger 'fuzzy-finder:select-path'
|
||||
|
||||
expect(finder.hasParent()).toBeFalsy()
|
||||
expect(editor1.buffer.getPath()).not.toBe expectedPath
|
||||
expect(editor2.buffer.getPath()).toBe expectedPath
|
||||
expect(editor1.getBuffer().getPath()).not.toBe expectedPath
|
||||
expect(editor2.getBuffer().getPath()).toBe expectedPath
|
||||
expect(editor2.isFocused).toBeTruthy()
|
||||
|
||||
describe "when no paths are highlighted", ->
|
||||
@@ -159,8 +159,8 @@ describe 'FuzzyFinder', ->
|
||||
finder.trigger 'fuzzy-finder:select-path'
|
||||
|
||||
expect(finder.hasParent()).toBeFalsy()
|
||||
expect(editor1.buffer.getPath()).not.toBe expectedPath
|
||||
expect(editor2.buffer.getPath()).toBe expectedPath
|
||||
expect(editor1.getBuffer().getPath()).not.toBe expectedPath
|
||||
expect(editor2.getBuffer().getPath()).toBe expectedPath
|
||||
expect(editor2.isFocused).toBeTruthy()
|
||||
|
||||
describe "when the highlighted path is not open in the active editor, but instead is open on another editor", ->
|
||||
@@ -179,8 +179,8 @@ describe 'FuzzyFinder', ->
|
||||
finder.trigger 'fuzzy-finder:select-path'
|
||||
|
||||
expect(finder.hasParent()).toBeFalsy()
|
||||
expect(editor1.buffer.getPath()).not.toBe expectedPath
|
||||
expect(editor2.buffer.getPath()).toBe expectedPath
|
||||
expect(editor1.getBuffer().getPath()).not.toBe expectedPath
|
||||
expect(editor2.getBuffer().getPath()).toBe expectedPath
|
||||
expect(editor2.isFocused).toBeTruthy()
|
||||
|
||||
describe "common behavior between file and buffer finder", ->
|
||||
@@ -271,12 +271,12 @@ describe 'FuzzyFinder', ->
|
||||
selectedLi = finder.find('li:eq(1)')
|
||||
|
||||
expectedPath = rootView.project.resolve(selectedLi.text())
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).not.toBe expectedPath
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).not.toBe expectedPath
|
||||
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
|
||||
|
||||
selectedLi.mousedown()
|
||||
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe expectedPath
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe expectedPath
|
||||
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
|
||||
|
||||
describe ".findMatches(queryString)", ->
|
||||
|
||||
@@ -11,7 +11,7 @@ describe "Snippets extension", ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
rootView.activateExtension(Snippets)
|
||||
editor = rootView.getActiveEditor()
|
||||
buffer = editor.buffer
|
||||
buffer = editor.getBuffer()
|
||||
rootView.simulateDomAttachment()
|
||||
rootView.enableKeymap()
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ describe "StripTrailingWhitespace", ->
|
||||
# works for buffers that are already open when extension is initialized
|
||||
editor.insertText("foo \nbar\t \n\nbaz")
|
||||
editor.save()
|
||||
expect(editor.buffer.getText()).toBe "foo\nbar\n\nbaz"
|
||||
expect(editor.getBuffer().getText()).toBe "foo\nbar\n\nbaz"
|
||||
|
||||
# works for buffers that are opened after extension is initialized
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
editor.moveCursorToEndOfLine()
|
||||
editor.insertText(" ")
|
||||
|
||||
editor.buffer.save()
|
||||
expect(editor.buffer.getText()).toBe 'Some text.\n'
|
||||
editor.getBuffer().save()
|
||||
expect(editor.getBuffer().getText()).toBe 'Some text.\n'
|
||||
|
||||
@@ -171,20 +171,20 @@ describe "TreeView", ->
|
||||
|
||||
sampleJs.trigger clickEvent(originalEvent: { detail: 1 })
|
||||
expect(sampleJs).toHaveClass 'selected'
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
|
||||
|
||||
sampleTxt.trigger clickEvent(originalEvent: { detail: 1 })
|
||||
expect(sampleTxt).toHaveClass 'selected'
|
||||
expect(treeView.find('.selected').length).toBe 1
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe require.resolve('fixtures/sample.txt')
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe require.resolve('fixtures/sample.txt')
|
||||
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
|
||||
|
||||
describe "when a file is double-clicked", ->
|
||||
it "selects the file and opens it in the active editor on the first click, then changes focus to the active editor on the second", ->
|
||||
sampleJs.trigger clickEvent(originalEvent: { detail: 1 })
|
||||
expect(sampleJs).toHaveClass 'selected'
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(rootView.getActiveEditor().isFocused).toBeFalsy()
|
||||
|
||||
sampleJs.trigger clickEvent(originalEvent: { detail: 2 })
|
||||
@@ -391,7 +391,7 @@ describe "TreeView", ->
|
||||
it "opens the file in the editor", ->
|
||||
treeView.root.find('.file:contains(sample.js)').click()
|
||||
treeView.root.trigger 'tree-view:open-selected-entry'
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe require.resolve('fixtures/sample.js')
|
||||
|
||||
describe "when a directory is selected", ->
|
||||
it "expands or collapses the directory", ->
|
||||
@@ -470,7 +470,7 @@ describe "TreeView", ->
|
||||
expect(fs.exists(newPath)).toBeTruthy()
|
||||
expect(fs.isFile(newPath)).toBeTruthy()
|
||||
expect(addDialog.parent()).not.toExist()
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).toBe newPath
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).toBe newPath
|
||||
|
||||
waitsFor "tree view to be updated", ->
|
||||
dirView.entries.find("> .file").length > 1
|
||||
@@ -499,7 +499,7 @@ describe "TreeView", ->
|
||||
expect(fs.exists(newPath)).toBeTruthy()
|
||||
expect(fs.isDirectory(newPath)).toBeTruthy()
|
||||
expect(addDialog.parent()).not.toExist()
|
||||
expect(rootView.getActiveEditor().buffer.getPath()).not.toBe newPath
|
||||
expect(rootView.getActiveEditor().getBuffer().getPath()).not.toBe newPath
|
||||
|
||||
describe "when a or directory already exists at the given path", ->
|
||||
it "shows an error message and does not close the dialog", ->
|
||||
|
||||
@@ -27,7 +27,7 @@ xdescribe "VimMode", ->
|
||||
expect(event.stopPropagation).not.toHaveBeenCalled()
|
||||
|
||||
it "does not allow the cursor to be placed on the \n character, unless the line is empty", ->
|
||||
editor.buffer.setText("012345\n\nabcdef")
|
||||
editor.getBuffer().setText("012345\n\nabcdef")
|
||||
editor.setCursorScreenPosition([0, 5])
|
||||
expect(editor.getCursorScreenPosition()).toEqual [0,5]
|
||||
|
||||
@@ -67,121 +67,121 @@ xdescribe "VimMode", ->
|
||||
|
||||
describe "the x keybinding", ->
|
||||
it "deletes a charachter", ->
|
||||
editor.buffer.setText("012345")
|
||||
editor.getBuffer().setText("012345")
|
||||
editor.setCursorScreenPosition([0, 4])
|
||||
|
||||
editor.trigger keydownEvent('x')
|
||||
expect(editor.buffer.getText()).toBe '01235'
|
||||
expect(editor.getBuffer().getText()).toBe '01235'
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, 4])
|
||||
|
||||
editor.trigger keydownEvent('x')
|
||||
expect(editor.buffer.getText()).toBe '0123'
|
||||
expect(editor.getBuffer().getText()).toBe '0123'
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, 3])
|
||||
|
||||
editor.trigger keydownEvent('x')
|
||||
expect(editor.buffer.getText()).toBe '012'
|
||||
expect(editor.getBuffer().getText()).toBe '012'
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0, 2])
|
||||
|
||||
it "deletes nothing when cursor is on empty line", ->
|
||||
editor.buffer.setText "012345\n\nabcdef"
|
||||
editor.getBuffer().setText "012345\n\nabcdef"
|
||||
editor.setCursorScreenPosition [1, 0]
|
||||
|
||||
editor.trigger keydownEvent 'x'
|
||||
expect(editor.buffer.getText()).toBe "012345\n\nabcdef"
|
||||
expect(editor.getBuffer().getText()).toBe "012345\n\nabcdef"
|
||||
|
||||
describe "the d keybinding", ->
|
||||
describe "when followed by a d", ->
|
||||
it "deletes the current line", ->
|
||||
editor.buffer.setText("12345\nabcde\nABCDE")
|
||||
editor.getBuffer().setText("12345\nabcde\nABCDE")
|
||||
editor.setCursorScreenPosition([1,1])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('d')
|
||||
expect(editor.buffer.getText()).toBe "12345\nABCDE"
|
||||
expect(editor.getBuffer().getText()).toBe "12345\nABCDE"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1,0])
|
||||
|
||||
it "deletes the last line", ->
|
||||
editor.buffer.setText("12345\nabcde\nABCDE")
|
||||
editor.getBuffer().setText("12345\nabcde\nABCDE")
|
||||
editor.setCursorScreenPosition([2,1])
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('d')
|
||||
expect(editor.buffer.getText()).toBe "12345\nabcde"
|
||||
expect(editor.getBuffer().getText()).toBe "12345\nabcde"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1,0])
|
||||
|
||||
xdescribe "when the second d is prefixed by a count", ->
|
||||
it "deletes n lines, starting from the current", ->
|
||||
editor.buffer.setText("12345\nabcde\nABCDE\nQWERT")
|
||||
editor.getBuffer().setText("12345\nabcde\nABCDE\nQWERT")
|
||||
editor.setCursorScreenPosition([1,1])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('2')
|
||||
editor.trigger keydownEvent('d')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "12345\nQWERT"
|
||||
expect(editor.getBuffer().getText()).toBe "12345\nQWERT"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1,0])
|
||||
|
||||
describe "when followed by an h", ->
|
||||
it "deletes the previous letter on the current line", ->
|
||||
editor.buffer.setText("abcd\n01234")
|
||||
editor.getBuffer().setText("abcd\n01234")
|
||||
editor.setCursorScreenPosition([1,1])
|
||||
|
||||
editor.trigger keydownEvent 'd'
|
||||
editor.trigger keydownEvent 'h'
|
||||
|
||||
expect(editor.buffer.getText()).toBe "abcd\n1234"
|
||||
expect(editor.getBuffer().getText()).toBe "abcd\n1234"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1,0])
|
||||
|
||||
editor.trigger keydownEvent 'd'
|
||||
editor.trigger keydownEvent 'h'
|
||||
|
||||
expect(editor.buffer.getText()).toBe "abcd\n1234"
|
||||
expect(editor.getBuffer().getText()).toBe "abcd\n1234"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([1,0])
|
||||
|
||||
describe "when followed by a w", ->
|
||||
it "deletes to the beginning of the next word", ->
|
||||
editor.buffer.setText("abcd efg")
|
||||
editor.getBuffer().setText("abcd efg")
|
||||
editor.setCursorScreenPosition([0,2])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('w')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "abefg"
|
||||
expect(editor.getBuffer().getText()).toBe "abefg"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0,2])
|
||||
|
||||
editor.buffer.setText("one two three four")
|
||||
editor.getBuffer().setText("one two three four")
|
||||
editor.setCursorScreenPosition([0,0])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('3')
|
||||
editor.trigger keydownEvent('w')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "four"
|
||||
expect(editor.getBuffer().getText()).toBe "four"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0,0])
|
||||
|
||||
describe "when followed by a b", ->
|
||||
it "deletes to the beginning of the previous word", ->
|
||||
editor.buffer.setText("abcd efg")
|
||||
editor.getBuffer().setText("abcd efg")
|
||||
editor.setCursorScreenPosition([0,2])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('b')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "cd efg"
|
||||
expect(editor.getBuffer().getText()).toBe "cd efg"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0,0])
|
||||
|
||||
editor.buffer.setText("one two three four")
|
||||
editor.getBuffer().setText("one two three four")
|
||||
editor.setCursorScreenPosition([0,11])
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('3')
|
||||
editor.trigger keydownEvent('b')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "ee four"
|
||||
expect(editor.getBuffer().getText()).toBe "ee four"
|
||||
expect(editor.getCursorScreenPosition()).toEqual([0,0])
|
||||
|
||||
describe "basic motion bindings", ->
|
||||
beforeEach ->
|
||||
editor.buffer.setText("12345\nabcde\nABCDE")
|
||||
editor.getBuffer().setText("12345\nabcde\nABCDE")
|
||||
editor.setCursorScreenPosition([1,1])
|
||||
|
||||
describe "the h keybinding", ->
|
||||
@@ -215,7 +215,7 @@ xdescribe "VimMode", ->
|
||||
|
||||
describe "the w keybinding", ->
|
||||
it "moves the cursor to the beginning of the next word", ->
|
||||
editor.buffer.setText("ab cde1+- \n xyz\n\nzip")
|
||||
editor.getBuffer().setText("ab cde1+- \n xyz\n\nzip")
|
||||
editor.setCursorScreenPosition([0,0])
|
||||
|
||||
editor.trigger keydownEvent('w')
|
||||
@@ -238,7 +238,7 @@ xdescribe "VimMode", ->
|
||||
|
||||
describe "the { keybinding", ->
|
||||
it "moves the cursor to the beginning of the paragraph", ->
|
||||
editor.buffer.setText("abcde\n\nfghij\nhijk\n xyz \n\nzip\n\n \nthe end")
|
||||
editor.getBuffer().setText("abcde\n\nfghij\nhijk\n xyz \n\nzip\n\n \nthe end")
|
||||
editor.setCursorScreenPosition([0,0])
|
||||
|
||||
editor.trigger keydownEvent('}')
|
||||
@@ -255,7 +255,7 @@ xdescribe "VimMode", ->
|
||||
|
||||
describe "the b keybinding", ->
|
||||
it "moves the cursor to the beginning of the previous word", ->
|
||||
editor.buffer.setText(" ab cde1+- \n xyz\n\nzip }\n last")
|
||||
editor.getBuffer().setText(" ab cde1+- \n xyz\n\nzip }\n last")
|
||||
editor.setCursorScreenPosition [4,1]
|
||||
|
||||
editor.trigger keydownEvent('b')
|
||||
@@ -287,28 +287,28 @@ xdescribe "VimMode", ->
|
||||
|
||||
describe "numeric prefix bindings", ->
|
||||
it "repeats the following operation N times", ->
|
||||
editor.buffer.setText("12345")
|
||||
editor.getBuffer().setText("12345")
|
||||
editor.setCursorScreenPosition([0,1])
|
||||
|
||||
editor.trigger keydownEvent('3')
|
||||
editor.trigger keydownEvent('x')
|
||||
|
||||
expect(editor.buffer.getText()).toBe '15'
|
||||
expect(editor.getBuffer().getText()).toBe '15'
|
||||
|
||||
editor.buffer.setText("123456789abc")
|
||||
editor.getBuffer().setText("123456789abc")
|
||||
editor.setCursorScreenPosition([0,0])
|
||||
editor.trigger keydownEvent('1')
|
||||
editor.trigger keydownEvent('0')
|
||||
editor.trigger keydownEvent('x')
|
||||
|
||||
expect(editor.buffer.getText()).toBe 'bc'
|
||||
expect(editor.getBuffer().getText()).toBe 'bc'
|
||||
|
||||
describe "insert-mode", ->
|
||||
beforeEach ->
|
||||
editor.trigger keydownEvent('i')
|
||||
|
||||
it "allows the cursor to reach the end of the line", ->
|
||||
editor.buffer.setText("012345\n\nabcdef")
|
||||
editor.getBuffer().setText("012345\n\nabcdef")
|
||||
editor.setCursorScreenPosition([0, 5])
|
||||
expect(editor.getCursorScreenPosition()).toEqual [0,5]
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ class Editor extends View
|
||||
charHeight: null
|
||||
cursorViews: null
|
||||
selectionViews: null
|
||||
buffer: null
|
||||
lineCache: null
|
||||
isFocused: false
|
||||
activeEditSession: null
|
||||
@@ -246,16 +245,16 @@ class Editor extends View
|
||||
bufferRowsForScreenRows: (startRow, endRow) -> @activeEditSession.bufferRowsForScreenRows(startRow, endRow)
|
||||
stateForScreenRow: (row) -> @activeEditSession.stateForScreenRow(row)
|
||||
|
||||
setText: (text) -> @buffer.setText(text)
|
||||
getText: -> @buffer.getText()
|
||||
getLastBufferRow: -> @buffer.getLastRow()
|
||||
getTextInRange: (range) -> @buffer.getTextInRange(range)
|
||||
getEofPosition: -> @buffer.getEofPosition()
|
||||
lineForBufferRow: (row) -> @buffer.lineForRow(row)
|
||||
lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row)
|
||||
rangeForBufferRow: (row) -> @buffer.rangeForRow(row)
|
||||
scanInRange: (args...) -> @buffer.scanInRange(args...)
|
||||
backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...)
|
||||
setText: (text) -> @getBuffer().setText(text)
|
||||
getText: -> @getBuffer().getText()
|
||||
getLastBufferRow: -> @getBuffer().getLastRow()
|
||||
getTextInRange: (range) -> @getBuffer().getTextInRange(range)
|
||||
getEofPosition: -> @getBuffer().getEofPosition()
|
||||
lineForBufferRow: (row) -> @getBuffer().lineForRow(row)
|
||||
lineLengthForBufferRow: (row) -> @getBuffer().lineLengthForRow(row)
|
||||
rangeForBufferRow: (row) -> @getBuffer().rangeForRow(row)
|
||||
scanInRange: (args...) -> @getBuffer().scanInRange(args...)
|
||||
backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...)
|
||||
|
||||
handleEvents: ->
|
||||
@on 'focus', =>
|
||||
@@ -353,6 +352,8 @@ class Editor extends View
|
||||
|
||||
@setActiveEditSessionIndex(index)
|
||||
|
||||
getBuffer: -> @activeEditSession.buffer
|
||||
|
||||
destroyActiveEditSession: ->
|
||||
if @editSessions.length == 1
|
||||
@remove()
|
||||
@@ -383,11 +384,8 @@ class Editor extends View
|
||||
|
||||
@activeEditSession = @editSessions[index]
|
||||
|
||||
@unsubscribeFromBuffer() if @buffer
|
||||
@buffer = @activeEditSession.buffer
|
||||
|
||||
@trigger 'editor-path-change'
|
||||
@activeEditSession.on "buffer-path-change", => @trigger 'editor-path-change'
|
||||
@trigger 'editor-path-change'
|
||||
@renderWhenAttached()
|
||||
|
||||
activateEditSessionForPath: (path) ->
|
||||
@@ -500,12 +498,12 @@ class Editor extends View
|
||||
$(window).off 'resize', @_setSoftWrapColumn
|
||||
|
||||
save: ->
|
||||
if not @buffer.getPath()
|
||||
if not @getBuffer().getPath()
|
||||
path = Native.saveDialog()
|
||||
return false if not path
|
||||
@buffer.saveAs(path)
|
||||
@getBuffer().saveAs(path)
|
||||
else
|
||||
@buffer.save()
|
||||
@getBuffer().save()
|
||||
true
|
||||
|
||||
subscribeToFontSize: ->
|
||||
@@ -540,8 +538,8 @@ class Editor extends View
|
||||
|
||||
close: ->
|
||||
return if @mini
|
||||
if @buffer.isModified()
|
||||
filename = if @buffer.getPath() then fs.base(@buffer.getPath()) else "untitled buffer"
|
||||
if @getBuffer().isModified()
|
||||
filename = if @getBuffer().getPath() then fs.base(@getBuffer().getPath()) else "untitled buffer"
|
||||
message = "'#{filename}' has changes, do you want to save them?"
|
||||
detailedMessage = "Your changes will be lost if you don't save them"
|
||||
buttons = [
|
||||
@@ -560,7 +558,6 @@ class Editor extends View
|
||||
@trigger 'before-remove'
|
||||
|
||||
@destroyEditSessions()
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
$(window).off ".editor#{@id}"
|
||||
rootView = @rootView()
|
||||
@@ -568,9 +565,6 @@ class Editor extends View
|
||||
if @pane() then @pane().remove() else super
|
||||
rootView?.focus()
|
||||
|
||||
unsubscribeFromBuffer: ->
|
||||
@buffer.off ".editor#{@id}"
|
||||
|
||||
destroyEditSessions: ->
|
||||
for session in @editSessions
|
||||
session.destroy()
|
||||
|
||||
@@ -24,4 +24,4 @@ class Gutter extends View
|
||||
@calculateDimensions()
|
||||
|
||||
calculateDimensions: ->
|
||||
@lineNumbers.width(@editor().buffer.getLastRow().toString().length * @editor().charWidth)
|
||||
@lineNumbers.width(@editor().getBuffer().getLastRow().toString().length * @editor().charWidth)
|
||||
|
||||
@@ -132,9 +132,9 @@ class RootView extends View
|
||||
|
||||
if not editor.mini
|
||||
editor.on 'editor-path-change.root-view', =>
|
||||
@trigger 'active-editor-path-change', editor.buffer.getPath()
|
||||
if not previousActiveEditor or editor.buffer.getPath() != previousActiveEditor.buffer.getPath()
|
||||
@trigger 'active-editor-path-change', editor.buffer.getPath()
|
||||
@trigger 'active-editor-path-change', editor.getBuffer().getPath()
|
||||
if not previousActiveEditor or editor.getBuffer().getPath() != previousActiveEditor.getBuffer().getPath()
|
||||
@trigger 'active-editor-path-change', editor.getBuffer().getPath()
|
||||
|
||||
activeKeybindings: ->
|
||||
keymap.bindingsForElement(document.activeElement)
|
||||
|
||||
@@ -28,7 +28,7 @@ class StatusBar extends View
|
||||
@editor.on 'cursor-move', => @updateCursorPositionText()
|
||||
|
||||
updatePathText: ->
|
||||
path = @editor.buffer.getPath()
|
||||
path = @editor.getBuffer().getPath()
|
||||
if path
|
||||
@currentPath.text(@rootView.project.relativize(path))
|
||||
else
|
||||
|
||||
@@ -32,10 +32,10 @@ class Autocomplete extends View
|
||||
initialize: (@editor) ->
|
||||
requireStylesheet 'autocomplete.css'
|
||||
@handleEvents()
|
||||
@setCurrentBuffer(@editor.buffer)
|
||||
@setCurrentBuffer(@editor.getBuffer())
|
||||
|
||||
handleEvents: ->
|
||||
@editor.on 'editor-path-change', => @setCurrentBuffer(@editor.buffer)
|
||||
@editor.on 'editor-path-change', => @setCurrentBuffer(@editor.getBuffer())
|
||||
@editor.on 'before-remove', => @currentBuffer?.off '.autocomplete'
|
||||
|
||||
@editor.on 'autocomplete:attach', => @attach()
|
||||
@@ -53,7 +53,7 @@ class Autocomplete extends View
|
||||
else
|
||||
@cancel()
|
||||
|
||||
@miniEditor.buffer.on 'change', (e) =>
|
||||
@miniEditor.getBuffer().on 'change', (e) =>
|
||||
@filterMatches() if @hasParent()
|
||||
|
||||
@miniEditor.preempt 'move-up', =>
|
||||
@@ -95,7 +95,7 @@ class Autocomplete extends View
|
||||
|
||||
cancel: ->
|
||||
@detach()
|
||||
@editor.buffer.change(@currentMatchBufferRange, @originalSelectedText) if @currentMatchBufferRange
|
||||
@editor.getBuffer().change(@currentMatchBufferRange, @originalSelectedText) if @currentMatchBufferRange
|
||||
@editor.setSelectedBufferRange(@originalSelectionBufferRange)
|
||||
|
||||
attach: ->
|
||||
@@ -120,7 +120,7 @@ class Autocomplete extends View
|
||||
super
|
||||
@editor.off(".autocomplete")
|
||||
@editor.focus()
|
||||
@miniEditor.buffer.setText('')
|
||||
@miniEditor.getBuffer().setText('')
|
||||
|
||||
setPosition: (originalCursorPosition) ->
|
||||
{ left, top } = @editor.pixelPositionForScreenPosition(originalCursorPosition)
|
||||
|
||||
@@ -10,6 +10,6 @@ class SelectAllMatches extends Command
|
||||
|
||||
execute: (editor, currentRange) ->
|
||||
rangesToSelect = []
|
||||
editor.buffer.scanInRange @regex, currentRange, (match, range) ->
|
||||
editor.getBuffer().scanInRange @regex, currentRange, (match, range) ->
|
||||
rangesToSelect.push(range)
|
||||
rangesToSelect
|
||||
|
||||
@@ -11,6 +11,6 @@ class Substitution extends Command
|
||||
@regex = new RegExp(pattern, options.join(''))
|
||||
|
||||
execute: (editor, currentRange) ->
|
||||
editor.buffer.scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
|
||||
editor.getBuffer().scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
|
||||
replace(@replacementText)
|
||||
[currentRange]
|
||||
|
||||
@@ -55,7 +55,7 @@ class CommandPanel extends View
|
||||
attach: (text='') ->
|
||||
@rootView.append(this)
|
||||
@miniEditor.focus()
|
||||
@miniEditor.buffer.setText(text)
|
||||
@miniEditor.getBuffer().setText(text)
|
||||
@prompt.css 'font', @miniEditor.css('font')
|
||||
|
||||
detach: ->
|
||||
|
||||
@@ -31,7 +31,7 @@ class FuzzyFinder extends View
|
||||
@on 'fuzzy-finder:select-path', => @select()
|
||||
@on 'mousedown', 'li', (e) => @entryClicked(e)
|
||||
|
||||
@miniEditor.buffer.on 'change', => @populatePathList() if @hasParent()
|
||||
@miniEditor.getBuffer().on 'change', => @populatePathList() if @hasParent()
|
||||
@miniEditor.off 'move-up move-down'
|
||||
|
||||
toggleFileFinder: ->
|
||||
@@ -72,7 +72,7 @@ class FuzzyFinder extends View
|
||||
|
||||
populatePathList: ->
|
||||
@pathList.empty()
|
||||
for path in @findMatches(@miniEditor.buffer.getText())
|
||||
for path in @findMatches(@miniEditor.getBuffer().getText())
|
||||
@pathList.append $$ -> @li path
|
||||
|
||||
@pathList.children('li:first').addClass 'selected'
|
||||
|
||||
@@ -101,7 +101,7 @@ class TreeView extends View
|
||||
@append(@root)
|
||||
|
||||
selectActiveFile: ->
|
||||
activeFilePath = @rootView.getActiveEditor()?.buffer.getPath()
|
||||
activeFilePath = @rootView.getActiveEditor()?.getBuffer().getPath()
|
||||
@selectEntryForPath(activeFilePath)
|
||||
|
||||
selectEntryForPath: (path) ->
|
||||
|
||||
@@ -28,7 +28,7 @@ class MoveUp extends Motion
|
||||
class MoveDown extends Motion
|
||||
execute: ->
|
||||
{column, row} = @editor.getCursorScreenPosition()
|
||||
@editor.moveCursorDown() if row < (@editor.buffer.getLineCount() - 1)
|
||||
@editor.moveCursorDown() if row < (@editor.getBuffer().getLineCount() - 1)
|
||||
|
||||
class MoveToPreviousWord extends Motion
|
||||
execute: ->
|
||||
@@ -47,7 +47,7 @@ class MoveToNextWord extends Motion
|
||||
nextWordPosition: ->
|
||||
regex = getWordRegex()
|
||||
{ row, column } = @editor.getCursorScreenPosition()
|
||||
rightOfCursor = @editor.buffer.lineForRow(row).substring(column)
|
||||
rightOfCursor = @editor.getBuffer().lineForRow(row).substring(column)
|
||||
|
||||
match = regex.exec(rightOfCursor)
|
||||
# If we're on top of part of a word, match the next one.
|
||||
@@ -55,10 +55,10 @@ class MoveToNextWord extends Motion
|
||||
|
||||
if match
|
||||
column += match.index
|
||||
else if row + 1 == @editor.buffer.getLineCount()
|
||||
column = @editor.buffer.lineForRow(row).length
|
||||
else if row + 1 == @editor.getBuffer().getLineCount()
|
||||
column = @editor.getBuffer().lineForRow(row).length
|
||||
else
|
||||
nextLineMatch = regex.exec(@editor.buffer.lineForRow(++row))
|
||||
nextLineMatch = regex.exec(@editor.getBuffer().lineForRow(++row))
|
||||
column = nextLineMatch?.index or 0
|
||||
{ row, column }
|
||||
|
||||
@@ -75,14 +75,14 @@ class MoveToNextParagraph extends Motion
|
||||
column = 0
|
||||
|
||||
startRow = @editor.getCursorBufferRow() + 1
|
||||
for r in [startRow..@editor.buffer.getLastRow()]
|
||||
if @editor.buffer.lineForRow(r).length == 0
|
||||
for r in [startRow..@editor.getBuffer().getLastRow()]
|
||||
if @editor.getBuffer().lineForRow(r).length == 0
|
||||
row = r
|
||||
break
|
||||
|
||||
if not row
|
||||
row = @editor.buffer.getLastRow()
|
||||
column = @editor.buffer.lastLine().length - 1
|
||||
row = @editor.getBuffer().getLastRow()
|
||||
column = @editor.getBuffer().lastLine().length - 1
|
||||
|
||||
new Point(row, column)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Delete
|
||||
@motion.select()
|
||||
@editor.getSelection().delete()
|
||||
else
|
||||
@editor.buffer.deleteRow(@editor.getCursorBufferRow())
|
||||
@editor.getBuffer().deleteRow(@editor.getCursorBufferRow())
|
||||
@editor.setCursorScreenPosition([@editor.getCursorScreenRow(), 0])
|
||||
|
||||
compose: (motion) ->
|
||||
|
||||
Reference in New Issue
Block a user