Add Buffer.characterIndexForPosition

This commit is contained in:
Corey Johnson
2012-03-21 14:25:28 -07:00
parent 909337bc1c
commit 0efbd65a24
2 changed files with 16 additions and 0 deletions

View File

@@ -203,3 +203,11 @@ describe 'Buffer', ->
lineLength = buffer.lineForRow(2).length
range = [[2,10], [4,10]]
expect(buffer.getTextInRange(range)).toBe "ems.length <= 1) return items;\n var pivot = items.shift(), current, left = [], right = [];\n while("
describe ".characterIndexForPosition(position)", ->
it "returns the total number of charachters that precede the given position", ->
expect(buffer.characterIndexForPosition([0, 0])).toBe 0
expect(buffer.characterIndexForPosition([0, 1])).toBe 1
expect(buffer.characterIndexForPosition([0, 29])).toBe 29
expect(buffer.characterIndexForPosition([1, 0])).toBe 30
expect(buffer.characterIndexForPosition([2, 0])).toBe 61

View File

@@ -1,5 +1,6 @@
_ = require 'underscore'
fs = require 'fs'
Point = require 'point'
Range = require 'range'
EventEmitter = require 'event-emitter'
UndoManager = require 'undo-manager'
@@ -59,6 +60,13 @@ class Buffer
lastLine: ->
@lineForRow(@lastRow())
characterIndexForPosition: (position) ->
position = Point.fromObject(position)
index = 0
index += @getLineLength(row) + 1 for row in [0...position.row]
index + position.column
deleteRow: (row) ->
range = null
if row == @lastRow()