💄 Use more delegated (editor -> buffer) methods

This commit is contained in:
Nathan Sobo
2012-07-04 12:47:51 -06:00
parent 43f51b9689
commit f253820250
5 changed files with 15 additions and 15 deletions

View File

@@ -1076,17 +1076,17 @@ describe "Editor", ->
it "renders correctly when scrolling after text is added to the buffer", ->
editor.insertText("1\n")
_.times 4, -> editor.moveCursorDown()
expect(editor.renderedLines.find('.line:eq(2)').text()).toBe editor.getBuffer().lineForRow(2)
expect(editor.renderedLines.find('.line:eq(7)').text()).toBe editor.getBuffer().lineForRow(7)
expect(editor.renderedLines.find('.line:eq(2)').text()).toBe editor.lineForBufferRow(2)
expect(editor.renderedLines.find('.line:eq(7)').text()).toBe editor.lineForBufferRow(7)
it "renders correctly when scrolling after text is removed from buffer", ->
editor.getBuffer().delete([[0,0],[1,0]])
expect(editor.renderedLines.find('.line:eq(0)').text()).toBe editor.getBuffer().lineForRow(0)
expect(editor.renderedLines.find('.line:eq(5)').text()).toBe editor.getBuffer().lineForRow(5)
expect(editor.renderedLines.find('.line:eq(0)').text()).toBe editor.lineForBufferRow(0)
expect(editor.renderedLines.find('.line:eq(5)').text()).toBe editor.lineForBufferRow(5)
editor.scrollTop(3 * editor.lineHeight)
expect(editor.renderedLines.find('.line:first').text()).toBe editor.getBuffer().lineForRow(1)
expect(editor.renderedLines.find('.line:last').text()).toBe editor.getBuffer().lineForRow(10)
expect(editor.renderedLines.find('.line:first').text()).toBe editor.lineForBufferRow(1)
expect(editor.renderedLines.find('.line:last').text()).toBe editor.lineForBufferRow(10)
describe "when creating and destroying folds that are longer than the visible lines", ->
describe "when the cursor precedes the fold when it is destroyed", ->

View File

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

View File

@@ -10,6 +10,6 @@ class SelectAllMatches extends Command
execute: (editor, currentRange) ->
rangesToSelect = []
editor.getBuffer().scanInRange @regex, currentRange, (match, range) ->
editor.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.getBuffer().scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
editor.scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
replace(@replacementText)
[currentRange]

View File

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