Rename Buffer.getLine to lineForRow

This commit is contained in:
Nathan Sobo
2012-03-05 16:06:27 -07:00
parent 95db96b238
commit fc7a13ce05
13 changed files with 98 additions and 94 deletions

View File

@@ -27,4 +27,4 @@ class App
windowClosed: (window) ->
index = @windows.indexOf(window)
@windows.splice(index, 1) if index >= 0
@windows.splice(index, 1) if index >= 0

View File

@@ -39,7 +39,7 @@ class Buffer
getLines: ->
@lines
getLine: (row) ->
lineForRow: (row) ->
@lines[row]
getLineLength: (row) ->
@@ -52,7 +52,7 @@ class Buffer
@getLines().length - 1
lastLine: ->
@getLine(@lastRow())
@lineForRow(@lastRow())
deleteRow: (row) ->
range = null
@@ -67,6 +67,7 @@ class Buffer
@change(new Range(point, point), text)
change: (oldRange, newText) ->
oldRange = Range.fromObject(oldRange)
newRange = new Range(_.clone(oldRange.start), _.clone(oldRange.start))
prefix = @lines[oldRange.start.row][0...oldRange.start.column]
suffix = @lines[oldRange.end.row][oldRange.end.column..]

View File

@@ -65,7 +65,7 @@ class Cursor extends View
moveToLineEnd: ->
{ row } = @getScreenPosition()
@setScreenPosition({ row, column: @editor.buffer.getLine(row).length })
@setScreenPosition({ row, column: @editor.buffer.lineForRow(row).length })
moveToLineStart: ->
{ row } = @getScreenPosition()
@@ -92,7 +92,7 @@ class Cursor extends View
offset = 0
matchBackwards = =>
line = @editor.buffer.getLine(row)
line = @editor.buffer.lineForRow(row)
reversedLine = line[0...column].split('').reverse().join('')
regex.exec reversedLine

View File

@@ -274,7 +274,7 @@ class Editor extends View
getCursor: -> @cursor
getSelection: -> @selection
getCurrentLine: -> @buffer.getLine(@getCursorRow())
getCurrentLine: -> @buffer.lineForRow(@getCursorRow())
getSelectedText: -> @selection.getText()
moveCursorUp: -> @cursor.moveUp()
moveCursorDown: -> @cursor.moveDown()

View File

@@ -42,7 +42,7 @@ class Highlighter
if nextRow > newRange.end.row
oldRange.end.row += (nextRow - newRange.end.row)
newRange.end.row = nextRow
endColumn = @buffer.getLine(nextRow).length
endColumn = @buffer.lineForRow(nextRow).length
newRange.end.column = endColumn
oldRange.end.column = endColumn
@@ -56,13 +56,16 @@ class Highlighter
screenLine
buildLineForScreenRow: (state, row) ->
line = @buffer.getLine(row)
line = @buffer.lineForRow(row)
{tokens, state} = @tokenizer.getLineTokens(line, state)
new ScreenLineFragment(tokens, line, [1, 0], [1, 0], { state })
lineForScreenRow: (row) ->
@screenLines[row]
lineForRow: (row) ->
@lineForScreenRow(row)
linesForScreenRows: (startRow, endRow) ->
@screenLines[startRow..endRow]

View File

@@ -108,7 +108,7 @@ class Selection extends View
{ row, column } = @cursor.getBufferPosition()
line = @editor.buffer.getLine(row)
line = @editor.buffer.lineForRow(row)
leftSide = line[0...column].split('').reverse().join('') # reverse left side
rightSide = line[column..]
@@ -120,7 +120,7 @@ class Selection extends View
@setBufferRange range
selectLine: (row=@cursor.getBufferPosition().row) ->
rowLength = @editor.buffer.getLine(row).length
rowLength = @editor.buffer.lineForRow(row).length
@setBufferRange new Range([row, 0], [row, rowLength])
selectRight: ->

View File

@@ -47,7 +47,7 @@ class MoveToNextWord extends Motion
nextWordPosition: ->
regex = getWordRegex()
{ row, column } = @editor.getCursorScreenPosition()
rightOfCursor = @editor.buffer.getLine(row).substring(column)
rightOfCursor = @editor.buffer.lineForRow(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.buffer.numLines()
column = @editor.buffer.getLine(row).length
column = @editor.buffer.lineForRow(row).length
else
nextLineMatch = regex.exec(@editor.buffer.getLine(++row))
nextLineMatch = regex.exec(@editor.buffer.lineForRow(++row))
column = nextLineMatch?.index or 0
{ row, column }
@@ -76,7 +76,7 @@ class MoveToNextParagraph extends Motion
startRow = @editor.getCursorRow() + 1
for r in [startRow..@editor.buffer.lastRow()]
if @editor.buffer.getLine(r).length == 0
if @editor.buffer.lineForRow(r).length == 0
row = r
break

View File

@@ -10,4 +10,4 @@ $.fn.scrollRight = (newValue) ->
if newValue?
@scrollLeft(newValue - @width())
else
@scrollLeft() + @width()
@scrollLeft() + @width()