mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Add Buffer.characterIndexForPosition
This commit is contained in:
@@ -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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user