Replace @buffer reference on Editor with @getBuffer method

This commit is contained in:
Nathan Sobo
2012-07-04 12:27:30 -06:00
parent fb6aa46531
commit c90c2e80d6
23 changed files with 163 additions and 169 deletions

View File

@@ -38,7 +38,6 @@ class Editor extends View
charHeight: null
cursorViews: null
selectionViews: null
buffer: null
lineCache: null
isFocused: false
activeEditSession: null
@@ -246,16 +245,16 @@ class Editor extends View
bufferRowsForScreenRows: (startRow, endRow) -> @activeEditSession.bufferRowsForScreenRows(startRow, endRow)
stateForScreenRow: (row) -> @activeEditSession.stateForScreenRow(row)
setText: (text) -> @buffer.setText(text)
getText: -> @buffer.getText()
getLastBufferRow: -> @buffer.getLastRow()
getTextInRange: (range) -> @buffer.getTextInRange(range)
getEofPosition: -> @buffer.getEofPosition()
lineForBufferRow: (row) -> @buffer.lineForRow(row)
lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row)
rangeForBufferRow: (row) -> @buffer.rangeForRow(row)
scanInRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...)
setText: (text) -> @getBuffer().setText(text)
getText: -> @getBuffer().getText()
getLastBufferRow: -> @getBuffer().getLastRow()
getTextInRange: (range) -> @getBuffer().getTextInRange(range)
getEofPosition: -> @getBuffer().getEofPosition()
lineForBufferRow: (row) -> @getBuffer().lineForRow(row)
lineLengthForBufferRow: (row) -> @getBuffer().lineLengthForRow(row)
rangeForBufferRow: (row) -> @getBuffer().rangeForRow(row)
scanInRange: (args...) -> @getBuffer().scanInRange(args...)
backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...)
handleEvents: ->
@on 'focus', =>
@@ -353,6 +352,8 @@ class Editor extends View
@setActiveEditSessionIndex(index)
getBuffer: -> @activeEditSession.buffer
destroyActiveEditSession: ->
if @editSessions.length == 1
@remove()
@@ -383,11 +384,8 @@ class Editor extends View
@activeEditSession = @editSessions[index]
@unsubscribeFromBuffer() if @buffer
@buffer = @activeEditSession.buffer
@trigger 'editor-path-change'
@activeEditSession.on "buffer-path-change", => @trigger 'editor-path-change'
@trigger 'editor-path-change'
@renderWhenAttached()
activateEditSessionForPath: (path) ->
@@ -500,12 +498,12 @@ class Editor extends View
$(window).off 'resize', @_setSoftWrapColumn
save: ->
if not @buffer.getPath()
if not @getBuffer().getPath()
path = Native.saveDialog()
return false if not path
@buffer.saveAs(path)
@getBuffer().saveAs(path)
else
@buffer.save()
@getBuffer().save()
true
subscribeToFontSize: ->
@@ -540,8 +538,8 @@ class Editor extends View
close: ->
return if @mini
if @buffer.isModified()
filename = if @buffer.getPath() then fs.base(@buffer.getPath()) else "untitled buffer"
if @getBuffer().isModified()
filename = if @getBuffer().getPath() then fs.base(@getBuffer().getPath()) else "untitled buffer"
message = "'#{filename}' has changes, do you want to save them?"
detailedMessage = "Your changes will be lost if you don't save them"
buttons = [
@@ -560,7 +558,6 @@ class Editor extends View
@trigger 'before-remove'
@destroyEditSessions()
@unsubscribeFromBuffer()
$(window).off ".editor#{@id}"
rootView = @rootView()
@@ -568,9 +565,6 @@ class Editor extends View
if @pane() then @pane().remove() else super
rootView?.focus()
unsubscribeFromBuffer: ->
@buffer.off ".editor#{@id}"
destroyEditSessions: ->
for session in @editSessions
session.destroy()

View File

@@ -24,4 +24,4 @@ class Gutter extends View
@calculateDimensions()
calculateDimensions: ->
@lineNumbers.width(@editor().buffer.getLastRow().toString().length * @editor().charWidth)
@lineNumbers.width(@editor().getBuffer().getLastRow().toString().length * @editor().charWidth)

View File

@@ -132,9 +132,9 @@ class RootView extends View
if not editor.mini
editor.on 'editor-path-change.root-view', =>
@trigger 'active-editor-path-change', editor.buffer.getPath()
if not previousActiveEditor or editor.buffer.getPath() != previousActiveEditor.buffer.getPath()
@trigger 'active-editor-path-change', editor.buffer.getPath()
@trigger 'active-editor-path-change', editor.getBuffer().getPath()
if not previousActiveEditor or editor.getBuffer().getPath() != previousActiveEditor.getBuffer().getPath()
@trigger 'active-editor-path-change', editor.getBuffer().getPath()
activeKeybindings: ->
keymap.bindingsForElement(document.activeElement)

View File

@@ -28,7 +28,7 @@ class StatusBar extends View
@editor.on 'cursor-move', => @updateCursorPositionText()
updatePathText: ->
path = @editor.buffer.getPath()
path = @editor.getBuffer().getPath()
if path
@currentPath.text(@rootView.project.relativize(path))
else

View File

@@ -32,10 +32,10 @@ class Autocomplete extends View
initialize: (@editor) ->
requireStylesheet 'autocomplete.css'
@handleEvents()
@setCurrentBuffer(@editor.buffer)
@setCurrentBuffer(@editor.getBuffer())
handleEvents: ->
@editor.on 'editor-path-change', => @setCurrentBuffer(@editor.buffer)
@editor.on 'editor-path-change', => @setCurrentBuffer(@editor.getBuffer())
@editor.on 'before-remove', => @currentBuffer?.off '.autocomplete'
@editor.on 'autocomplete:attach', => @attach()
@@ -53,7 +53,7 @@ class Autocomplete extends View
else
@cancel()
@miniEditor.buffer.on 'change', (e) =>
@miniEditor.getBuffer().on 'change', (e) =>
@filterMatches() if @hasParent()
@miniEditor.preempt 'move-up', =>
@@ -95,7 +95,7 @@ class Autocomplete extends View
cancel: ->
@detach()
@editor.buffer.change(@currentMatchBufferRange, @originalSelectedText) if @currentMatchBufferRange
@editor.getBuffer().change(@currentMatchBufferRange, @originalSelectedText) if @currentMatchBufferRange
@editor.setSelectedBufferRange(@originalSelectionBufferRange)
attach: ->
@@ -120,7 +120,7 @@ class Autocomplete extends View
super
@editor.off(".autocomplete")
@editor.focus()
@miniEditor.buffer.setText('')
@miniEditor.getBuffer().setText('')
setPosition: (originalCursorPosition) ->
{ left, top } = @editor.pixelPositionForScreenPosition(originalCursorPosition)

View File

@@ -10,6 +10,6 @@ class SelectAllMatches extends Command
execute: (editor, currentRange) ->
rangesToSelect = []
editor.buffer.scanInRange @regex, currentRange, (match, range) ->
editor.getBuffer().scanInRange @regex, currentRange, (match, range) ->
rangesToSelect.push(range)
rangesToSelect

View File

@@ -11,6 +11,6 @@ class Substitution extends Command
@regex = new RegExp(pattern, options.join(''))
execute: (editor, currentRange) ->
editor.buffer.scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
editor.getBuffer().scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
replace(@replacementText)
[currentRange]

View File

@@ -55,7 +55,7 @@ class CommandPanel extends View
attach: (text='') ->
@rootView.append(this)
@miniEditor.focus()
@miniEditor.buffer.setText(text)
@miniEditor.getBuffer().setText(text)
@prompt.css 'font', @miniEditor.css('font')
detach: ->

View File

@@ -31,7 +31,7 @@ class FuzzyFinder extends View
@on 'fuzzy-finder:select-path', => @select()
@on 'mousedown', 'li', (e) => @entryClicked(e)
@miniEditor.buffer.on 'change', => @populatePathList() if @hasParent()
@miniEditor.getBuffer().on 'change', => @populatePathList() if @hasParent()
@miniEditor.off 'move-up move-down'
toggleFileFinder: ->
@@ -72,7 +72,7 @@ class FuzzyFinder extends View
populatePathList: ->
@pathList.empty()
for path in @findMatches(@miniEditor.buffer.getText())
for path in @findMatches(@miniEditor.getBuffer().getText())
@pathList.append $$ -> @li path
@pathList.children('li:first').addClass 'selected'

View File

@@ -101,7 +101,7 @@ class TreeView extends View
@append(@root)
selectActiveFile: ->
activeFilePath = @rootView.getActiveEditor()?.buffer.getPath()
activeFilePath = @rootView.getActiveEditor()?.getBuffer().getPath()
@selectEntryForPath(activeFilePath)
selectEntryForPath: (path) ->

View File

@@ -28,7 +28,7 @@ class MoveUp extends Motion
class MoveDown extends Motion
execute: ->
{column, row} = @editor.getCursorScreenPosition()
@editor.moveCursorDown() if row < (@editor.buffer.getLineCount() - 1)
@editor.moveCursorDown() if row < (@editor.getBuffer().getLineCount() - 1)
class MoveToPreviousWord extends Motion
execute: ->
@@ -47,7 +47,7 @@ class MoveToNextWord extends Motion
nextWordPosition: ->
regex = getWordRegex()
{ row, column } = @editor.getCursorScreenPosition()
rightOfCursor = @editor.buffer.lineForRow(row).substring(column)
rightOfCursor = @editor.getBuffer().lineForRow(row).substring(column)
match = regex.exec(rightOfCursor)
# If we're on top of part of a word, match the next one.
@@ -55,10 +55,10 @@ class MoveToNextWord extends Motion
if match
column += match.index
else if row + 1 == @editor.buffer.getLineCount()
column = @editor.buffer.lineForRow(row).length
else if row + 1 == @editor.getBuffer().getLineCount()
column = @editor.getBuffer().lineForRow(row).length
else
nextLineMatch = regex.exec(@editor.buffer.lineForRow(++row))
nextLineMatch = regex.exec(@editor.getBuffer().lineForRow(++row))
column = nextLineMatch?.index or 0
{ row, column }
@@ -75,14 +75,14 @@ class MoveToNextParagraph extends Motion
column = 0
startRow = @editor.getCursorBufferRow() + 1
for r in [startRow..@editor.buffer.getLastRow()]
if @editor.buffer.lineForRow(r).length == 0
for r in [startRow..@editor.getBuffer().getLastRow()]
if @editor.getBuffer().lineForRow(r).length == 0
row = r
break
if not row
row = @editor.buffer.getLastRow()
column = @editor.buffer.lastLine().length - 1
row = @editor.getBuffer().getLastRow()
column = @editor.getBuffer().lastLine().length - 1
new Point(row, column)

View File

@@ -43,7 +43,7 @@ class Delete
@motion.select()
@editor.getSelection().delete()
else
@editor.buffer.deleteRow(@editor.getCursorBufferRow())
@editor.getBuffer().deleteRow(@editor.getCursorBufferRow())
@editor.setCursorScreenPosition([@editor.getCursorScreenRow(), 0])
compose: (motion) ->