Remove unused method TokenizedBuffer.indentLevelForRow

This commit is contained in:
Max Brunsfeld
2017-09-22 16:20:10 -07:00
parent 62e94f7b96
commit 274a699272
2 changed files with 0 additions and 117 deletions

View File

@@ -443,91 +443,6 @@ describe('TokenizedBuffer', () => {
})
})
describe('.indentLevelForRow(row)', () => {
beforeEach(() => {
buffer = atom.project.bufferForPathSync('sample.js')
tokenizedBuffer = new TokenizedBuffer({buffer, grammar: atom.grammars.grammarForScopeName('source.js'), tabLength: 2})
fullyTokenize(tokenizedBuffer)
})
describe('when the line is non-empty', () => {
it('has an indent level based on the leading whitespace on the line', () => {
expect(tokenizedBuffer.indentLevelForRow(0)).toBe(0)
expect(tokenizedBuffer.indentLevelForRow(1)).toBe(1)
expect(tokenizedBuffer.indentLevelForRow(2)).toBe(2)
buffer.insert([2, 0], ' ')
expect(tokenizedBuffer.indentLevelForRow(2)).toBe(2.5)
})
})
describe('when the line is empty', () => {
it('assumes the indentation level of the first non-empty line below or above if one exists', () => {
buffer.insert([12, 0], ' ')
buffer.insert([12, Infinity], '\n\n')
expect(tokenizedBuffer.indentLevelForRow(13)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(14)).toBe(2)
buffer.insert([1, Infinity], '\n\n')
expect(tokenizedBuffer.indentLevelForRow(2)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(3)).toBe(2)
buffer.setText('\n\n\n')
expect(tokenizedBuffer.indentLevelForRow(1)).toBe(0)
})
})
describe('when the changed lines are surrounded by whitespace-only lines', () => {
it('updates the indentLevel of empty lines that precede the change', () => {
expect(tokenizedBuffer.indentLevelForRow(12)).toBe(0)
buffer.insert([12, 0], '\n')
buffer.insert([13, 0], ' ')
expect(tokenizedBuffer.indentLevelForRow(12)).toBe(1)
})
it('updates empty line indent guides when the empty line is the last line', () => {
buffer.insert([12, 2], '\n')
// The newline and the tab need to be in two different operations to surface the bug
buffer.insert([12, 0], ' ')
expect(tokenizedBuffer.indentLevelForRow(13)).toBe(1)
buffer.insert([12, 0], ' ')
expect(tokenizedBuffer.indentLevelForRow(13)).toBe(2)
expect(tokenizedBuffer.tokenizedLines[14]).not.toBeDefined()
})
it('updates the indentLevel of empty lines surrounding a change that inserts lines', () => {
buffer.insert([7, 0], '\n\n')
buffer.insert([5, 0], '\n\n')
expect(tokenizedBuffer.indentLevelForRow(5)).toBe(3)
expect(tokenizedBuffer.indentLevelForRow(6)).toBe(3)
expect(tokenizedBuffer.indentLevelForRow(9)).toBe(3)
expect(tokenizedBuffer.indentLevelForRow(10)).toBe(3)
expect(tokenizedBuffer.indentLevelForRow(11)).toBe(2)
buffer.setTextInRange([[7, 0], [8, 65]], ' one\n two\n three\n four')
expect(tokenizedBuffer.indentLevelForRow(5)).toBe(4)
expect(tokenizedBuffer.indentLevelForRow(6)).toBe(4)
expect(tokenizedBuffer.indentLevelForRow(11)).toBe(4)
expect(tokenizedBuffer.indentLevelForRow(12)).toBe(4)
expect(tokenizedBuffer.indentLevelForRow(13)).toBe(2)
})
it('updates the indentLevel of empty lines surrounding a change that removes lines', () => {
buffer.insert([7, 0], '\n\n')
buffer.insert([5, 0], '\n\n')
buffer.setTextInRange([[7, 0], [8, 65]], ' ok')
expect(tokenizedBuffer.indentLevelForRow(5)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(6)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(7)).toBe(2) // new text
expect(tokenizedBuffer.indentLevelForRow(8)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(9)).toBe(2)
expect(tokenizedBuffer.indentLevelForRow(10)).toBe(2)
})
})
}) // }
describe('.tokenizedLineForRow(row)', () => {
it("returns the tokenized line for a row, or a placeholder line if it hasn't been tokenized yet", () => {
buffer = atom.project.bufferForPathSync('sample.js')

View File

@@ -392,38 +392,6 @@ class TokenizedBuffer {
return scopes
}
indentLevelForRow (bufferRow) {
const line = this.buffer.lineForRow(bufferRow)
let indentLevel = 0
if (line === '') {
let nextRow = bufferRow + 1
const lineCount = this.buffer.getLineCount()
while (nextRow < lineCount) {
const nextLine = this.buffer.lineForRow(nextRow)
if (nextLine !== '') {
indentLevel = Math.ceil(this.indentLevelForLine(nextLine))
break
}
nextRow++
}
let previousRow = bufferRow - 1
while (previousRow >= 0) {
const previousLine = this.buffer.lineForRow(previousRow)
if (previousLine !== '') {
indentLevel = Math.max(Math.ceil(this.indentLevelForLine(previousLine)), indentLevel)
break
}
previousRow--
}
return indentLevel
} else {
return this.indentLevelForLine(line)
}
}
indentLevelForLine (line, tabLength = this.tabLength) {
let indentLength = 0
for (let i = 0, {length} = line; i < length; i++) {