Merge pull request #1132 from atom/cj-editor-rename

Editor & EditSession rename
This commit is contained in:
Corey Johnson
2013-11-20 10:11:09 -08:00
32 changed files with 9242 additions and 9237 deletions

View File

@@ -73,8 +73,8 @@ window.clickEvent = (properties={}) ->
window.mouseEvent = (type, properties) ->
if properties.point
{point, editor} = properties
{top, left} = @pagePixelPositionForPoint(editor, point)
{point, editorView} = properties
{top, left} = @pagePixelPositionForPoint(editorView, point)
properties.pageX = left + 1
properties.pageY = top + 1
properties.originalEvent ?= {detail: 1}
@@ -86,14 +86,14 @@ window.mousedownEvent = (properties={}) ->
window.mousemoveEvent = (properties={}) ->
window.mouseEvent('mousemove', properties)
window.pagePixelPositionForPoint = (editor, point) ->
window.pagePixelPositionForPoint = (editorView, point) ->
point = Point.fromObject point
top = editor.lines.offset().top + point.row * editor.lineHeight
left = editor.lines.offset().left + point.column * editor.charWidth - editor.lines.scrollLeft()
top = editorView.lines.offset().top + point.row * editorView.lineHeight
left = editorView.lines.offset().left + point.column * editorView.charWidth - editorView.lines.scrollLeft()
{ top, left }
window.setEditorWidthInChars = (editor, widthInChars, charWidth=editor.charWidth) ->
editor.width(charWidth * widthInChars + editor.lines.position().left)
window.seteditorViewWidthInChars = (editorView, widthInChars, charWidth=editorView.charWidth) ->
editorView.width(charWidth * widthInChars + editorView.lines.position().left)
$.fn.resultOfTrigger = (type) ->
event = $.Event(type)

View File

@@ -2,8 +2,8 @@ require './benchmark-helper'
{$, _, RootView} = require 'atom'
TokenizedBuffer = require '../src/tokenized-buffer'
describe "editor.", ->
editor = null
describe "editorView.", ->
editorView = null
beforeEach ->
window.rootViewParentSelector = '#jasmine-content'
@@ -12,19 +12,19 @@ describe "editor.", ->
rootView.width(1024)
rootView.height(768)
rootView.openSync() # open blank editor
editor = rootView.getActiveView()
rootView.openSync()
editorView = rootView.getActiveView()
afterEach ->
if editor.pendingDisplayUpdate
if editorView.pendingDisplayUpdate
waitsFor "editor to finish rendering", (done) ->
editor.on 'editor:display-updated', done
editorView.on 'editor:display-updated', done
describe "keymap.", ->
event = null
beforeEach ->
event = keydownEvent('x', target: editor.hiddenInput[0])
event = keydownEvent('x', target: editorView.hiddenInput[0])
benchmark "keydown-event-with-no-binding", 10, ->
keymap.handleKeyEvent(event)
@@ -35,8 +35,8 @@ describe "editor.", ->
describe "empty-file.", ->
benchmark "insert-delete", ->
editor.insertText('x')
editor.backspace()
editorView.insertText('x')
editorView.backspace()
describe "300-line-file.", ->
beforeEach ->
@@ -44,81 +44,81 @@ describe "editor.", ->
describe "at-begining.", ->
benchmark "insert-delete", ->
editor.insertText('x')
editor.backspace()
editorView.insertText('x')
editorView.backspace()
benchmark "insert-delete-rehighlight", ->
editor.insertText('"')
editor.backspace()
editorView.insertText('"')
editorView.backspace()
describe "at-end.", ->
beforeEach ->
editor.moveCursorToBottom()
editorView.moveCursorToBottom()
benchmark "insert-delete", ->
editor.insertText('"')
editor.backspace()
editorView.insertText('"')
editorView.backspace()
describe "empty-vs-set-innerHTML.", ->
[firstRow, lastRow] = []
beforeEach ->
firstRow = editor.getFirstVisibleScreenRow()
lastRow = editor.getLastVisibleScreenRow()
firstRow = editorView.getFirstVisibleScreenRow()
lastRow = editorView.getLastVisibleScreenRow()
benchmark "build-gutter-html.", 1000, ->
editor.gutter.renderLineNumbers(null, firstRow, lastRow)
editorView.gutter.renderLineNumbers(null, firstRow, lastRow)
benchmark "set-innerHTML.", 1000, ->
editor.gutter.renderLineNumbers(null, firstRow, lastRow)
editor.gutter.lineNumbers[0].innerHtml = ''
editorView.gutter.renderLineNumbers(null, firstRow, lastRow)
editorView.gutter.lineNumbers[0].innerHtml = ''
benchmark "empty.", 1000, ->
editor.gutter.renderLineNumbers(null, firstRow, lastRow)
editor.gutter.lineNumbers.empty()
editorView.gutter.renderLineNumbers(null, firstRow, lastRow)
editorView.gutter.lineNumbers.empty()
describe "positionLeftForLineAndColumn.", ->
line = null
beforeEach ->
editor.scrollTop(2000)
editor.resetDisplay()
line = editor.lineElementForScreenRow(106)[0]
editorView.scrollTop(2000)
editorView.resetDisplay()
line = editorView.lineElementForScreenRow(106)[0]
describe "one-line.", ->
beforeEach ->
editor.clearCharacterWidthCache()
editorView.clearCharacterWidthCache()
benchmark "uncached", 5000, ->
editor.positionLeftForLineAndColumn(line, 106, 82)
editor.clearCharacterWidthCache()
editorView.positionLeftForLineAndColumn(line, 106, 82)
editorView.clearCharacterWidthCache()
benchmark "cached", 5000, ->
editor.positionLeftForLineAndColumn(line, 106, 82)
editorView.positionLeftForLineAndColumn(line, 106, 82)
describe "multiple-lines.", ->
[firstRow, lastRow] = []
beforeEach ->
firstRow = editor.getFirstVisibleScreenRow()
lastRow = editor.getLastVisibleScreenRow()
firstRow = editorView.getFirstVisibleScreenRow()
lastRow = editorView.getLastVisibleScreenRow()
benchmark "cache-entire-visible-area", 100, ->
for i in [firstRow..lastRow]
line = editor.lineElementForScreenRow(i)[0]
editor.positionLeftForLineAndColumn(line, i, Math.max(0, editor.lineLengthForBufferRow(i)))
line = editorView.lineElementForScreenRow(i)[0]
editorView.positionLeftForLineAndColumn(line, i, Math.max(0, editorView.lineLengthForBufferRow(i)))
describe "text-rendering.", ->
beforeEach ->
editor.scrollTop(2000)
editorView.scrollTop(2000)
benchmark "resetDisplay", 50, ->
editor.resetDisplay()
editorView.resetDisplay()
benchmark "htmlForScreenRows", 1000, ->
lastRow = editor.getLastScreenRow()
editor.htmlForScreenRows(0, lastRow)
lastRow = editorView.getLastScreenRow()
editorView.htmlForScreenRows(0, lastRow)
benchmark "htmlForScreenRows.htmlParsing", 50, ->
lastRow = editor.getLastScreenRow()
html = editor.htmlForScreenRows(0, lastRow)
lastRow = editorView.getLastScreenRow()
html = editorView.htmlForScreenRows(0, lastRow)
div = document.createElement('div')
div.innerHTML = html
@@ -126,44 +126,44 @@ describe "editor.", ->
describe "gutter-api.", ->
describe "getLineNumberElementsForClass.", ->
beforeEach ->
editor.gutter.addClassToLine(20, 'omgwow')
editor.gutter.addClassToLine(40, 'omgwow')
editorView.gutter.addClassToLine(20, 'omgwow')
editorView.gutter.addClassToLine(40, 'omgwow')
benchmark "DOM", 20000, ->
editor.gutter.getLineNumberElementsForClass('omgwow')
editorView.gutter.getLineNumberElementsForClass('omgwow')
benchmark "getLineNumberElement.DOM", 20000, ->
editor.gutter.getLineNumberElement(12)
editorView.gutter.getLineNumberElement(12)
benchmark "toggle-class", 2000, ->
editor.gutter.addClassToLine(40, 'omgwow')
editor.gutter.removeClassFromLine(40, 'omgwow')
editorView.gutter.addClassToLine(40, 'omgwow')
editorView.gutter.removeClassFromLine(40, 'omgwow')
describe "find-then-unset.", ->
classes = ['one', 'two', 'three', 'four']
benchmark "single-class", 200, ->
editor.gutter.addClassToLine(30, 'omgwow')
editor.gutter.addClassToLine(40, 'omgwow')
editor.gutter.removeClassFromAllLines('omgwow')
editorView.gutter.addClassToLine(30, 'omgwow')
editorView.gutter.addClassToLine(40, 'omgwow')
editorView.gutter.removeClassFromAllLines('omgwow')
benchmark "multiple-class", 200, ->
editor.gutter.addClassToLine(30, 'one')
editor.gutter.addClassToLine(30, 'two')
editorView.gutter.addClassToLine(30, 'one')
editorView.gutter.addClassToLine(30, 'two')
editor.gutter.addClassToLine(40, 'two')
editor.gutter.addClassToLine(40, 'three')
editor.gutter.addClassToLine(40, 'four')
editorView.gutter.addClassToLine(40, 'two')
editorView.gutter.addClassToLine(40, 'three')
editorView.gutter.addClassToLine(40, 'four')
for klass in classes
editor.gutter.removeClassFromAllLines(klass)
editorView.gutter.removeClassFromAllLines(klass)
describe "line-htmlification.", ->
div = null
html = null
beforeEach ->
lastRow = editor.getLastScreenRow()
html = editor.htmlForScreenRows(0, lastRow)
lastRow = editorView.getLastScreenRow()
html = editorView.htmlForScreenRows(0, lastRow)
div = document.createElement('div')
benchmark "setInnerHTML", 1, ->
@@ -178,40 +178,40 @@ describe "editor.", ->
rootView.openSync('huge.js')
benchmark "moving-to-eof.", 1, ->
editor.moveCursorToBottom()
editorView.moveCursorToBottom()
describe "on-first-line.", ->
benchmark "inserting-newline", 5, ->
editor.insertNewline()
editorView.insertNewline()
describe "on-last-visible-line.", ->
beforeEach ->
editor.setCursorScreenPosition([editor.getLastVisibleScreenRow(), 0])
editorView.setCursorScreenPosition([editorView.getLastVisibleScreenRow(), 0])
benchmark "move-down-and-scroll", 300, ->
editor.trigger 'move-down'
editorView.trigger 'move-down'
describe "at-eof.", ->
endPosition = null
beforeEach ->
editor.moveCursorToBottom()
endPosition = editor.getCursorScreenPosition()
editorView.moveCursorToBottom()
endPosition = editorView.getCursorScreenPosition()
benchmark "move-to-beginning-of-word", ->
editor.moveCursorToBeginningOfWord()
editor.setCursorScreenPosition(endPosition)
editorView.moveCursorToBeginningOfWord()
editorView.setCursorScreenPosition(endPosition)
benchmark "insert", ->
editor.insertText('x')
editorView.insertText('x')
describe "TokenizedBuffer.", ->
describe "coffee-script-grammar.", ->
[languageMode, buffer] = []
beforeEach ->
editSession = benchmarkFixturesProject.openSync('medium.coffee')
{ languageMode, buffer } = editSession
editor = benchmarkFixturesProject.openSync('medium.coffee')
{ languageMode, buffer } = editor
benchmark "construction", 20, ->
new TokenizedBuffer(buffer, { languageMode, tabLength: 2})

View File

@@ -20,7 +20,7 @@ unless process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE
module.exports.$ = $
module.exports.$$ = $$
module.exports.$$$ = $$$
module.exports.Editor = require '../src/editor'
module.exports.Editor = require '../src/editor-view'
module.exports.RootView = require '../src/root-view'
module.exports.SelectList = require '../src/select-list'
module.exports.ScrollView = require '../src/scroll-view'

View File

@@ -95,14 +95,14 @@ describe "the `atom` global", ->
it "triggers the activation event on all handlers registered during activation", ->
rootView.openSync()
editor = rootView.getActiveView()
editorView = rootView.getActiveView()
eventHandler = jasmine.createSpy("activation-event")
editor.command 'activation-event', eventHandler
editor.trigger 'activation-event'
editorView.command 'activation-event', eventHandler
editorView.trigger 'activation-event'
expect(mainModule.activate.callCount).toBe 1
expect(mainModule.activationEventCallCount).toBe 1
expect(eventHandler.callCount).toBe 1
editor.trigger 'activation-event'
editorView.trigger 'activation-event'
expect(mainModule.activationEventCallCount).toBe 2
expect(eventHandler.callCount).toBe 2
expect(mainModule.activate.callCount).toBe 1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2825
spec/editor-view-spec.coffee Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -208,44 +208,44 @@ describe "Git", ->
expect(repo.isStatusModified(statuses[modifiedPath])).toBeTruthy()
describe "buffer events", ->
[originalContent, editSession] = []
[originalContent, editor] = []
beforeEach ->
editSession = project.openSync('sample.js')
originalContent = editSession.getText()
editor = project.openSync('sample.js')
originalContent = editor.getText()
afterEach ->
fs.writeFileSync(editSession.getPath(), originalContent)
fs.writeFileSync(editor.getPath(), originalContent)
it "emits a status-changed event when a buffer is saved", ->
editSession.insertNewline()
editor.insertNewline()
statusHandler = jasmine.createSpy('statusHandler')
project.getRepo().on 'status-changed', statusHandler
editSession.save()
editor.save()
expect(statusHandler.callCount).toBe 1
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
expect(statusHandler).toHaveBeenCalledWith editor.getPath(), 256
it "emits a status-changed event when a buffer is reloaded", ->
fs.writeFileSync(editSession.getPath(), 'changed')
fs.writeFileSync(editor.getPath(), 'changed')
statusHandler = jasmine.createSpy('statusHandler')
project.getRepo().on 'status-changed', statusHandler
editSession.getBuffer().reload()
editor.getBuffer().reload()
expect(statusHandler.callCount).toBe 1
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
editSession.getBuffer().reload()
expect(statusHandler).toHaveBeenCalledWith editor.getPath(), 256
editor.getBuffer().reload()
expect(statusHandler.callCount).toBe 1
it "emits a status-changed event when a buffer's path changes", ->
fs.writeFileSync(editSession.getPath(), 'changed')
fs.writeFileSync(editor.getPath(), 'changed')
statusHandler = jasmine.createSpy('statusHandler')
project.getRepo().on 'status-changed', statusHandler
editSession.getBuffer().emit 'path-changed'
editor.getBuffer().emit 'path-changed'
expect(statusHandler.callCount).toBe 1
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
editSession.getBuffer().emit 'path-changed'
expect(statusHandler).toHaveBeenCalledWith editor.getPath(), 256
editor.getBuffer().emit 'path-changed'
expect(statusHandler.callCount).toBe 1
describe "when a project is deserialized", ->

View File

@@ -1,14 +1,14 @@
describe "LanguageMode", ->
[editSession, buffer, languageMode] = []
[editor, buffer, languageMode] = []
afterEach ->
editSession.destroy()
editor.destroy()
describe "javascript", ->
beforeEach ->
atom.activatePackage('language-javascript', sync: true)
editSession = project.openSync('sample.js', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('sample.js', autoIndent: false)
{buffer, languageMode} = editor
describe ".minIndentLevelForRowRange(startRow, endRow)", ->
it "returns the minimum indent level for the given row range", ->
@@ -110,8 +110,8 @@ describe "LanguageMode", ->
describe "coffeescript", ->
beforeEach ->
atom.activatePackage('language-coffee-script', sync: true)
editSession = project.openSync('coffee.coffee', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('coffee.coffee', autoIndent: false)
{buffer, languageMode} = editor
describe ".toggleLineCommentsForBufferRows(start, end)", ->
it "comments/uncomments lines in the given range", ->
@@ -157,8 +157,8 @@ describe "LanguageMode", ->
describe "css", ->
beforeEach ->
atom.activatePackage('language-css', sync: true)
editSession = project.openSync('css.css', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('css.css', autoIndent: false)
{buffer, languageMode} = editor
describe ".toggleLineCommentsForBufferRows(start, end)", ->
it "comments/uncomments lines in the given range", ->
@@ -199,8 +199,8 @@ describe "LanguageMode", ->
beforeEach ->
atom.activatePackage('language-less', sync: true)
atom.activatePackage('language-css', sync: true)
editSession = project.openSync('sample.less', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('sample.less', autoIndent: false)
{buffer, languageMode} = editor
describe "when commenting lines", ->
it "only uses the `commentEnd` pattern if it comes from the same grammar as the `commentStart`", ->
@@ -210,67 +210,67 @@ describe "LanguageMode", ->
describe "folding", ->
beforeEach ->
atom.activatePackage('language-javascript', sync: true)
editSession = project.openSync('sample.js', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('sample.js', autoIndent: false)
{buffer, languageMode} = editor
it "maintains cursor buffer position when a folding/unfolding", ->
editSession.setCursorBufferPosition([5,5])
editor.setCursorBufferPosition([5,5])
languageMode.foldAll()
expect(editSession.getCursorBufferPosition()).toEqual([5,5])
expect(editor.getCursorBufferPosition()).toEqual([5,5])
describe ".unfoldAll()", ->
it "unfolds every folded line", ->
initialScreenLineCount = editSession.getScreenLineCount()
initialScreenLineCount = editor.getScreenLineCount()
languageMode.foldBufferRow(0)
languageMode.foldBufferRow(1)
expect(editSession.getScreenLineCount()).toBeLessThan initialScreenLineCount
expect(editor.getScreenLineCount()).toBeLessThan initialScreenLineCount
languageMode.unfoldAll()
expect(editSession.getScreenLineCount()).toBe initialScreenLineCount
expect(editor.getScreenLineCount()).toBe initialScreenLineCount
describe ".foldAll()", ->
it "folds every foldable line", ->
languageMode.foldAll()
fold1 = editSession.lineForScreenRow(0).fold
fold1 = editor.lineForScreenRow(0).fold
expect([fold1.getStartRow(), fold1.getEndRow()]).toEqual [0, 12]
fold1.destroy()
fold2 = editSession.lineForScreenRow(1).fold
fold2 = editor.lineForScreenRow(1).fold
expect([fold2.getStartRow(), fold2.getEndRow()]).toEqual [1, 9]
fold2.destroy()
fold3 = editSession.lineForScreenRow(4).fold
fold3 = editor.lineForScreenRow(4).fold
expect([fold3.getStartRow(), fold3.getEndRow()]).toEqual [4, 7]
describe ".foldBufferRow(bufferRow)", ->
describe "when bufferRow can be folded", ->
it "creates a fold based on the syntactic region starting at the given row", ->
languageMode.foldBufferRow(1)
fold = editSession.lineForScreenRow(1).fold
fold = editor.lineForScreenRow(1).fold
expect(fold.getStartRow()).toBe 1
expect(fold.getEndRow()).toBe 9
describe "when bufferRow can't be folded", ->
it "searches upward for the first row that begins a syntatic region containing the given buffer row (and folds it)", ->
languageMode.foldBufferRow(8)
fold = editSession.lineForScreenRow(1).fold
fold = editor.lineForScreenRow(1).fold
expect(fold.getStartRow()).toBe 1
expect(fold.getEndRow()).toBe 9
describe "when the bufferRow is already folded", ->
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
languageMode.foldBufferRow(2)
expect(editSession.lineForScreenRow(1).fold).toBeDefined()
expect(editSession.lineForScreenRow(0).fold).not.toBeDefined()
expect(editor.lineForScreenRow(1).fold).toBeDefined()
expect(editor.lineForScreenRow(0).fold).not.toBeDefined()
languageMode.foldBufferRow(1)
expect(editSession.lineForScreenRow(0).fold).toBeDefined()
expect(editor.lineForScreenRow(0).fold).toBeDefined()
describe "when the bufferRow is in a multi-line comment", ->
it "searches upward and downward for surrounding comment lines and folds them as a single fold", ->
buffer.insert([1,0], " //this is a comment\n // and\n //more docs\n\n//second comment")
languageMode.foldBufferRow(1)
fold = editSession.lineForScreenRow(1).fold
fold = editor.lineForScreenRow(1).fold
expect(fold.getStartRow()).toBe 1
expect(fold.getEndRow()).toBe 3
@@ -278,7 +278,7 @@ describe "LanguageMode", ->
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
buffer.insert([1,0], " //this is a single line comment\n")
languageMode.foldBufferRow(1)
fold = editSession.lineForScreenRow(0).fold
fold = editor.lineForScreenRow(0).fold
expect(fold.getStartRow()).toBe 0
expect(fold.getEndRow()).toBe 13
@@ -286,77 +286,77 @@ describe "LanguageMode", ->
describe "when bufferRow can be unfolded", ->
it "destroys a fold based on the syntactic region starting at the given row", ->
languageMode.foldBufferRow(1)
expect(editSession.lineForScreenRow(1).fold).toBeDefined()
expect(editor.lineForScreenRow(1).fold).toBeDefined()
languageMode.unfoldBufferRow(1)
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
expect(editor.lineForScreenRow(1).fold).toBeUndefined()
describe "when bufferRow can't be unfolded", ->
it "does not throw an error", ->
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
expect(editor.lineForScreenRow(1).fold).toBeUndefined()
languageMode.unfoldBufferRow(1)
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
expect(editor.lineForScreenRow(1).fold).toBeUndefined()
describe "folding with comments", ->
beforeEach ->
atom.activatePackage('language-javascript', sync: true)
editSession = project.openSync('sample-with-comments.js', autoIndent: false)
{buffer, languageMode} = editSession
editor = project.openSync('sample-with-comments.js', autoIndent: false)
{buffer, languageMode} = editor
describe ".unfoldAll()", ->
it "unfolds every folded line", ->
initialScreenLineCount = editSession.getScreenLineCount()
initialScreenLineCount = editor.getScreenLineCount()
languageMode.foldBufferRow(0)
languageMode.foldBufferRow(5)
expect(editSession.getScreenLineCount()).toBeLessThan initialScreenLineCount
expect(editor.getScreenLineCount()).toBeLessThan initialScreenLineCount
languageMode.unfoldAll()
expect(editSession.getScreenLineCount()).toBe initialScreenLineCount
expect(editor.getScreenLineCount()).toBe initialScreenLineCount
describe ".foldAll()", ->
it "folds every foldable line", ->
languageMode.foldAll()
fold1 = editSession.lineForScreenRow(0).fold
fold1 = editor.lineForScreenRow(0).fold
expect([fold1.getStartRow(), fold1.getEndRow()]).toEqual [0, 19]
fold1.destroy()
fold2 = editSession.lineForScreenRow(1).fold
fold2 = editor.lineForScreenRow(1).fold
expect([fold2.getStartRow(), fold2.getEndRow()]).toEqual [1, 4]
fold3 = editSession.lineForScreenRow(2).fold.destroy()
fold3 = editor.lineForScreenRow(2).fold.destroy()
fold4 = editSession.lineForScreenRow(3).fold
fold4 = editor.lineForScreenRow(3).fold
expect([fold4.getStartRow(), fold4.getEndRow()]).toEqual [6, 8]
describe ".foldAllAtIndentLevel()", ->
it "folds every foldable range at a given indentLevel", ->
languageMode.foldAllAtIndentLevel(2)
fold1 = editSession.lineForScreenRow(6).fold
fold1 = editor.lineForScreenRow(6).fold
expect([fold1.getStartRow(), fold1.getEndRow()]).toEqual [6, 8]
fold1.destroy()
fold2 = editSession.lineForScreenRow(11).fold
fold2 = editor.lineForScreenRow(11).fold
expect([fold2.getStartRow(), fold2.getEndRow()]).toEqual [11, 14]
fold2.destroy()
it "does not fold anything but the indentLevel", ->
languageMode.foldAllAtIndentLevel(0)
fold1 = editSession.lineForScreenRow(0).fold
fold1 = editor.lineForScreenRow(0).fold
expect([fold1.getStartRow(), fold1.getEndRow()]).toEqual [0, 19]
fold1.destroy()
fold2 = editSession.lineForScreenRow(5).fold
fold2 = editor.lineForScreenRow(5).fold
expect(fold2).toBeFalsy()
describe "css", ->
beforeEach ->
atom.activatePackage('language-source', sync: true)
atom.activatePackage('language-css', sync: true)
editSession = project.openSync('css.css', autoIndent: true)
editor = project.openSync('css.css', autoIndent: true)
describe "suggestedIndentForBufferRow", ->
it "does not return negative values (regression)", ->
editSession.setText('.test {\npadding: 0;\n}')
expect(editSession.suggestedIndentForBufferRow(2)).toBe 0
editor.setText('.test {\npadding: 0;\n}')
expect(editor.suggestedIndentForBufferRow(2)).toBe 0

View File

@@ -111,11 +111,11 @@ describe "PaneContainer", ->
describe "when the last-closed pane item is an edit session", ->
it "reopens the edit session (regression)", ->
editSession = project.openSync('sample.js')
pane3.showItem(editSession)
pane3.destroyItem(editSession)
editor = project.openSync('sample.js')
pane3.showItem(editor)
pane3.destroyItem(editor)
expect(container.reopenItem()).toBeTruthy()
expect(pane3.activeItem.getPath()).toBe editSession.getPath()
expect(pane3.activeItem.getPath()).toBe editor.getPath()
expect(container.reopenItem()).toBeFalsy()
describe "when there is no active pane", ->

View File

@@ -5,7 +5,7 @@ path = require 'path'
temp = require 'temp'
describe "Pane", ->
[container, view1, view2, editSession1, editSession2, pane] = []
[container, view1, view2, editor1, editor2, pane] = []
class TestView extends View
@deserialize: ({id, text}) -> new TestView({id, text})
@@ -20,9 +20,9 @@ describe "Pane", ->
container = new PaneContainer
view1 = new TestView(id: 'view-1', text: 'View 1')
view2 = new TestView(id: 'view-2', text: 'View 2')
editSession1 = project.openSync('sample.js')
editSession2 = project.openSync('sample.txt')
pane = new Pane(view1, editSession1, view2, editSession2)
editor1 = project.openSync('sample.js')
editor2 = project.openSync('sample.txt')
pane = new Pane(view1, editor1, view2, editor2)
container.setRoot(pane)
afterEach ->
@@ -52,9 +52,9 @@ describe "Pane", ->
expect(itemChangedHandler.argsForCall[0][1]).toBe view2
itemChangedHandler.reset()
pane.showItem(editSession1)
pane.showItem(editor1)
expect(itemChangedHandler).toHaveBeenCalled()
expect(itemChangedHandler.argsForCall[0][1]).toBe editSession1
expect(itemChangedHandler.argsForCall[0][1]).toBe editor1
itemChangedHandler.reset()
describe "if the pane's active view is focused before calling showItem", ->
@@ -70,12 +70,12 @@ describe "Pane", ->
view3 = null
beforeEach ->
view3 = new TestView(id: 'view-3', text: "View 3")
pane.showItem(editSession1)
pane.showItem(editor1)
expect(pane.getActiveItemIndex()).toBe 1
it "adds it to the items list after the active item", ->
pane.showItem(view3)
expect(pane.getItems()).toEqual [view1, editSession1, view3, view2, editSession2]
expect(pane.getItems()).toEqual [view1, editor1, view3, view2, editor2]
expect(pane.activeItem).toBe view3
expect(pane.getActiveItemIndex()).toBe 2
@@ -89,19 +89,19 @@ describe "Pane", ->
describe "when showing a model item", ->
describe "when no view has yet been appended for that item", ->
it "appends and shows a view to display the item based on its `.getViewClass` method", ->
pane.showItem(editSession1)
editor = pane.activeView
expect(editor.css('display')).not.toBe 'none'
expect(editor.activeEditSession).toBe editSession1
pane.showItem(editor1)
editorView = pane.activeView
expect(editorView.css('display')).not.toBe 'none'
expect(editorView.activeEditSession).toBe editor1
describe "when a valid view has already been appended for another item", ->
it "multiple views are created for multiple items", ->
pane.showItem(editSession1)
pane.showItem(editSession2)
pane.showItem(editor1)
pane.showItem(editor2)
expect(pane.itemViews.find('.editor').length).toBe 2
editor = pane.activeView
expect(editor.css('display')).not.toBe 'none'
expect(editor.activeEditSession).toBe editSession2
editorView = pane.activeView
expect(editorView.css('display')).not.toBe 'none'
expect(editorView.activeEditSession).toBe editor2
it "creates a new view with the item", ->
initialViewCount = pane.itemViews.find('.test-view').length
@@ -141,77 +141,77 @@ describe "Pane", ->
describe ".destroyItem(item)", ->
describe "if the item is not modified", ->
it "removes the item and tries to call destroy on it", ->
pane.destroyItem(editSession2)
expect(pane.getItems().indexOf(editSession2)).toBe -1
expect(editSession2.destroyed).toBeTruthy()
pane.destroyItem(editor2)
expect(pane.getItems().indexOf(editor2)).toBe -1
expect(editor2.destroyed).toBeTruthy()
describe "if the item is modified", ->
beforeEach ->
spyOn(editSession2, 'save')
spyOn(editSession2, 'saveAs')
spyOn(editor2, 'save')
spyOn(editor2, 'saveAs')
editSession2.insertText('a')
expect(editSession2.isModified()).toBeTruthy()
editor2.insertText('a')
expect(editor2.isModified()).toBeTruthy()
describe "if the [Save] option is selected", ->
describe "when the item has a uri", ->
it "saves the item before removing and destroying it", ->
spyOn(atom, 'confirmSync').andReturn(0)
pane.destroyItem(editSession2)
pane.destroyItem(editor2)
expect(editSession2.save).toHaveBeenCalled()
expect(pane.getItems().indexOf(editSession2)).toBe -1
expect(editSession2.destroyed).toBeTruthy()
expect(editor2.save).toHaveBeenCalled()
expect(pane.getItems().indexOf(editor2)).toBe -1
expect(editor2.destroyed).toBeTruthy()
describe "when the item has no uri", ->
it "presents a save-as dialog, then saves the item with the given uri before removing and destroying it", ->
editSession2.buffer.setPath(undefined)
editor2.buffer.setPath(undefined)
spyOn(atom, 'showSaveDialogSync').andReturn("/selected/path")
spyOn(atom, 'confirmSync').andReturn(0)
pane.destroyItem(editSession2)
pane.destroyItem(editor2)
expect(atom.showSaveDialogSync).toHaveBeenCalled()
expect(editSession2.saveAs).toHaveBeenCalledWith("/selected/path")
expect(pane.getItems().indexOf(editSession2)).toBe -1
expect(editSession2.destroyed).toBeTruthy()
expect(editor2.saveAs).toHaveBeenCalledWith("/selected/path")
expect(pane.getItems().indexOf(editor2)).toBe -1
expect(editor2.destroyed).toBeTruthy()
describe "if the [Don't Save] option is selected", ->
it "removes and destroys the item without saving it", ->
spyOn(atom, 'confirmSync').andReturn(2)
pane.destroyItem(editSession2)
pane.destroyItem(editor2)
expect(editSession2.save).not.toHaveBeenCalled()
expect(pane.getItems().indexOf(editSession2)).toBe -1
expect(editSession2.destroyed).toBeTruthy()
expect(editor2.save).not.toHaveBeenCalled()
expect(pane.getItems().indexOf(editor2)).toBe -1
expect(editor2.destroyed).toBeTruthy()
describe "if the [Cancel] option is selected", ->
it "does not save, remove, or destroy the item", ->
spyOn(atom, 'confirmSync').andReturn(1)
pane.destroyItem(editSession2)
pane.destroyItem(editor2)
expect(editSession2.save).not.toHaveBeenCalled()
expect(pane.getItems().indexOf(editSession2)).not.toBe -1
expect(editSession2.destroyed).toBeFalsy()
expect(editor2.save).not.toHaveBeenCalled()
expect(pane.getItems().indexOf(editor2)).not.toBe -1
expect(editor2.destroyed).toBeFalsy()
describe ".removeItem(item)", ->
it "removes the item from the items list and shows the next item if it was showing", ->
pane.removeItem(view1)
expect(pane.getItems()).toEqual [editSession1, view2, editSession2]
expect(pane.activeItem).toBe editSession1
expect(pane.getItems()).toEqual [editor1, view2, editor2]
expect(pane.activeItem).toBe editor1
pane.showItem(editSession2)
pane.removeItem(editSession2)
expect(pane.getItems()).toEqual [editSession1, view2]
expect(pane.activeItem).toBe editSession1
pane.showItem(editor2)
pane.removeItem(editor2)
expect(pane.getItems()).toEqual [editor1, view2]
expect(pane.activeItem).toBe editor1
it "triggers 'pane:item-removed' with the item and its former index", ->
itemRemovedHandler = jasmine.createSpy("itemRemovedHandler")
pane.on 'pane:item-removed', itemRemovedHandler
pane.removeItem(editSession1)
pane.removeItem(editor1)
expect(itemRemovedHandler).toHaveBeenCalled()
expect(itemRemovedHandler.argsForCall[0][1..2]).toEqual [editSession1, 1]
expect(itemRemovedHandler.argsForCall[0][1..2]).toEqual [editor1, 1]
describe "when removing the last item", ->
it "removes the pane", ->
@@ -236,11 +236,11 @@ describe "Pane", ->
describe "when the item is a model", ->
it "removes the associated view only when all items that require it have been removed", ->
pane.showItem(editSession1)
pane.showItem(editSession2)
pane.removeItem(editSession2)
pane.showItem(editor1)
pane.showItem(editor2)
pane.removeItem(editor2)
expect(pane.itemViews.find('.editor')).toExist()
pane.removeItem(editSession1)
pane.removeItem(editor1)
expect(pane.itemViews.find('.editor')).not.toExist()
describe ".moveItem(item, index)", ->
@@ -249,21 +249,21 @@ describe "Pane", ->
pane.on 'pane:item-moved', itemMovedHandler
pane.moveItem(view1, 2)
expect(pane.getItems()).toEqual [editSession1, view2, view1, editSession2]
expect(pane.getItems()).toEqual [editor1, view2, view1, editor2]
expect(itemMovedHandler).toHaveBeenCalled()
expect(itemMovedHandler.argsForCall[0][1..2]).toEqual [view1, 2]
itemMovedHandler.reset()
pane.moveItem(editSession1, 3)
expect(pane.getItems()).toEqual [view2, view1, editSession2, editSession1]
pane.moveItem(editor1, 3)
expect(pane.getItems()).toEqual [view2, view1, editor2, editor1]
expect(itemMovedHandler).toHaveBeenCalled()
expect(itemMovedHandler.argsForCall[0][1..2]).toEqual [editSession1, 3]
expect(itemMovedHandler.argsForCall[0][1..2]).toEqual [editor1, 3]
itemMovedHandler.reset()
pane.moveItem(editSession1, 1)
expect(pane.getItems()).toEqual [view2, editSession1, view1, editSession2]
pane.moveItem(editor1, 1)
expect(pane.getItems()).toEqual [view2, editor1, view1, editor2]
expect(itemMovedHandler).toHaveBeenCalled()
expect(itemMovedHandler.argsForCall[0][1..2]).toEqual [editSession1, 1]
expect(itemMovedHandler.argsForCall[0][1..2]).toEqual [editor1, 1]
itemMovedHandler.reset()
describe ".moveItemToPane(item, pane, index)", ->
@@ -275,21 +275,21 @@ describe "Pane", ->
it "moves the item to the given pane at the given index", ->
pane.moveItemToPane(view1, pane2, 1)
expect(pane.getItems()).toEqual [editSession1, view2, editSession2]
expect(pane.getItems()).toEqual [editor1, view2, editor2]
expect(pane2.getItems()).toEqual [view3, view1]
describe "when it is the last item on the source pane", ->
it "removes the source pane, but does not destroy the item", ->
pane.removeItem(view1)
pane.removeItem(view2)
pane.removeItem(editSession2)
pane.removeItem(editor2)
expect(pane.getItems()).toEqual [editSession1]
pane.moveItemToPane(editSession1, pane2, 1)
expect(pane.getItems()).toEqual [editor1]
pane.moveItemToPane(editor1, pane2, 1)
expect(pane.hasParent()).toBeFalsy()
expect(pane2.getItems()).toEqual [view3, editSession1]
expect(editSession1.destroyed).toBeFalsy()
expect(pane2.getItems()).toEqual [view3, editor1]
expect(editor1.destroyed).toBeFalsy()
describe "when the item is a jQuery object", ->
it "preserves data by detaching instead of removing", ->
@@ -303,37 +303,37 @@ describe "Pane", ->
containerCloseHandler = jasmine.createSpy("containerCloseHandler")
container.on 'core:close', containerCloseHandler
pane.showItem(editSession1)
pane.showItem(editor1)
initialItemCount = pane.getItems().length
pane.trigger 'core:close'
expect(pane.getItems().length).toBe initialItemCount - 1
expect(editSession1.destroyed).toBeTruthy()
expect(editor1.destroyed).toBeTruthy()
expect(containerCloseHandler).not.toHaveBeenCalled()
describe "pane:close", ->
it "destroys all items and removes the pane", ->
pane.showItem(editSession1)
pane.showItem(editor1)
pane.trigger 'pane:close'
expect(pane.hasParent()).toBeFalsy()
expect(editSession2.destroyed).toBeTruthy()
expect(editSession1.destroyed).toBeTruthy()
expect(editor2.destroyed).toBeTruthy()
expect(editor1.destroyed).toBeTruthy()
describe "pane:close-other-items", ->
it "destroys all items except the current", ->
pane.showItem(editSession1)
pane.showItem(editor1)
pane.trigger 'pane:close-other-items'
expect(editSession2.destroyed).toBeTruthy()
expect(pane.getItems()).toEqual [editSession1]
expect(editor2.destroyed).toBeTruthy()
expect(pane.getItems()).toEqual [editor1]
describe "core:save", ->
describe "when the current item has a uri", ->
describe "when the current item has a save method", ->
it "saves the current item", ->
spyOn(editSession2, 'save')
pane.showItem(editSession2)
spyOn(editor2, 'save')
pane.showItem(editor2)
pane.trigger 'core:save'
expect(editSession2.save).toHaveBeenCalled()
expect(editor2.save).toHaveBeenCalled()
describe "when the current item has no save method", ->
it "does nothing", ->
@@ -347,14 +347,14 @@ describe "Pane", ->
describe "when the current item has a saveAs method", ->
it "opens a save dialog and saves the current item as the selected path", ->
spyOn(editSession2, 'saveAs')
editSession2.buffer.setPath(undefined)
pane.showItem(editSession2)
spyOn(editor2, 'saveAs')
editor2.buffer.setPath(undefined)
pane.showItem(editor2)
pane.trigger 'core:save'
expect(atom.showSaveDialogSync).toHaveBeenCalled()
expect(editSession2.saveAs).toHaveBeenCalledWith('/selected/path')
expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item has no saveAs method", ->
it "does nothing", ->
@@ -368,13 +368,13 @@ describe "Pane", ->
describe "when the current item has a saveAs method", ->
it "opens the save dialog and calls saveAs on the item with the selected path", ->
spyOn(editSession2, 'saveAs')
pane.showItem(editSession2)
spyOn(editor2, 'saveAs')
pane.showItem(editor2)
pane.trigger 'core:save-as'
expect(atom.showSaveDialogSync).toHaveBeenCalledWith(path.dirname(editSession2.getPath()))
expect(editSession2.saveAs).toHaveBeenCalledWith('/selected/path')
expect(atom.showSaveDialogSync).toHaveBeenCalledWith(path.dirname(editor2.getPath()))
expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item does not have a saveAs method", ->
it "does nothing", ->
@@ -386,11 +386,11 @@ describe "Pane", ->
it "advances forward/backward through the pane's items, looping around at either end", ->
expect(pane.activeItem).toBe view1
pane.trigger 'pane:show-previous-item'
expect(pane.activeItem).toBe editSession2
expect(pane.activeItem).toBe editor2
pane.trigger 'pane:show-previous-item'
expect(pane.activeItem).toBe view2
pane.trigger 'pane:show-next-item'
expect(pane.activeItem).toBe editSession2
expect(pane.activeItem).toBe editor2
pane.trigger 'pane:show-next-item'
expect(pane.activeItem).toBe view1
@@ -424,8 +424,8 @@ describe "Pane", ->
describe ".remove()", ->
it "destroys all the pane's items", ->
pane.remove()
expect(editSession1.destroyed).toBeTruthy()
expect(editSession2.destroyed).toBeTruthy()
expect(editor1.destroyed).toBeTruthy()
expect(editor2.destroyed).toBeTruthy()
it "triggers a 'pane:removed' event with the pane", ->
removedHandler = jasmine.createSpy("removedHandler")
@@ -438,7 +438,7 @@ describe "Pane", ->
[paneToLeft, paneToRight] = []
beforeEach ->
pane.showItem(editSession1)
pane.showItem(editor1)
paneToLeft = pane.splitLeft(pane.copyActiveItem())
paneToRight = pane.splitRight(pane.copyActiveItem())
container.attachToDom()
@@ -492,7 +492,7 @@ describe "Pane", ->
describe ".getNextPane()", ->
it "returns the next pane if one exists, wrapping around from the last pane to the first", ->
pane.showItem(editSession1)
pane.showItem(editor1)
expect(pane.getNextPane()).toBeUndefined
pane2 = pane.splitRight(pane.copyActiveItem())
expect(pane.getNextPane()).toBe pane2
@@ -538,7 +538,7 @@ describe "Pane", ->
[pane1, view3, view4] = []
beforeEach ->
pane1 = pane
pane.showItem(editSession1)
pane.showItem(editor1)
view3 = new TestView(id: 'view-3', text: 'View 3')
view4 = new TestView(id: 'view-4', text: 'View 4')
@@ -547,8 +547,8 @@ describe "Pane", ->
# creates the new pane with a copy of the active item if none are given
pane2 = pane1.splitRight(pane1.copyActiveItem())
expect(container.find('.row .pane').toArray()).toEqual [pane1[0], pane2[0]]
expect(pane2.items).toEqual [editSession1]
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
expect(pane2.items).toEqual [editor1]
expect(pane2.activeItem).not.toBe editor1 # it's a copy
pane3 = pane2.splitRight(view3, view4)
expect(pane3.getItems()).toEqual [view3, view4]
@@ -571,8 +571,8 @@ describe "Pane", ->
# creates the new pane with a copy of the active item if none are given
pane2 = pane.splitLeft(pane1.copyActiveItem())
expect(container.find('.row .pane').toArray()).toEqual [pane2[0], pane[0]]
expect(pane2.items).toEqual [editSession1]
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
expect(pane2.items).toEqual [editor1]
expect(pane2.activeItem).not.toBe editor1 # it's a copy
pane3 = pane2.splitLeft(view3, view4)
expect(pane3.getItems()).toEqual [view3, view4]
@@ -583,8 +583,8 @@ describe "Pane", ->
# creates the new pane with a copy of the active item if none are given
pane2 = pane.splitDown(pane1.copyActiveItem())
expect(container.find('.column .pane').toArray()).toEqual [pane[0], pane2[0]]
expect(pane2.items).toEqual [editSession1]
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
expect(pane2.items).toEqual [editor1]
expect(pane2.activeItem).not.toBe editor1 # it's a copy
pane3 = pane2.splitDown(view3, view4)
expect(pane3.getItems()).toEqual [view3, view4]
@@ -595,8 +595,8 @@ describe "Pane", ->
# creates the new pane with a copy of the active item if none are given
pane2 = pane.splitUp(pane1.copyActiveItem())
expect(container.find('.column .pane').toArray()).toEqual [pane2[0], pane[0]]
expect(pane2.items).toEqual [editSession1]
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
expect(pane2.items).toEqual [editor1]
expect(pane2.activeItem).not.toBe editor1 # it's a copy
pane3 = pane2.splitUp(view3, view4)
expect(pane3.getItems()).toEqual [view3, view4]
@@ -673,18 +673,18 @@ describe "Pane", ->
describe ".itemForUri(uri)", ->
it "returns the item for which a call to .getUri() returns the given uri", ->
expect(pane.itemForUri(editSession1.getUri())).toBe editSession1
expect(pane.itemForUri(editSession2.getUri())).toBe editSession2
expect(pane.itemForUri(editor1.getUri())).toBe editor1
expect(pane.itemForUri(editor2.getUri())).toBe editor2
describe "serialization", ->
it "can serialize and deserialize the pane and all its items", ->
newPane = deserialize(pane.serialize())
expect(newPane.getItems()).toEqual [view1, editSession1, view2, editSession2]
expect(newPane.getItems()).toEqual [view1, editor1, view2, editor2]
it "restores the active item on deserialization", ->
pane.showItem(editSession2)
pane.showItem(editor2)
newPane = deserialize(pane.serialize())
expect(newPane.activeItem).toEqual editSession2
expect(newPane.activeItem).toEqual editor2
it "does not show items that cannot be deserialized", ->
spyOn(console, 'warn')

View File

@@ -36,58 +36,58 @@ 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)", ->
editSession = project.openSync("a")
editor = project.openSync("a")
anotherEditSession = project.openSync("a")
expect(project.editSessions.length).toBe 2
expect(editSession.buffer).toBe anotherEditSession.buffer
expect(project.editors.length).toBe 2
expect(editor.buffer).toBe anotherEditSession.buffer
editSession.destroy()
expect(project.editSessions.length).toBe 1
editor.destroy()
expect(project.editors.length).toBe 1
anotherEditSession.destroy()
expect(project.editSessions.length).toBe 0
expect(project.editors.length).toBe 0
describe "when an edit session is saved and the project has no path", ->
it "sets the project's path to the saved file's parent directory", ->
tempFile = temp.openSync().path
project.setPath(undefined)
expect(project.getPath()).toBeUndefined()
editSession = project.openSync()
editSession.saveAs(tempFile)
editor = project.openSync()
editor.saveAs(tempFile)
expect(project.getPath()).toBe path.dirname(tempFile)
describe "when an edit session is deserialized", ->
it "emits an 'edit-session-created' event and stores the edit session", ->
handler = jasmine.createSpy('editSessionCreatedHandler')
project.on 'edit-session-created', handler
it "emits an 'editor-created' event and stores the edit session", ->
handler = jasmine.createSpy('editorCreatedHandler')
project.on 'editor-created', handler
editSession1 = project.openSync("a")
editor1 = project.openSync("a")
expect(handler.callCount).toBe 1
expect(project.getEditSessions().length).toBe 1
expect(project.getEditSessions()[0]).toBe editSession1
expect(project.getEditSessions()[0]).toBe editor1
editSession2 = deserialize(editSession1.serialize())
editor2 = deserialize(editor1.serialize())
expect(handler.callCount).toBe 2
expect(project.getEditSessions().length).toBe 2
expect(project.getEditSessions()[0]).toBe editSession1
expect(project.getEditSessions()[1]).toBe editSession2
expect(project.getEditSessions()[0]).toBe editor1
expect(project.getEditSessions()[1]).toBe editor2
describe "when an edit session is copied", ->
it "emits an 'edit-session-created' event and stores the edit session", ->
handler = jasmine.createSpy('editSessionCreatedHandler')
project.on 'edit-session-created', handler
it "emits an 'editor-created' event and stores the edit session", ->
handler = jasmine.createSpy('editorCreatedHandler')
project.on 'editor-created', handler
editSession1 = project.openSync("a")
editor1 = project.openSync("a")
expect(handler.callCount).toBe 1
expect(project.getEditSessions().length).toBe 1
expect(project.getEditSessions()[0]).toBe editSession1
expect(project.getEditSessions()[0]).toBe editor1
editSession2 = editSession1.copy()
editor2 = editor1.copy()
expect(handler.callCount).toBe 2
expect(project.getEditSessions().length).toBe 2
expect(project.getEditSessions()[0]).toBe editSession1
expect(project.getEditSessions()[1]).toBe editSession2
expect(project.getEditSessions()[0]).toBe editor1
expect(project.getEditSessions()[1]).toBe editor2
describe ".openSync(path)", ->
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditSessionHandler] = []
@@ -96,7 +96,7 @@ describe "Project", ->
newBufferHandler = jasmine.createSpy('newBufferHandler')
project.on 'buffer-created', newBufferHandler
newEditSessionHandler = jasmine.createSpy('newEditSessionHandler')
project.on 'edit-session-created', newEditSessionHandler
project.on 'editor-created', newEditSessionHandler
fooOpener = (pathToOpen, options) -> { foo: pathToOpen, options } if pathToOpen?.match(/\.foo/)
barOpener = (pathToOpen) -> { bar: pathToOpen } if pathToOpen?.match(/^bar:\/\//)
@@ -109,34 +109,34 @@ describe "Project", ->
describe "when passed a path that doesn't match a custom opener", ->
describe "when given an absolute path that hasn't been opened previously", ->
it "returns a new edit session for the given path and emits 'buffer-created' and 'edit-session-created' events", ->
editSession = project.openSync(absolutePath)
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
it "returns a new edit session for the given path and emits 'buffer-created' and 'editor-created' events", ->
editor = project.openSync(absolutePath)
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).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 'edit-session-created' events", ->
editSession = project.openSync('a')
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created' and 'editor-created' events", ->
editor = project.openSync('a')
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).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 'edit-session-created' event", ->
editSession = project.openSync(absolutePath)
it "returns a new edit session containing previously opened buffer and emits a 'editor-created' event", ->
editor = project.openSync(absolutePath)
newBufferHandler.reset()
expect(project.openSync(absolutePath).buffer).toBe editSession.buffer
expect(project.openSync('a').buffer).toBe editSession.buffer
expect(project.openSync(absolutePath).buffer).toBe editor.buffer
expect(project.openSync('a').buffer).toBe editor.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
expect(newEditSessionHandler).toHaveBeenCalledWith editor
describe "when not passed a path", ->
it "returns a new edit session and emits 'buffer-created' and 'edit-session-created' events", ->
editSession = project.openSync()
expect(editSession.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
it "returns a new edit session and emits 'buffer-created' and 'editor-created' events", ->
editor = project.openSync()
expect(editor.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editor
describe "when passed a path that matches a custom opener", ->
it "returns the resource returned by the custom opener", ->
@@ -152,7 +152,7 @@ describe "Project", ->
newBufferHandler = jasmine.createSpy('newBufferHandler')
project.on 'buffer-created', newBufferHandler
newEditSessionHandler = jasmine.createSpy('newEditSessionHandler')
project.on 'edit-session-created', newEditSessionHandler
project.on 'editor-created', newEditSessionHandler
fooOpener = (pathToOpen, options) -> { foo: pathToOpen, options } if pathToOpen?.match(/\.foo/)
barOpener = (pathToOpen) -> { bar: pathToOpen } if pathToOpen?.match(/^bar:\/\//)
@@ -165,50 +165,50 @@ describe "Project", ->
describe "when passed a path that doesn't match a custom opener", ->
describe "when given an absolute path that isn't currently open", ->
it "returns a new edit session for the given path and emits 'buffer-created' and 'edit-session-created' events", ->
editSession = null
it "returns a new edit session for the given path and emits 'buffer-created' and 'editor-created' events", ->
editor = null
waitsForPromise ->
project.open(absolutePath).then (o) -> editSession = o
project.open(absolutePath).then (o) -> editor = o
runs ->
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).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 'edit-session-created' events", ->
editSession = null
it "returns a new edit session for the given path (relative to the project root) and emits 'buffer-created' and 'editor-created' events", ->
editor = null
waitsForPromise ->
project.open(absolutePath).then (o) -> editSession = o
project.open(absolutePath).then (o) -> editor = o
runs ->
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
expect(editor.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editor.buffer
expect(newEditSessionHandler).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 'edit-session-created' event", ->
editSession = null
it "returns a new edit session containing currently opened buffer and emits a 'editor-created' event", ->
editor = null
waitsForPromise ->
project.open(absolutePath).then (o) -> editSession = o
project.open(absolutePath).then (o) -> editor = o
runs ->
newBufferHandler.reset()
expect(project.openSync(absolutePath).buffer).toBe editSession.buffer
expect(project.openSync('a').buffer).toBe editSession.buffer
expect(project.openSync(absolutePath).buffer).toBe editor.buffer
expect(project.openSync('a').buffer).toBe editor.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
expect(newEditSessionHandler).toHaveBeenCalledWith editor
describe "when not passed a path", ->
it "returns a new edit session and emits 'buffer-created' and 'edit-session-created' events", ->
editSession = null
it "returns a new edit session and emits 'buffer-created' and 'editor-created' events", ->
editor = null
waitsForPromise ->
project.open().then (o) -> editSession = o
project.open().then (o) -> editor = o
runs ->
expect(editSession.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
expect(editor.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editor.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editor
describe "when passed a path that matches a custom opener", ->
it "returns the resource returned by the custom opener", ->
@@ -336,8 +336,8 @@ describe "Project", ->
describe "when a buffer is already open", ->
it "replaces properly and saves when not modified", ->
editSession = project.openSync('sample.js')
expect(editSession.isModified()).toBeFalsy()
editor = project.openSync('sample.js')
expect(editor.isModified()).toBeFalsy()
results = []
waitsForPromise ->
@@ -349,12 +349,12 @@ describe "Project", ->
expect(results[0].filePath).toBe filePath
expect(results[0].replacements).toBe 6
expect(editSession.isModified()).toBeFalsy()
expect(editor.isModified()).toBeFalsy()
it "does NOT save when modified", ->
editSession = project.openSync('sample.js')
editSession.buffer.change([[0,0],[0,0]], 'omg')
expect(editSession.isModified()).toBeTruthy()
editor = project.openSync('sample.js')
editor.buffer.change([[0,0],[0,0]], 'omg')
expect(editor.isModified()).toBeTruthy()
results = []
waitsForPromise ->
@@ -366,7 +366,7 @@ describe "Project", ->
expect(results[0].filePath).toBe filePath
expect(results[0].replacements).toBe 6
expect(editSession.isModified()).toBeTruthy()
expect(editor.isModified()).toBeTruthy()
describe ".scan(options, callback)", ->
describe "when called with a regex", ->
@@ -519,8 +519,8 @@ describe "Project", ->
expect(resultHandler).not.toHaveBeenCalled()
it "scans buffer contents if the buffer is modified", ->
editSession = project.openSync("a")
editSession.setText("Elephant")
editor = project.openSync("a")
editor.setText("Elephant")
results = []
waitsForPromise ->
project.scan /a|Elephant/, (result) -> results.push result

View File

@@ -99,10 +99,10 @@ describe "RootView", ->
describe "when there is an active view", ->
it "hands off focus to the active view", ->
editor = rootView.getActiveView()
editor.isFocused = false
editorView = rootView.getActiveView()
editorView.isFocused = false
rootView.focus()
expect(editor.isFocused).toBeTruthy()
expect(editorView.isFocused).toBeTruthy()
describe "when there is no active view", ->
beforeEach ->
@@ -163,9 +163,9 @@ describe "RootView", ->
describe "when the title of the active pane item changes", ->
it "updates the window title based on the item's new title", ->
editSession = rootView.getActivePaneItem()
editSession.buffer.setPath(path.join(temp.dir, 'hi'))
expect(rootView.title).toBe "#{editSession.getTitle()} - #{project.getPath()}"
editor = rootView.getActivePaneItem()
editor.buffer.setPath(path.join(temp.dir, 'hi'))
expect(rootView.title).toBe "#{editor.getTitle()} - #{project.getPath()}"
describe "when the active pane's item changes", ->
it "updates the title to the new item's title plus the project path", ->
@@ -220,34 +220,34 @@ describe "RootView", ->
describe "when called with no path", ->
it "creates a empty edit session as an item on a new pane, and focuses the pane", ->
editSession = rootView.openSync()
expect(rootView.getActivePane().activeItem).toBe editSession
expect(editSession.getPath()).toBeUndefined()
editor = rootView.openSync()
expect(rootView.getActivePane().activeItem).toBe editor
expect(editor.getPath()).toBeUndefined()
expect(rootView.getActivePane().focus).toHaveBeenCalled()
it "can create multiple empty edit sessions as an item on a new pane", ->
editSession = rootView.openSync()
editSession2 = rootView.openSync()
editor = rootView.openSync()
editor2 = rootView.openSync()
expect(rootView.getActivePane().getItems().length).toBe 2
expect(editSession).not.toBe editSession2
expect(editor).not.toBe editor2
describe "when called with a path", ->
it "creates an edit session for the given path as an item on a new pane, and focuses the pane", ->
editSession = rootView.openSync('b')
expect(rootView.getActivePane().activeItem).toBe editSession
expect(editSession.getPath()).toBe require.resolve('./fixtures/dir/b')
editor = rootView.openSync('b')
expect(rootView.getActivePane().activeItem).toBe editor
expect(editor.getPath()).toBe require.resolve('./fixtures/dir/b')
expect(rootView.getActivePane().focus).toHaveBeenCalled()
describe "when the changeFocus option is false", ->
it "does not focus the new pane", ->
editSession = rootView.openSync('b', changeFocus: false)
editor = rootView.openSync('b', changeFocus: false)
expect(rootView.getActivePane().focus).not.toHaveBeenCalled()
describe "when the split option is 'right'", ->
it "creates a new pane and opens the file in said pane", ->
editSession = rootView.openSync('b', split: 'right')
expect(rootView.getActivePane().activeItem).toBe editSession
expect(editSession.getPath()).toBe require.resolve('./fixtures/dir/b')
editor = rootView.openSync('b', split: 'right')
expect(rootView.getActivePane().activeItem).toBe editor
expect(editor.getPath()).toBe require.resolve('./fixtures/dir/b')
describe "when there is an active pane", ->
[activePane, initialItemCount] = []
@@ -258,10 +258,10 @@ describe "RootView", ->
describe "when called with no path", ->
it "opens an edit session with an empty buffer as an item in the active pane and focuses it", ->
editSession = rootView.openSync()
editor = rootView.openSync()
expect(activePane.getItems().length).toBe initialItemCount + 1
expect(activePane.activeItem).toBe editSession
expect(editSession.getPath()).toBeUndefined()
expect(activePane.activeItem).toBe editor
expect(editor.getPath()).toBeUndefined()
expect(activePane.focus).toHaveBeenCalled()
describe "when called with a path", ->
@@ -269,43 +269,43 @@ describe "RootView", ->
it "shows the existing edit session in the pane", ->
previousEditSession = activePane.activeItem
editSession = rootView.openSync('b')
expect(activePane.activeItem).toBe editSession
expect(editSession).not.toBe previousEditSession
editor = rootView.openSync('b')
expect(activePane.activeItem).toBe editor
expect(editor).not.toBe previousEditSession
editSession = rootView.openSync(previousEditSession.getPath())
expect(editSession).toBe previousEditSession
expect(activePane.activeItem).toBe editSession
editor = rootView.openSync(previousEditSession.getPath())
expect(editor).toBe previousEditSession
expect(activePane.activeItem).toBe editor
expect(activePane.focus).toHaveBeenCalled()
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.openSync('b')
editor = rootView.openSync('b')
expect(activePane.items.length).toBe 2
expect(activePane.activeItem).toBe editSession
expect(activePane.activeItem).toBe editor
expect(activePane.focus).toHaveBeenCalled()
describe "when the changeFocus option is false", ->
it "does not focus the active pane", ->
editSession = rootView.openSync('b', changeFocus: false)
editor = rootView.openSync('b', changeFocus: false)
expect(activePane.focus).not.toHaveBeenCalled()
describe "when the split option is 'right'", ->
it "creates a new pane and opens the file in said pane", ->
pane1 = rootView.getActivePane()
editSession = rootView.openSync('b', split: 'right')
editor = rootView.openSync('b', split: 'right')
pane2 = rootView.getActivePane()
expect(pane2[0]).not.toBe pane1[0]
expect(editSession.getPath()).toBe require.resolve('./fixtures/dir/b')
expect(editor.getPath()).toBe require.resolve('./fixtures/dir/b')
expect(rootView.panes.find('.row .pane').toArray()).toEqual [pane1[0], pane2[0]]
editSession = rootView.openSync('file1', split: 'right')
editor = rootView.openSync('file1', split: 'right')
pane3 = rootView.getActivePane()
expect(pane3[0]).toBe pane2[0]
expect(editSession.getPath()).toBe require.resolve('./fixtures/dir/file1')
expect(editor.getPath()).toBe require.resolve('./fixtures/dir/file1')
expect(rootView.panes.find('.row .pane').toArray()).toEqual [pane1[0], pane2[0]]
@@ -372,41 +372,41 @@ describe "RootView", ->
describe "when called with no path", ->
it "creates a empty edit session as an item on a new pane, and focuses the pane", ->
editSession = null
editor = null
waitsForPromise ->
rootView.open().then (o) -> editSession = o
rootView.open().then (o) -> editor = o
runs ->
expect(rootView.getActivePane().activeItem).toBe editSession
expect(editSession.getPath()).toBeUndefined()
expect(rootView.getActivePane().activeItem).toBe editor
expect(editor.getPath()).toBeUndefined()
expect(rootView.getActivePane().focus).toHaveBeenCalled()
it "can create multiple empty edit sessions as items on a pane", ->
editSession1 = null
editSession2 = null
editor1 = null
editor2 = null
waitsForPromise ->
rootView.open()
.then (o) ->
editSession1 = o
editor1 = o
rootView.open()
.then (o) ->
editSession2 = o
editor2 = o
runs ->
expect(rootView.getActivePane().getItems().length).toBe 2
expect(editSession1).not.toBe editSession2
expect(editor1).not.toBe editor2
describe "when called with a path", ->
it "creates an edit session for the given path as an item on a new pane, and focuses the pane", ->
editSession = null
editor = null
waitsForPromise ->
rootView.open('b').then (o) -> editSession = o
rootView.open('b').then (o) -> editor = o
runs ->
expect(rootView.getActivePane().activeItem).toBe editSession
expect(editSession.getPath()).toBe require.resolve('./fixtures/dir/b')
expect(rootView.getActivePane().activeItem).toBe editor
expect(editor.getPath()).toBe require.resolve('./fixtures/dir/b')
expect(rootView.getActivePane().focus).toHaveBeenCalled()
describe "when there is an active pane", ->
@@ -417,15 +417,15 @@ describe "RootView", ->
describe "when called with no path", ->
it "opens an edit session with an empty buffer as an item in the active pane and focuses it", ->
editSession = null
editor = null
waitsForPromise ->
rootView.open().then (o) -> editSession = o
rootView.open().then (o) -> editor = o
runs ->
expect(activePane.getItems().length).toBe 2
expect(activePane.activeItem).toBe editSession
expect(editSession.getPath()).toBeUndefined()
expect(activePane.activeItem).toBe editor
expect(editor.getPath()).toBeUndefined()
expect(activePane.focus).toHaveBeenCalled()
describe "when called with a path", ->
@@ -433,31 +433,31 @@ describe "RootView", ->
it "shows the existing edit session in the pane", ->
previousEditSession = activePane.activeItem
editSession = null
editor = null
waitsForPromise ->
rootView.open('b').then (o) -> editSession = o
rootView.open('b').then (o) -> editor = o
runs ->
expect(activePane.activeItem).toBe editSession
expect(editSession).not.toBe previousEditSession
expect(activePane.activeItem).toBe editor
expect(editor).not.toBe previousEditSession
waitsForPromise ->
rootView.open(previousEditSession.getPath()).then (o) -> editSession = o
rootView.open(previousEditSession.getPath()).then (o) -> editor = o
runs ->
expect(editSession).toBe previousEditSession
expect(activePane.activeItem).toBe editSession
expect(editor).toBe previousEditSession
expect(activePane.activeItem).toBe editor
expect(activePane.focus).toHaveBeenCalled()
describe "when the active pane does not have an existing item for the given path", ->
it "creates a new edit session for the given path in the active pane", ->
editSession = null
editor = null
waitsForPromise ->
rootView.open('b').then (o) -> editSession = o
rootView.open('b').then (o) -> editor = o
runs ->
expect(activePane.activeItem).toBe editSession
expect(activePane.activeItem).toBe editor
expect(activePane.getItems().length).toBe 2
expect(activePane.focus).toHaveBeenCalled()

View File

@@ -1,12 +1,12 @@
EditSession = require '../src/edit-session'
Editor = require '../src/editor'
describe "Selection", ->
[buffer, editSession, selection] = []
[buffer, editor, selection] = []
beforeEach ->
buffer = project.bufferForPathSync('sample.js')
editSession = new EditSession(buffer: buffer, tabLength: 2)
selection = editSession.getSelection()
editor = new Editor(buffer: buffer, tabLength: 2)
selection = editor.getSelection()
afterEach ->
buffer.destroy()

View File

@@ -9,7 +9,7 @@ Keymap = require '../src/keymap'
Config = require '../src/config'
{Point} = require 'telepath'
Project = require '../src/project'
Editor = require '../src/editor'
EditorView = require '../src/editor-view'
TokenizedBuffer = require '../src/tokenized-buffer'
pathwatcher = require 'pathwatcher'
platform = require './spec-helper-platform'
@@ -75,7 +75,7 @@ beforeEach ->
spyOn(config, 'load')
spyOn(config, 'save')
config.setDefaults('core', RootView.configDefaults)
config.setDefaults('editor', Editor.configDefaults)
config.setDefaults('editor', EditorView.configDefaults)
config.set "editor.fontFamily", "Courier"
config.set "editor.fontSize", 16
config.set "editor.autoIndent", false
@@ -86,7 +86,7 @@ beforeEach ->
window.config = config
# make editor display updates synchronous
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
spyOn(EditorView.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
spyOn(RootView.prototype, 'setTitle').andCallFake (@title) ->
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
@@ -174,8 +174,8 @@ window.keydownEvent = (key, properties={}) ->
window.mouseEvent = (type, properties) ->
if properties.point
{point, editor} = properties
{top, left} = @pagePixelPositionForPoint(editor, point)
{point, editorView} = properties
{top, left} = @pagePixelPositionForPoint(editorView, point)
properties.pageX = left + 1
properties.pageY = top + 1
properties.originalEvent ?= {detail: 1}
@@ -236,22 +236,22 @@ window.advanceClock = (delta=1) ->
callback() for callback in callbacks
window.pagePixelPositionForPoint = (editor, point) ->
window.pagePixelPositionForPoint = (editorView, point) ->
point = Point.fromObject point
top = editor.renderedLines.offset().top + point.row * editor.lineHeight
left = editor.renderedLines.offset().left + point.column * editor.charWidth - editor.renderedLines.scrollLeft()
top = editorView.renderedLines.offset().top + point.row * editorView.lineHeight
left = editorView.renderedLines.offset().left + point.column * editorView.charWidth - editorView.renderedLines.scrollLeft()
{ top, left }
window.tokensText = (tokens) ->
_.pluck(tokens, 'value').join('')
window.setEditorWidthInChars = (editor, widthInChars, charWidth=editor.charWidth) ->
editor.width(charWidth * widthInChars + editor.gutter.outerWidth())
$(window).trigger 'resize' # update width of editor's on-screen lines
window.setEditorWidthInChars = (editorView, widthInChars, charWidth=editorView.charWidth) ->
editorView.width(charWidth * widthInChars + editorView.gutter.outerWidth())
$(window).trigger 'resize' # update width of editor view's on-screen lines
window.setEditorHeightInLines = (editor, heightInChars, charHeight=editor.lineHeight) ->
editor.height(charHeight * heightInChars + editor.renderedLines.position().top)
$(window).trigger 'resize' # update editor's on-screen lines
window.setEditorHeightInLines = (editorView, heightInChars, charHeight=editorView.lineHeight) ->
editorView.height(charHeight * heightInChars + editorView.renderedLines.position().top)
$(window).trigger 'resize' # update editor view's on-screen lines
$.fn.resultOfTrigger = (type) ->
event = $.Event(type)

View File

@@ -447,25 +447,25 @@ describe "TextMateGrammar", ->
describe "when the grammar is added", ->
it "retokenizes existing buffers that contain tokens that match the injection selector", ->
editSession = project.openSync('sample.js')
editSession.setText("// http://github.com")
editor = project.openSync('sample.js')
editor.setText("// http://github.com")
{tokens} = editSession.lineForScreenRow(0)
{tokens} = editor.lineForScreenRow(0)
expect(tokens[1].value).toBe " http://github.com"
expect(tokens[1].scopes).toEqual ["source.js", "comment.line.double-slash.js"]
atom.activatePackage('language-hyperlink', sync: true)
{tokens} = editSession.lineForScreenRow(0)
{tokens} = editor.lineForScreenRow(0)
expect(tokens[2].value).toBe "http://github.com"
expect(tokens[2].scopes).toEqual ["source.js", "comment.line.double-slash.js", "markup.underline.link.http.hyperlink"]
describe "when the grammar is updated", ->
it "retokenizes existing buffers that contain tokens that match the injection selector", ->
editSession = project.openSync('sample.js')
editSession.setText("// SELECT * FROM OCTOCATS")
editor = project.openSync('sample.js')
editor.setText("// SELECT * FROM OCTOCATS")
{tokens} = editSession.lineForScreenRow(0)
{tokens} = editor.lineForScreenRow(0)
expect(tokens[1].value).toBe " SELECT * FROM OCTOCATS"
expect(tokens[1].scopes).toEqual ["source.js", "comment.line.double-slash.js"]
@@ -477,13 +477,13 @@ describe "TextMateGrammar", ->
patterns: [ { include: "source.sql" } ]
))
{tokens} = editSession.lineForScreenRow(0)
{tokens} = editor.lineForScreenRow(0)
expect(tokens[1].value).toBe " SELECT * FROM OCTOCATS"
expect(tokens[1].scopes).toEqual ["source.js", "comment.line.double-slash.js"]
atom.activatePackage('language-sql', sync: true)
{tokens} = editSession.lineForScreenRow(0)
{tokens} = editor.lineForScreenRow(0)
expect(tokens[2].value).toBe "SELECT"
expect(tokens[2].scopes).toEqual ["source.js", "comment.line.double-slash.js", "keyword.other.DML.sql"]

View File

@@ -61,23 +61,23 @@ describe "Window", ->
it "prompts user to save and and calls rootView.confirmClose", ->
spyOn(rootView, 'confirmClose').andCallThrough()
spyOn(atom, "confirmSync").andReturn(2)
editSession = rootView.openSync("sample.js")
editSession.insertText("I look different, I feel different.")
editor = rootView.openSync("sample.js")
editor.insertText("I look different, I feel different.")
$(window).trigger(beforeUnloadEvent)
expect(rootView.confirmClose).toHaveBeenCalled()
expect(atom.confirmSync).toHaveBeenCalled()
it "prompts user to save and handler returns true if don't save", ->
spyOn(atom, "confirmSync").andReturn(2)
editSession = rootView.openSync("sample.js")
editSession.insertText("I look different, I feel different.")
editor = rootView.openSync("sample.js")
editor.insertText("I look different, I feel different.")
$(window).trigger(beforeUnloadEvent)
expect(atom.confirmSync).toHaveBeenCalled()
it "prompts user to save and handler returns false if dialog is canceled", ->
spyOn(atom, "confirmSync").andReturn(1)
editSession = rootView.openSync("sample.js")
editSession.insertText("I look different, I feel different.")
editor = rootView.openSync("sample.js")
editor.insertText("I look different, I feel different.")
$(window).trigger(beforeUnloadEvent)
expect(atom.confirmSync).toHaveBeenCalled()

View File

@@ -9,14 +9,14 @@ class CursorView extends View
@div class: 'cursor idle', => @raw ' '
blinkPeriod: 800
editor: null
editorView: null
visible: true
needsUpdate: true
needsRemoval: false
shouldPauseBlinking: false
initialize: (@cursor, @editor) ->
initialize: (@cursor, @editorView) ->
@cursor.on 'moved.cursor-view', =>
@needsUpdate = true
@shouldPauseBlinking = true
@@ -25,7 +25,7 @@ class CursorView extends View
@needsUpdate = true
@cursor.on 'autoscrolled.cursor-view', =>
@editor.requestDisplayUpdate()
@editorView.requestDisplayUpdate()
@cursor.on 'destroyed.cursor-view', =>
@needsRemoval = true
@@ -34,7 +34,7 @@ class CursorView extends View
@addClass("site-#{@cursor.marker.getOriginSiteId()}")
beforeRemove: ->
@editor.removeCursorView(this)
@editorView.removeCursorView(this)
@cursor.off('.cursor-view')
@stopBlinking()
@@ -52,7 +52,7 @@ class CursorView extends View
else if !@startBlinkingTimeout
@startBlinking()
@setVisible(@cursor.isVisible() and not @editor.isFoldedAtScreenRow(screenPosition.row))
@setVisible(@cursor.isVisible() and not @editorView.isFoldedAtScreenRow(screenPosition.row))
# Override for speed. The base function checks the computedStyle
isHidden: ->
@@ -69,7 +69,7 @@ class CursorView extends View
@cursor.clearAutoscroll()
getPixelPosition: ->
@editor.pixelPositionForScreenPosition(@getScreenPosition())
@editorView.pixelPositionForScreenPosition(@getScreenPosition())
setVisible: (visible) ->
unless @visible == visible

View File

@@ -5,7 +5,7 @@ _ = require 'underscore-plus'
# Public: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
#
# Cursors belong to {EditSession}s and have some metadata attached in the form
# Cursors belong to {Editor}s and have some metadata attached in the form
# of a {StringMarker}.
module.exports =
class Cursor
@@ -17,8 +17,8 @@ class Cursor
visible: true
needsAutoscroll: null
# Private: Instantiated by an {EditSession}
constructor: ({@editSession, @marker}) ->
# Private: Instantiated by an {Editor}
constructor: ({@editor, @marker}) ->
@updateVisibility()
@marker.on 'changed', (e) =>
@updateVisibility()
@@ -37,10 +37,10 @@ class Cursor
textChanged: textChanged
@emit 'moved', movedEvent
@editSession.emit 'cursor-moved', movedEvent
@editor.emit 'cursor-moved', movedEvent
@marker.on 'destroyed', =>
@destroyed = true
@editSession.removeCursor(this)
@editor.removeCursor(this)
@emit 'destroyed'
@needsAutoscroll = true
@@ -62,7 +62,7 @@ class Cursor
# An {Array} of two numbers: the screen row, and the screen column.
# * options:
# + autoscroll:
# A Boolean which, if `true`, scrolls the {EditSession} to wherever the
# A Boolean which, if `true`, scrolls the {Editor} to wherever the
# cursor moves to.
setScreenPosition: (screenPosition, options={}) ->
@changePosition options, =>
@@ -78,7 +78,7 @@ class Cursor
# An {Array} of two numbers: the buffer row, and the buffer column.
# * options:
# + autoscroll:
# A Boolean which, if `true`, scrolls the {EditSession} to wherever the
# A Boolean which, if `true`, scrolls the {Editor} to wherever the
# cursor moves to.
setBufferPosition: (bufferPosition, options={}) ->
@changePosition options, =>
@@ -118,13 +118,13 @@ class Cursor
segments.push("[#{_.escapeRegExp(nonWordCharacters)}]+")
new RegExp(segments.join("|"), "g")
# Public: Identifies if this cursor is the last in the {EditSession}.
# Public: Identifies if this cursor is the last in the {Editor}.
#
# "Last" is defined as the most recently added cursor.
#
# Returns a Boolean.
isLastCursor: ->
this == @editSession.getCursor()
this == @editor.getCursor()
# Public: Identifies if the cursor is surrounded by whitespace.
#
@@ -135,7 +135,7 @@ class Cursor
isSurroundedByWhitespace: ->
{row, column} = @getBufferPosition()
range = [[row, Math.min(0, column - 1)], [row, Math.max(0, column + 1)]]
/^\s+$/.test @editSession.getTextInBufferRange(range)
/^\s+$/.test @editor.getTextInBufferRange(range)
# Public: Returns whether the cursor is currently between a word and non-word
# character. The non-word characters are defined by the
@@ -150,7 +150,7 @@ class Cursor
{row, column} = @getBufferPosition()
range = [[row, column - 1], [row, column + 1]]
[before, after] = @editSession.getTextInBufferRange(range)
[before, after] = @editor.getTextInBufferRange(range)
return false if /\s/.test(before) or /\s/.test(after)
nonWordCharacters = atom.config.get('editor.nonWordCharacters').split('')
@@ -160,7 +160,7 @@ class Cursor
isInsideWord: ->
{row, column} = @getBufferPosition()
range = [[row, column], [row, Infinity]]
@editSession.getTextInBufferRange(range).search(@wordRegExp()) == 0
@editor.getTextInBufferRange(range).search(@wordRegExp()) == 0
# Public: Prevents this cursor from causing scrolling.
clearAutoscroll: ->
@@ -189,7 +189,7 @@ class Cursor
# Public: Returns the cursor's current buffer row of text excluding its line
# ending.
getCurrentBufferLine: ->
@editSession.lineForBufferRow(@getBufferRow())
@editor.lineForBufferRow(@getBufferRow())
# Public: Moves the cursor up one screen row.
moveUp: (rowCount = 1, {moveToEndOfSelection}={}) ->
@@ -248,7 +248,7 @@ class Cursor
# Public: Moves the cursor to the bottom of the buffer.
moveToBottom: ->
@setBufferPosition(@editSession.getEofBufferPosition())
@setBufferPosition(@editor.getEofBufferPosition())
# Public: Moves the cursor to the beginning of the screen line.
moveToBeginningOfLine: ->
@@ -258,7 +258,7 @@ class Cursor
# line.
moveToFirstCharacterOfLine: ->
{row, column} = @getScreenPosition()
screenline = @editSession.lineForScreenRow(row)
screenline = @editor.lineForScreenRow(row)
goalColumn = screenline.text.search(/\S/)
return if goalColumn == -1
@@ -272,7 +272,7 @@ class Cursor
position = @getBufferPosition()
scanRange = @getCurrentLineBufferRange()
endOfLeadingWhitespace = null
@editSession.scanInBufferRange /^[ \t]*/, scanRange, ({range}) =>
@editor.scanInBufferRange /^[ \t]*/, scanRange, ({range}) =>
endOfLeadingWhitespace = range.end
@setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position)
@@ -318,11 +318,11 @@ class Cursor
getBeginningOfCurrentWordBufferPosition: (options = {}) ->
allowPrevious = options.allowPrevious ? true
currentBufferPosition = @getBufferPosition()
previousNonBlankRow = @editSession.buffer.previousNonBlankRow(currentBufferPosition.row)
previousNonBlankRow = @editor.buffer.previousNonBlankRow(currentBufferPosition.row)
scanRange = [[previousNonBlankRow, 0], currentBufferPosition]
beginningOfWordPosition = null
@editSession.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp(options)), scanRange, ({range, stop}) =>
@editor.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp(options)), scanRange, ({range, stop}) =>
if range.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious
beginningOfWordPosition = range.start
if not beginningOfWordPosition?.isEqual(currentBufferPosition)
@@ -334,11 +334,11 @@ class Cursor
# the current word, or the previous word.
getPreviousWordBoundaryBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
previousNonBlankRow = @editSession.buffer.previousNonBlankRow(currentBufferPosition.row)
previousNonBlankRow = @editor.buffer.previousNonBlankRow(currentBufferPosition.row)
scanRange = [[previousNonBlankRow, 0], currentBufferPosition]
beginningOfWordPosition = null
@editSession.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
@editor.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
if range.start.row < currentBufferPosition.row and currentBufferPosition.column > 0
# force it to stop at the beginning of each line
beginningOfWordPosition = new Point(currentBufferPosition.row, 0)
@@ -356,10 +356,10 @@ class Cursor
# the current word, or the previous word.
getMoveNextWordBoundaryBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()]
scanRange = [currentBufferPosition, @editor.getEofBufferPosition()]
endOfWordPosition = null
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
@editor.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
if range.start.row > currentBufferPosition.row
# force it to stop at the beginning of each line
endOfWordPosition = new Point(range.start.row, 0)
@@ -386,10 +386,10 @@ class Cursor
getEndOfCurrentWordBufferPosition: (options = {}) ->
allowNext = options.allowNext ? true
currentBufferPosition = @getBufferPosition()
scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()]
scanRange = [currentBufferPosition, @editor.getEofBufferPosition()]
endOfWordPosition = null
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp(options)), scanRange, ({range, stop}) =>
@editor.scanInBufferRange (options.wordRegex ? @wordRegExp(options)), scanRange, ({range, stop}) =>
if range.start.isLessThanOrEqual(currentBufferPosition) or allowNext
endOfWordPosition = range.end
if not endOfWordPosition?.isEqual(currentBufferPosition)
@@ -407,10 +407,10 @@ class Cursor
getBeginningOfNextWordBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
start = if @isInsideWord() then @getEndOfCurrentWordBufferPosition() else currentBufferPosition
scanRange = [start, @editSession.getEofBufferPosition()]
scanRange = [start, @editor.getEofBufferPosition()]
beginningOfNextWordPosition = null
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
@editor.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
beginningOfNextWordPosition = range.start
stop()
@@ -432,7 +432,7 @@ class Cursor
# + includeNewline:
# A boolean which controls whether the Range should include the newline.
getCurrentLineBufferRange: (options) ->
@editSession.bufferRangeForBufferRow(@getBufferRow(), options)
@editor.bufferRangeForBufferRow(@getBufferRow(), options)
# Public: Retrieves the range for the current paragraph.
#
@@ -440,11 +440,11 @@ class Cursor
#
# Returns a {Range}.
getCurrentParagraphBufferRange: ->
@editSession.languageMode.rowRangeForParagraphAtBufferRow(@getBufferRow())
@editor.languageMode.rowRangeForParagraphAtBufferRow(@getBufferRow())
# Public: Returns the characters preceeding the cursor in the current word.
getCurrentWordPrefix: ->
@editSession.getTextInBufferRange([@getBeginningOfCurrentWordBufferPosition(), @getBufferPosition()])
@editor.getTextInBufferRange([@getBeginningOfCurrentWordBufferPosition(), @getBufferPosition()])
# Public: Returns whether the cursor is at the start of a line.
isAtBeginningOfLine: ->
@@ -452,8 +452,8 @@ class Cursor
# Public: Returns the indentation level of the current line.
getIndentLevel: ->
if @editSession.getSoftTabs()
@getBufferColumn() / @editSession.getTabLength()
if @editor.getSoftTabs()
@getBufferColumn() / @editor.getTabLength()
else
@getBufferColumn()
@@ -465,13 +465,13 @@ class Cursor
#
# Returns an {Array} of {String}s.
getScopes: ->
@editSession.scopesForBufferPosition(@getBufferPosition())
@editor.scopesForBufferPosition(@getBufferPosition())
# Public: Returns true if this cursor has no non-whitespace characters before
# its current position.
hasPrecedingCharactersOnLine: ->
bufferPosition = @getBufferPosition()
line = @editSession.lineForBufferRow(bufferPosition.row)
line = @editor.lineForBufferRow(bufferPosition.row)
firstCharacterColumn = line.search(/\S/)
if firstCharacterColumn is -1

File diff suppressed because it is too large Load Diff

1854
src/editor-view.coffee Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
{Range} = require 'telepath'
_ = require 'underscore-plus'
# Private: Represents the portion of the {Editor} containing row numbers.
# Private: Represents the portion of the {EditorView} containing row numbers.
#
# The gutter also indicates if rows are folded.
module.exports =
@@ -25,37 +25,37 @@ class Gutter extends View
@attached = true
highlightLines = => @highlightLines()
@getEditor().on 'cursor:moved', highlightLines
@getEditor().on 'selection:changed', highlightLines
@getEditorView().on 'cursor:moved', highlightLines
@getEditorView().on 'selection:changed', highlightLines
@on 'mousedown', (e) => @handleMouseEvents(e)
beforeRemove: ->
$(document).off(".gutter-#{@getEditor().id}")
$(document).off(".gutter-#{@getEditorView().id}")
handleMouseEvents: (e) ->
editor = @getEditor()
startRow = editor.screenPositionFromMouseEvent(e).row
editorView = @getEditorView()
startRow = editorView.screenPositionFromMouseEvent(e).row
if e.shiftKey
editor.selectToScreenPosition([startRow + 1, 0])
editorView.selectToScreenPosition([startRow + 1, 0])
return
else
editor.getSelection().setScreenRange([[startRow, 0], [startRow, 0]])
editorView.getSelection().setScreenRange([[startRow, 0], [startRow, 0]])
moveHandler = (e) =>
start = startRow
end = editor.screenPositionFromMouseEvent(e).row
end = editorView.screenPositionFromMouseEvent(e).row
if end > start then end++ else start++
editor.getSelection().setScreenRange([[start, 0], [end, 0]])
editorView.getSelection().setScreenRange([[start, 0], [end, 0]])
$(document).on "mousemove.gutter-#{@getEditor().id}", moveHandler
$(document).one "mouseup.gutter-#{@getEditor().id}", => $(document).off 'mousemove', moveHandler
$(document).on "mousemove.gutter-#{@getEditorView().id}", moveHandler
$(document).one "mouseup.gutter-#{@getEditorView().id}", => $(document).off 'mousemove', moveHandler
### Public ###
# Retrieves the containing {Editor}.
# Retrieves the containing {EditorView}.
#
# Returns an {Editor}.
getEditor: ->
# Returns an {EditorView}.
getEditorView: ->
@parentView
# Defines whether to show the gutter or not.
@@ -192,9 +192,9 @@ class Gutter extends View
@elementBuilder.children
buildLineElementsHtml: (startScreenRow, endScreenRow) =>
editor = @getEditor()
maxDigits = editor.getLineCount().toString().length
rows = editor.bufferRowsForScreenRows(startScreenRow, endScreenRow)
editorView = @getEditorView()
maxDigits = editorView.getLineCount().toString().length
rows = editorView.bufferRowsForScreenRows(startScreenRow, endScreenRow)
html = ''
for row in rows
@@ -204,7 +204,7 @@ class Gutter extends View
rowValue = (row + 1).toString()
classes = "line-number line-number-#{row}"
classes += ' fold' if editor.isFoldedAtBufferRow(row)
classes += ' fold' if editorView.isFoldedAtBufferRow(row)
rowValuePadding = _.multiplyString('&nbsp;', maxDigits - rowValue.length)
@@ -230,8 +230,8 @@ class Gutter extends View
@highlightedLineNumbers.push(highlightedLineNumber)
highlightLines: ->
if @getEditor().getSelection().isEmpty()
row = @getEditor().getCursorScreenPosition().row
if @getEditorView().getSelection().isEmpty()
row = @getEditorView().getCursorScreenPosition().row
rowRange = new Range([row, 0], [row, 0])
return if @selectionEmpty and @highlightedRows?.isEqual(rowRange)
@@ -240,7 +240,7 @@ class Gutter extends View
@highlightedRows = rowRange
@selectionEmpty = true
else
selectedRows = @getEditor().getSelection().getScreenRange()
selectedRows = @getEditorView().getSelection().getScreenRange()
endRow = selectedRows.end.row
endRow-- if selectedRows.end.column is 0
selectedRows = new Range([selectedRows.start.row, 0], [endRow, 0])

View File

@@ -12,7 +12,7 @@ class LanguageMode
buffer: null
grammar: null
editSession: null
editor: null
currentGrammarScore: null
### Internal ###
@@ -22,11 +22,11 @@ class LanguageMode
### Public ###
# Sets up a `LanguageMode` for the given {EditSession}.
# Sets up a `LanguageMode` for the given {Editor}.
#
# editSession - The {EditSession} to associate with
constructor: (@editSession) ->
@buffer = @editSession.buffer
# editor - The {Editor} to associate with
constructor: (@editor) ->
@buffer = @editor.buffer
# Wraps the lines between two rows in comments.
#
@@ -37,7 +37,7 @@ class LanguageMode
#
# Returns an {Array} of the commented {Ranges}.
toggleLineCommentsForBufferRows: (start, end) ->
scopes = @editSession.scopesForBufferPosition([start, 0])
scopes = @editor.scopesForBufferPosition([start, 0])
properties = atom.syntax.propertiesForScope(scopes, "editor.commentStart")[0]
return unless properties
@@ -46,7 +46,7 @@ class LanguageMode
return unless commentStartString
buffer = @editSession.buffer
buffer = @editor.buffer
commentStartRegexString = _.escapeRegExp(commentStartString).replace(/(\s+)$/, '($1)?')
commentStartRegex = new OnigRegExp("^(\\s*)(#{commentStartRegexString})")
shouldUncomment = commentStartRegex.test(buffer.lineForRow(start))
@@ -83,8 +83,8 @@ class LanguageMode
buffer.change([[row, columnStart], [row, columnEnd]], "")
else
indent = @minIndentLevelForRowRange(start, end)
indentString = @editSession.buildIndentString(indent)
tabLength = @editSession.getTabLength()
indentString = @editor.buildIndentString(indent)
tabLength = @editor.getTabLength()
indentRegex = new RegExp("(\t|[ ]{#{tabLength}}){#{Math.floor(indent)}}")
for row in [start..end]
line = buffer.lineForRow(row)
@@ -98,12 +98,12 @@ class LanguageMode
for currentRow in [0..@buffer.getLastRow()]
[startRow, endRow] = @rowRangeForFoldAtBufferRow(currentRow) ? []
continue unless startRow?
@editSession.createFold(startRow, endRow)
@editor.createFold(startRow, endRow)
# Unfolds all the foldable lines in the buffer.
unfoldAll: ->
for row in [@buffer.getLastRow()..0]
fold.destroy() for fold in @editSession.displayBuffer.foldsStartingAtBufferRow(row)
fold.destroy() for fold in @editor.displayBuffer.foldsStartingAtBufferRow(row)
# Fold all comment and code blocks at a given indentLevel
#
@@ -114,8 +114,8 @@ class LanguageMode
continue unless startRow?
# assumption: startRow will always be the min indent level for the entire range
if @editSession.indentationForBufferRow(startRow) == indentLevel
@editSession.createFold(startRow, endRow)
if @editor.indentationForBufferRow(startRow) == indentLevel
@editor.createFold(startRow, endRow)
# Given a buffer row, creates a fold at it.
#
@@ -126,14 +126,14 @@ class LanguageMode
for currentRow in [bufferRow..0]
[startRow, endRow] = @rowRangeForFoldAtBufferRow(currentRow) ? []
continue unless startRow? and startRow <= bufferRow <= endRow
fold = @editSession.displayBuffer.largestFoldStartingAtBufferRow(startRow)
return @editSession.createFold(startRow, endRow) unless fold
fold = @editor.displayBuffer.largestFoldStartingAtBufferRow(startRow)
return @editor.createFold(startRow, endRow) unless fold
# Given a buffer row, this unfolds it.
#
# bufferRow - A {Number} indicating the buffer row
unfoldBufferRow: (bufferRow) ->
@editSession.displayBuffer.largestFoldContainingBufferRow(bufferRow)?.destroy()
@editor.displayBuffer.largestFoldContainingBufferRow(bufferRow)?.destroy()
# Find the row range for a fold at a given bufferRow. Will handle comments
# and code.
@@ -147,30 +147,30 @@ class LanguageMode
rowRange
rowRangeForCommentAtBufferRow: (bufferRow) ->
return unless @editSession.displayBuffer.tokenizedBuffer.lineForScreenRow(bufferRow).isComment()
return unless @editor.displayBuffer.tokenizedBuffer.lineForScreenRow(bufferRow).isComment()
startRow = bufferRow
for currentRow in [bufferRow-1..0]
break if @buffer.isRowBlank(currentRow)
break unless @editSession.displayBuffer.tokenizedBuffer.lineForScreenRow(currentRow).isComment()
break unless @editor.displayBuffer.tokenizedBuffer.lineForScreenRow(currentRow).isComment()
startRow = currentRow
endRow = bufferRow
for currentRow in [bufferRow+1..@buffer.getLastRow()]
break if @buffer.isRowBlank(currentRow)
break unless @editSession.displayBuffer.tokenizedBuffer.lineForScreenRow(currentRow).isComment()
break unless @editor.displayBuffer.tokenizedBuffer.lineForScreenRow(currentRow).isComment()
endRow = currentRow
return [startRow, endRow] if startRow isnt endRow
rowRangeForCodeFoldAtBufferRow: (bufferRow) ->
return null unless @doesBufferRowStartFold(bufferRow)
startIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
for row in [(bufferRow + 1)..@editSession.getLastBufferRow()]
continue if @editSession.isBufferRowBlank(row)
indentation = @editSession.indentationForBufferRow(row)
startIndentLevel = @editor.indentationForBufferRow(bufferRow)
scopes = @editor.scopesForBufferPosition([bufferRow, 0])
for row in [(bufferRow + 1)..@editor.getLastBufferRow()]
continue if @editor.isBufferRowBlank(row)
indentation = @editor.indentationForBufferRow(row)
if indentation <= startIndentLevel
includeRowInFold = indentation == startIndentLevel and @foldEndRegexForScopes(scopes)?.search(@editSession.lineForBufferRow(row))
includeRowInFold = indentation == startIndentLevel and @foldEndRegexForScopes(scopes)?.search(@editor.lineForBufferRow(row))
foldEndRow = row if includeRowInFold
break
@@ -179,19 +179,19 @@ class LanguageMode
[bufferRow, foldEndRow]
doesBufferRowStartFold: (bufferRow) ->
return false if @editSession.isBufferRowBlank(bufferRow)
nextNonEmptyRow = @editSession.nextNonBlankBufferRow(bufferRow)
return false if @editor.isBufferRowBlank(bufferRow)
nextNonEmptyRow = @editor.nextNonBlankBufferRow(bufferRow)
return false unless nextNonEmptyRow?
@editSession.indentationForBufferRow(nextNonEmptyRow) > @editSession.indentationForBufferRow(bufferRow)
@editor.indentationForBufferRow(nextNonEmptyRow) > @editor.indentationForBufferRow(bufferRow)
# Find a row range for a 'paragraph' around specified bufferRow.
# Right now, a paragraph is a block of text bounded by and empty line or a
# block of text that is not the same type (comments next to source code).
rowRangeForParagraphAtBufferRow: (bufferRow) ->
return unless /\w/.test(@editSession.lineForBufferRow(bufferRow))
return unless /\w/.test(@editor.lineForBufferRow(bufferRow))
isRowComment = (row) =>
@editSession.displayBuffer.tokenizedBuffer.lineForScreenRow(row).isComment()
@editor.displayBuffer.tokenizedBuffer.lineForScreenRow(row).isComment()
if isRowComment(bufferRow)
isOriginalRowComment = true
@@ -199,22 +199,22 @@ class LanguageMode
[firstRow, lastRow] = range or [bufferRow, bufferRow]
else
isOriginalRowComment = false
[firstRow, lastRow] = [0, @editSession.getLastBufferRow()-1]
[firstRow, lastRow] = [0, @editor.getLastBufferRow()-1]
startRow = bufferRow
while startRow > firstRow
break if isRowComment(startRow - 1) != isOriginalRowComment
break unless /\w/.test(@editSession.lineForBufferRow(startRow - 1))
break unless /\w/.test(@editor.lineForBufferRow(startRow - 1))
startRow--
endRow = bufferRow
lastRow = @editSession.getLastBufferRow()
lastRow = @editor.getLastBufferRow()
while endRow < lastRow
break if isRowComment(endRow + 1) != isOriginalRowComment
break unless /\w/.test(@editSession.lineForBufferRow(endRow + 1))
break unless /\w/.test(@editor.lineForBufferRow(endRow + 1))
endRow++
new Range([startRow, 0], [endRow, @editSession.lineLengthForBufferRow(endRow)])
new Range([startRow, 0], [endRow, @editor.lineLengthForBufferRow(endRow)])
# Given a buffer row, this returns a suggested indentation level.
#
@@ -224,8 +224,8 @@ class LanguageMode
#
# Returns a {Number}.
suggestedIndentForBufferRow: (bufferRow) ->
currentIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
currentIndentLevel = @editor.indentationForBufferRow(bufferRow)
scopes = @editor.scopesForBufferPosition([bufferRow, 0])
return currentIndentLevel unless increaseIndentRegex = @increaseIndentRegexForScopes(scopes)
currentLine = @buffer.lineForRow(bufferRow)
@@ -233,8 +233,8 @@ class LanguageMode
return currentIndentLevel unless precedingRow?
precedingLine = @buffer.lineForRow(precedingRow)
desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow)
desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine) and not @editSession.isBufferRowCommented(precedingRow)
desiredIndentLevel = @editor.indentationForBufferRow(precedingRow)
desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine) and not @editor.isBufferRowCommented(precedingRow)
return desiredIndentLevel unless decreaseIndentRegex = @decreaseIndentRegexForScopes(scopes)
desiredIndentLevel -= 1 if decreaseIndentRegex.test(currentLine)
@@ -248,7 +248,7 @@ class LanguageMode
#
# Returns a {Number} of the indent level of the block of lines.
minIndentLevelForRowRange: (startRow, endRow) ->
indents = (@editSession.indentationForBufferRow(row) for row in [startRow..endRow] when not @editSession.isBufferRowBlank(row))
indents = (@editor.indentationForBufferRow(row) for row in [startRow..endRow] when not @editor.isBufferRowBlank(row))
indents = [0] unless indents.length
Math.min(indents...)
@@ -264,13 +264,13 @@ class LanguageMode
# bufferRow - The row {Number}
autoIndentBufferRow: (bufferRow) ->
indentLevel = @suggestedIndentForBufferRow(bufferRow)
@editSession.setIndentationForBufferRow(bufferRow, indentLevel)
@editor.setIndentationForBufferRow(bufferRow, indentLevel)
# Given a buffer row, this decreases the indentation.
#
# bufferRow - The row {Number}
autoDecreaseIndentForBufferRow: (bufferRow) ->
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
scopes = @editor.scopesForBufferPosition([bufferRow, 0])
increaseIndentRegex = @increaseIndentRegexForScopes(scopes)
decreaseIndentRegex = @decreaseIndentRegexForScopes(scopes)
return unless increaseIndentRegex and decreaseIndentRegex
@@ -278,16 +278,16 @@ class LanguageMode
line = @buffer.lineForRow(bufferRow)
return unless decreaseIndentRegex.test(line)
currentIndentLevel = @editSession.indentationForBufferRow(bufferRow)
currentIndentLevel = @editor.indentationForBufferRow(bufferRow)
return if currentIndentLevel is 0
precedingRow = @buffer.previousNonBlankRow(bufferRow)
return unless precedingRow?
precedingLine = @buffer.lineForRow(precedingRow)
desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow)
desiredIndentLevel = @editor.indentationForBufferRow(precedingRow)
desiredIndentLevel -= 1 unless increaseIndentRegex.test(precedingLine)
if desiredIndentLevel >= 0 and desiredIndentLevel < currentIndentLevel
@editSession.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
@editor.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
tokenizeLine: (line, stack, firstLine) ->
{tokens, stack} = @grammar.tokenizeLine(line, stack, firstLine)

View File

@@ -7,7 +7,7 @@ PaneColumn = require './pane-column'
# Public: A container which can contains multiple items to be switched between.
#
# Items can be almost anything however most commonly they're {Editor}s.
# Items can be almost anything however most commonly they're {EditorView}s.
#
# Most packages won't need to use this class, unless you're interested in
# building a package that deals with switching between panes or tiems.

View File

@@ -7,7 +7,7 @@ Q = require 'q'
telepath = require 'telepath'
TextBuffer = require './text-buffer'
EditSession = require './edit-session'
Editor = require './editor'
{Emitter} = require 'emissary'
Directory = require './directory'
Task = require './task'
@@ -37,7 +37,7 @@ class Project extends telepath.Model
buffer.once 'destroyed', => @removeBuffer(buffer)
@openers = []
@editSessions = []
@editors = []
@setPath(@path)
# Private: Called by telepath.
@@ -52,7 +52,7 @@ class Project extends telepath.Model
# Private:
destroy: ->
editSession.destroy() for editSession in @getEditSessions()
editor.destroy() for editor in @getEditSessions()
buffer.release() for buffer in @getBuffers()
@destroyRepo()
@@ -133,14 +133,14 @@ class Project extends telepath.Model
@rootDirectory?.contains(pathToCheck) ? false
# Public: Given a path to a file, this constructs and associates a new
# {EditSession}, showing the file.
# {Editor}, showing the file.
#
# * filePath:
# The {String} path of the file to associate with
# * editSessionOptions:
# Options that you can pass to the {EditSession} constructor
# * options:
# Options that you can pass to the {Editor} constructor
#
# Returns a promise that resolves to an {EditSession}.
# Returns a promise that resolves to an {Editor}.
open: (filePath, options={}) ->
filePath = @resolve(filePath)
resource = null
@@ -160,20 +160,20 @@ class Project extends telepath.Model
@buildEditSessionForBuffer(@bufferForPathSync(filePath), options)
# Public: Retrieves all {EditSession}s for all open files.
# Public: Retrieves all {Editor}s for all open files.
#
# Returns an {Array} of {EditSession}s.
# Returns an {Array} of {Editor}s.
getEditSessions: ->
new Array(@editSessions...)
new Array(@editors...)
# Public: Add the given {EditSession}.
addEditSession: (editSession) ->
@editSessions.push editSession
@emit 'edit-session-created', editSession
# Public: Add the given {Editor}.
addEditSession: (editor) ->
@editors.push editor
@emit 'editor-created', editor
# Public: Return and removes the given {EditSession}.
removeEditSession: (editSession) ->
_.remove(@editSessions, editSession)
# Public: Return and removes the given {Editor}.
removeEditSession: (editor) ->
_.remove(@editors, editor)
# Private: Retrieves all the {TextBuffer}s in the project; that is, the
# buffers for all open files.
@@ -331,15 +331,15 @@ class Project extends telepath.Model
deferred.promise
# Private:
buildEditSessionForBuffer: (buffer, editSessionOptions) ->
editSession = new EditSession(_.extend({buffer}, editSessionOptions))
@addEditSession(editSession)
editSession
buildEditSessionForBuffer: (buffer, editorOptions) ->
editor = new Editor(_.extend({buffer}, editorOptions))
@addEditSession(editor)
editor
# Private:
eachEditSession: (callback) ->
callback(editSession) for editSession in @getEditSessions()
@on 'edit-session-created', (editSession) -> callback(editSession)
callback(editor) for editor in @getEditSessions()
@on 'editor-created', (editor) -> callback(editor)
# Private:
eachBuffer: (args...) ->

View File

@@ -5,12 +5,12 @@ Q = require 'q'
_ = require 'underscore-plus'
fs = require 'fs-plus'
telepath = require 'telepath'
Editor = require './editor'
EditorView = require './editor-view'
Pane = require './pane'
PaneColumn = require './pane-column'
PaneRow = require './pane-row'
PaneContainer = require './pane-container'
EditSession = require './edit-session'
Editor = require './editor'
# Public: The container for the entire Atom application.
#
@@ -38,7 +38,7 @@ EditSession = require './edit-session'
#
module.exports =
class RootView extends View
registerDeserializers(this, Pane, PaneRow, PaneColumn, Editor)
registerDeserializers(this, Pane, PaneRow, PaneColumn, EditorView)
@version: 1
@@ -169,26 +169,26 @@ class RootView extends View
# * options
# + initialLine: The buffer line number to open to.
#
# Returns a promise that resolves to the {EditSession} for the file URI.
# Returns a promise that resolves to the {Editor} for the file URI.
open: (filePath, options={}) ->
changeFocus = options.changeFocus ? true
filePath = project.resolve(filePath)
initialLine = options.initialLine
activePane = @getActivePane()
editSession = activePane.itemForUri(project.relativize(filePath)) if activePane and filePath
promise = project.open(filePath, {initialLine}) if not editSession
editor = activePane.itemForUri(project.relativize(filePath)) if activePane and filePath
promise = project.open(filePath, {initialLine}) if not editor
Q(editSession ? promise)
.then (editSession) =>
Q(editor ? promise)
.then (editor) =>
if not activePane
activePane = new Pane(editSession)
activePane = new Pane(editor)
@panes.setRoot(activePane)
activePane.showItem(editSession)
activePane.showItem(editor)
activePane.focus() if changeFocus
@trigger "uri-opened"
editSession
editor
.catch (error) ->
console.error(error.stack ? error)
@@ -249,7 +249,7 @@ class RootView extends View
setTitle: (title) ->
document.title = title
# Private: Returns an Array of all of the application's {Editor}s.
# Private: Returns an Array of all of the application's {EditorView}s.
getEditors: ->
@panes.find('.pane > .item-views > .editor').map(-> $(this).view()).toArray()
@@ -259,7 +259,7 @@ class RootView extends View
getModifiedBuffers: ->
modifiedBuffers = []
for pane in @getPanes()
for item in pane.getItems() when item instanceof EditSession
for item in pane.getItems() when item instanceof Editor
modifiedBuffers.push item.buffer if item.buffer.isModified()
modifiedBuffers
@@ -267,7 +267,7 @@ class RootView extends View
#
# Returns an {Array} of {String}s.
getOpenBufferPaths: ->
_.uniq(_.flatten(@getEditors().map (editor) -> editor.getOpenBufferPaths()))
_.uniq(_.flatten(@getEditors().map (editorView) -> editorView.getOpenBufferPaths()))
# Public: Returns the currently focused {Pane}.
getActivePane: ->
@@ -308,14 +308,14 @@ class RootView extends View
indexOfPane: (pane) ->
@panes.indexOfPane(pane)
# Private: Fires a callback on each open {Editor}.
# Private: Fires a callback on each open {EditorView}.
eachEditor: (callback) ->
callback(editor) for editor in @getEditors()
attachedCallback = (e, editor) -> callback(editor)
@on('editor:attached', attachedCallback)
off: => @off('editor:attached', attachedCallback)
# Public: Fires a callback on each open {EditSession}.
# Public: Fires a callback on each open {Editor}.
eachEditSession: (callback) ->
project.eachEditSession(callback)
@@ -325,6 +325,6 @@ class RootView extends View
# Private: Destroys everything.
remove: ->
editor.remove() for editor in @getEditors()
editorView.remove() for editorView in @getEditors()
project?.destroy()
super

View File

@@ -1,5 +1,5 @@
{$, View} = require './space-pen-extensions'
Editor = require './editor'
EditorView = require './editor-view'
fuzzyFilter = require('fuzzaldrin').filter
# Public: Provides a widget for users to make a selection from a list of
@@ -10,7 +10,7 @@ class SelectList extends View
# Private:
@content: ->
@div class: @viewClass(), =>
@subview 'miniEditor', new Editor(mini: true)
@subview 'miniEditor', new EditorView(mini: true)
@div class: 'error-message', outlet: 'error'
@div class: 'loading', outlet: 'loadingArea', =>
@span class: 'loading-message', outlet: 'loading'

View File

@@ -11,12 +11,12 @@ class SelectionView extends View
regions: null
needsRemoval: false
initialize: ({@editor, @selection} = {}) ->
initialize: ({@editorView, @selection} = {}) ->
@regions = []
@selection.on 'screen-range-changed', => @editor.requestDisplayUpdate()
@selection.on 'screen-range-changed', => @editorView.requestDisplayUpdate()
@selection.on 'destroyed', =>
@needsRemoval = true
@editor.requestDisplayUpdate()
@editorView.requestDisplayUpdate()
if @selection.marker.isRemote()
@addClass("site-#{@selection.marker.getOriginSiteId()}")
@@ -26,7 +26,7 @@ class SelectionView extends View
range = @getScreenRange()
@trigger 'selection:changed'
@editor.highlightFoldsContainingBufferRange(@getBufferRange())
@editorView.highlightFoldsContainingBufferRange(@getBufferRange())
return if range.isEmpty()
rowSpan = range.end.row - range.start.row
@@ -40,11 +40,11 @@ class SelectionView extends View
@appendRegion(1, { row: range.end.row, column: 0 }, range.end)
appendRegion: (rows, start, end) ->
{ lineHeight, charWidth } = @editor
css = @editor.pixelPositionForScreenPosition(start)
{ lineHeight, charWidth } = @editorView
css = @editorView.pixelPositionForScreenPosition(start)
css.height = lineHeight * rows
if end
css.width = @editor.pixelPositionForScreenPosition(end).left - css.left
css.width = @editorView.pixelPositionForScreenPosition(end).left - css.left
else
css.right = 0
@@ -57,7 +57,7 @@ class SelectionView extends View
startRow = start.row
endRow = end.row
endRow-- if end.column == 0
@editor.pixelPositionForScreenPosition([((startRow + endRow + 1) / 2), start.column])
@editorView.pixelPositionForScreenPosition([((startRow + endRow + 1) / 2), start.column])
clearRegions: ->
region.remove() for region in @regions
@@ -85,5 +85,5 @@ class SelectionView extends View
@removeClass('highlighted')
remove: ->
@editor.removeSelectionView(this)
@editorView.removeSelectionView(this)
super

View File

@@ -2,27 +2,27 @@
{Emitter} = require 'emissary'
{pick} = require 'underscore-plus'
# Public: Represents a selection in the {EditSession}.
# Public: Represents a selection in the {Editor}.
module.exports =
class Selection
Emitter.includeInto(this)
cursor: null
marker: null
editSession: null
editor: null
initialScreenRange: null
wordwise: false
needsAutoscroll: null
# Private:
constructor: ({@cursor, @marker, @editSession}) ->
constructor: ({@cursor, @marker, @editor}) ->
@cursor.selection = this
@marker.on 'changed', => @screenRangeChanged()
@marker.on 'destroyed', =>
@destroyed = true
@editSession.removeSelection(this)
@emit 'destroyed' unless @editSession.destroyed
@editor.removeSelection(this)
@emit 'destroyed' unless @editor.destroyed
# Private:
destroy: ->
@@ -65,7 +65,7 @@ class Selection
# * options:
# + A hash of options matching those found in {.setBufferRange}
setScreenRange: (screenRange, options) ->
@setBufferRange(@editSession.bufferRangeForScreenRange(screenRange), options)
@setBufferRange(@editor.bufferRangeForScreenRange(screenRange), options)
# Public: Returns the buffer {Range} for the selection.
getBufferRange: ->
@@ -79,12 +79,12 @@ class Selection
# + preserveFolds:
# if `true`, the fold settings are preserved after the selection moves
# + autoscroll:
# if `true`, the {EditSession} scrolls to the new selection
# if `true`, the {Editor} scrolls to the new selection
setBufferRange: (bufferRange, options={}) ->
bufferRange = Range.fromObject(bufferRange)
@needsAutoscroll = options.autoscroll
options.isReversed ?= @isReversed()
@editSession.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@editor.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
@modifySelection =>
@cursor.needsAutoscroll = false if options.autoscroll?
@marker.setBufferRange(bufferRange, options)
@@ -102,7 +102,7 @@ class Selection
# Public: Returns the text in the selection.
getText: ->
@editSession.buffer.getTextInRange(@getBufferRange())
@editor.buffer.getTextInRange(@getBufferRange())
# Public: Clears the selection, moving the marker to the head.
clear: ->
@@ -132,7 +132,7 @@ class Selection
# * row:
# The line Number to select (default: the row of the cursor)
selectLine: (row=@cursor.getBufferPosition().row) ->
range = @editSession.bufferRangeForBufferRow(row, includeNewline: true)
range = @editor.bufferRangeForBufferRow(row, includeNewline: true)
@setBufferRange(range)
@linewise = true
@wordwise = false
@@ -202,7 +202,7 @@ class Selection
# Public: Selects all the text in the buffer.
selectAll: ->
@setBufferRange(@editSession.buffer.getRange(), autoscroll: false)
@setBufferRange(@editor.buffer.getRange(), autoscroll: false)
# Public: Selects all the text from the current cursor position to the
# beginning of the line.
@@ -247,17 +247,17 @@ class Selection
range = (@getGoalBufferRange() ? @getBufferRange()).copy()
nextRow = range.end.row + 1
for row in [nextRow..@editSession.getLastBufferRow()]
for row in [nextRow..@editor.getLastBufferRow()]
range.start.row = row
range.end.row = row
clippedRange = @editSession.clipBufferRange(range)
clippedRange = @editor.clipBufferRange(range)
if range.isEmpty()
continue if range.end.column > 0 and clippedRange.end.column is 0
else
continue if clippedRange.isEmpty()
@editSession.addSelectionForBufferRange(range, goalBufferRange: range)
@editor.addSelectionForBufferRange(range, goalBufferRange: range)
break
# Public:
@@ -274,14 +274,14 @@ class Selection
for row in [previousRow..0]
range.start.row = row
range.end.row = row
clippedRange = @editSession.clipBufferRange(range)
clippedRange = @editor.clipBufferRange(range)
if range.isEmpty()
continue if range.end.column > 0 and clippedRange.end.column is 0
else
continue if clippedRange.isEmpty()
@editSession.addSelectionForBufferRange(range, goalBufferRange: range)
@editor.addSelectionForBufferRange(range, goalBufferRange: range)
break
# Public: Replaces text at the current selection.
@@ -302,7 +302,7 @@ class Selection
# if `skip`, skips the undo stack for this operation.
insertText: (text, options={}) ->
oldBufferRange = @getBufferRange()
@editSession.destroyFoldsContainingBufferRow(oldBufferRange.end.row)
@editor.destroyFoldsContainingBufferRow(oldBufferRange.end.row)
wasReversed = @isReversed()
@clear()
@cursor.needsAutoscroll = @cursor.isLastCursor()
@@ -310,18 +310,18 @@ class Selection
if options.indentBasis? and not options.autoIndent
text = @normalizeIndents(text, options.indentBasis)
newBufferRange = @editSession.buffer.change(oldBufferRange, text, pick(options, 'undo'))
newBufferRange = @editor.buffer.change(oldBufferRange, text, pick(options, 'undo'))
if options.select
@setBufferRange(newBufferRange, isReversed: wasReversed)
else
@cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed
if options.autoIndent
@editSession.autoIndentBufferRow(row) for row in newBufferRange.getRows()
@editor.autoIndentBufferRow(row) for row in newBufferRange.getRows()
else if options.autoIndentNewline and text == '\n'
@editSession.autoIndentBufferRow(newBufferRange.end.row)
@editor.autoIndentBufferRow(newBufferRange.end.row)
else if options.autoDecreaseIndent and /\S/.test text
@editSession.autoDecreaseIndentForBufferRow(newBufferRange.start.row)
@editor.autoDecreaseIndentForBufferRow(newBufferRange.start.row)
newBufferRange
@@ -336,9 +336,9 @@ class Selection
isCursorInsideExistingLine = /\S/.test(textPrecedingCursor)
lines = text.split('\n')
firstLineIndentLevel = @editSession.indentLevelForLine(lines[0])
firstLineIndentLevel = @editor.indentLevelForLine(lines[0])
if isCursorInsideExistingLine
minimumIndentLevel = @editSession.indentationForBufferRow(@cursor.getBufferRow())
minimumIndentLevel = @editor.indentationForBufferRow(@cursor.getBufferRow())
else
minimumIndentLevel = @cursor.getIndentLevel()
@@ -349,7 +349,7 @@ class Selection
else if line == '' # remove all indentation from empty lines
indentLevel = 0
else
lineIndentLevel = @editSession.indentLevelForLine(lines[i])
lineIndentLevel = @editor.indentLevelForLine(lines[i])
indentLevel = minimumIndentLevel + (lineIndentLevel - indentBasis)
normalizedLines.push(@setIndentationForLine(line, indentLevel))
@@ -361,19 +361,19 @@ class Selection
# * options - A hash with one key,
# + autoIndent:
# If `true`, the indentation is performed appropriately. Otherwise,
# {EditSession.getTabText} is used
# {Editor.getTabText} is used
indent: ({ autoIndent }={})->
{ row, column } = @cursor.getBufferPosition()
if @isEmpty()
@cursor.skipLeadingWhitespace()
desiredIndent = @editSession.suggestedIndentForBufferRow(row)
desiredIndent = @editor.suggestedIndentForBufferRow(row)
delta = desiredIndent - @cursor.getIndentLevel()
if autoIndent and delta > 0
@insertText(@editSession.buildIndentString(delta))
@insertText(@editor.buildIndentString(delta))
else
@insertText(@editSession.getTabText())
@insertText(@editor.getTabText())
else
@indentSelectedRows()
@@ -381,18 +381,18 @@ class Selection
indentSelectedRows: ->
[start, end] = @getBufferRowRange()
for row in [start..end]
@editSession.buffer.insert([row, 0], @editSession.getTabText()) unless @editSession.buffer.lineLengthForRow(row) == 0
@editor.buffer.insert([row, 0], @editor.getTabText()) unless @editor.buffer.lineLengthForRow(row) == 0
# Public: ?
setIndentationForLine: (line, indentLevel) ->
desiredIndentLevel = Math.max(0, indentLevel)
desiredIndentString = @editSession.buildIndentString(desiredIndentLevel)
desiredIndentString = @editor.buildIndentString(desiredIndentLevel)
line.replace(/^[\t ]*/, desiredIndentString)
# Public: Removes the first character before the selection if the selection
# is empty otherwise it deletes the selection.
backspace: ->
@selectLeft() if @isEmpty() and not @editSession.isFoldedAtScreenRow(@cursor.getScreenRow())
@selectLeft() if @isEmpty() and not @editor.isFoldedAtScreenRow(@cursor.getScreenRow())
@deleteSelectedText()
# Public: Removes from the start of the selection to the beginning of the
@@ -414,7 +414,7 @@ class Selection
# selection if the selection is empty.
delete: ->
if @isEmpty()
if @cursor.isAtEndOfLine() and fold = @editSession.largestFoldStartingAtScreenRow(@cursor.getScreenRow() + 1)
if @cursor.isAtEndOfLine() and fold = @editor.largestFoldStartingAtScreenRow(@cursor.getScreenRow() + 1)
@selectToBufferPosition(fold.getBufferRange().end)
else
@selectRight()
@@ -429,9 +429,9 @@ class Selection
# Public: Removes only the selected text.
deleteSelectedText: ->
bufferRange = @getBufferRange()
if bufferRange.isEmpty() and fold = @editSession.largestFoldContainingBufferRow(bufferRange.start.row)
if bufferRange.isEmpty() and fold = @editor.largestFoldContainingBufferRow(bufferRange.start.row)
bufferRange = bufferRange.union(fold.getBufferRange(includeNewline: true))
@editSession.buffer.delete(bufferRange) unless bufferRange.isEmpty()
@editor.buffer.delete(bufferRange) unless bufferRange.isEmpty()
@cursor?.setBufferPosition(bufferRange.start)
# Public: Removes the line at the beginning of the selection if the selection
@@ -440,18 +440,18 @@ class Selection
deleteLine: ->
if @isEmpty()
start = @cursor.getScreenRow()
range = @editSession.bufferRowsForScreenRows(start, start + 1)
range = @editor.bufferRowsForScreenRows(start, start + 1)
if range[1] > range[0]
@editSession.buffer.deleteRows(range[0], range[1] - 1)
@editor.buffer.deleteRows(range[0], range[1] - 1)
else
@editSession.buffer.deleteRow(range[0])
@editor.buffer.deleteRow(range[0])
else
range = @getBufferRange()
start = range.start.row
end = range.end.row
if end isnt @editSession.buffer.getLastRow() and range.end.column is 0
if end isnt @editor.buffer.getLastRow() and range.end.column is 0
end--
@editSession.buffer.deleteRows(start, end)
@editor.buffer.deleteRows(start, end)
# Public: Joins the current line with the one below it.
#
@@ -459,16 +459,16 @@ class Selection
joinLine: ->
selectedRange = @getBufferRange()
if selectedRange.isEmpty()
return if selectedRange.start.row is @editSession.buffer.getLastRow()
return if selectedRange.start.row is @editor.buffer.getLastRow()
else
joinMarker = @editSession.markBufferRange(selectedRange, invalidationStrategy: 'never')
joinMarker = @editor.markBufferRange(selectedRange, invalidationStrategy: 'never')
rowCount = Math.max(1, selectedRange.getRowCount() - 1)
for row in [0...rowCount]
@cursor.setBufferPosition([selectedRange.start.row])
@cursor.moveToEndOfLine()
nextRow = selectedRange.start.row + 1
if nextRow <= @editSession.buffer.getLastRow() and @editSession.buffer.lineLengthForRow(nextRow) > 0
if nextRow <= @editor.buffer.getLastRow() and @editor.buffer.lineLengthForRow(nextRow) > 0
@insertText(' ')
@cursor.moveToEndOfLine()
@modifySelection =>
@@ -484,8 +484,8 @@ class Selection
# Public: Removes one level of indent from the currently selected rows.
outdentSelectedRows: ->
[start, end] = @getBufferRowRange()
buffer = @editSession.buffer
leadingTabRegex = new RegExp("^ {1,#{@editSession.getTabLength()}}|\t")
buffer = @editor.buffer
leadingTabRegex = new RegExp("^ {1,#{@editor.getTabLength()}}|\t")
for row in [start..end]
if matchLength = buffer.lineForRow(row).match(leadingTabRegex)?[0].length
buffer.delete [[row, 0], [row, matchLength]]
@@ -494,7 +494,7 @@ class Selection
# by the relevant grammars.
autoIndentSelectedRows: ->
[start, end] = @getBufferRowRange()
@editSession.autoIndentBufferRows(start, end)
@editor.autoIndentBufferRows(start, end)
# Public: Wraps the selected lines in comments if they aren't currently part
# of a comment.
@@ -503,7 +503,7 @@ class Selection
#
# Returns an Array of the commented {Range}s.
toggleLineComments: ->
@editSession.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
@editor.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
# Public: Cuts the selection until the end of the line.
#
@@ -527,19 +527,19 @@ class Selection
# ?
copy: (maintainPasteboard=false) ->
return if @isEmpty()
text = @editSession.buffer.getTextInRange(@getBufferRange())
text = @editor.buffer.getTextInRange(@getBufferRange())
if maintainPasteboard
[currentText, metadata] = atom.pasteboard.read()
text = currentText + '\n' + text
else
metadata = { indentBasis: @editSession.indentationForBufferRow(@getBufferRange().start.row) }
metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) }
atom.pasteboard.write(text, metadata)
# Public: Creates a fold containing the current selection.
fold: ->
range = @getBufferRange()
@editSession.createFold(range.start.row, range.end.row)
@editor.createFold(range.start.row, range.end.row)
@cursor.setBufferPosition([range.end.row + 1, 0])
# Public: ?

View File

@@ -126,12 +126,12 @@ class TextBuffer extends telepath.Model
# Identifies if the buffer belongs to multiple editors.
#
# For example, if the {Editor} was split.
# For example, if the {EditorView} was split.
#
# Returns a {Boolean}.
hasMultipleEditors: -> @refcount > 1
# Reloads a file in the {EditSession}.
# Reloads a file in the {Editor}.
#
# Sets the buffer's content to the cached disk contents
reload: ->

View File

@@ -49,7 +49,7 @@ window.startEditorWindow = ->
atom.restoreDimensions()
atom.config.load()
atom.config.setDefaults('core', require('./root-view').configDefaults)
atom.config.setDefaults('editor', require('./editor').configDefaults)
atom.config.setDefaults('editor', require('./editor-view').configDefaults)
atom.keymap.loadBundledKeymaps()
atom.themes.loadBaseStylesheets()
atom.packages.loadPackages()