Pass tabLength to suggestedIndent methods for now

This commit is contained in:
Max Brunsfeld
2017-11-06 16:56:06 -08:00
parent fe6b385c97
commit 70cca84599
3 changed files with 39 additions and 18 deletions

View File

@@ -448,9 +448,19 @@ class Selection {
if (options.autoIndent && textIsAutoIndentable && !NonWhitespaceRegExp.test(precedingText) && (remainingLines.length > 0)) {
autoIndentFirstLine = true
const firstLine = precedingText + firstInsertedLine
desiredIndentLevel = this.editor.tokenizedBuffer.suggestedIndentForLineAtBufferRow(oldBufferRange.start.row, firstLine)
indentAdjustment = desiredIndentLevel - this.editor.indentLevelForLine(firstLine)
this.adjustIndent(remainingLines, indentAdjustment)
const languageMode = this.editor.buffer.getLanguageMode()
desiredIndentLevel = (
languageMode.suggestedIndentForLineAtBufferRow &&
languageMode.suggestedIndentForLineAtBufferRow(
oldBufferRange.start.row,
firstLine,
this.editor.getTabLength()
)
)
if (desiredIndentLevel != null) {
indentAdjustment = desiredIndentLevel - this.editor.indentLevelForLine(firstLine)
this.adjustIndent(remainingLines, indentAdjustment)
}
}
text = firstInsertedLine

View File

@@ -4387,7 +4387,10 @@ class TextEditor {
suggestedIndentForBufferRow (bufferRow, options) {
const languageMode = this.buffer.getLanguageMode()
return languageMode.suggestedIndentForBufferRow && languageMode.suggestedIndentForBufferRow(bufferRow, options)
return (
languageMode.suggestedIndentForBufferRow &&
languageMode.suggestedIndentForBufferRow(bufferRow, this.getTabLength(), options)
)
}
// Given a buffer row, indent it.
@@ -4415,7 +4418,7 @@ class TextEditor {
const languageMode = this.buffer.getLanguageMode()
const indentLevel = (
languageMode.suggestedIndentForEditedBufferRow &&
languageMode.suggestedIndentForEditedBufferRow(bufferRow)
languageMode.suggestedIndentForEditedBufferRow(bufferRow, this.getTabLength())
)
if (indentLevel != null) this.setIndentationForBufferRow(bufferRow, indentLevel)
}

View File

@@ -76,10 +76,14 @@ class TokenizedBuffer {
// * bufferRow - A {Number} indicating the buffer row
//
// Returns a {Number}.
suggestedIndentForBufferRow (bufferRow, options) {
const line = this.buffer.lineForRow(bufferRow)
const tokenizedLine = this.tokenizedLineForRow(bufferRow)
return this._suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
suggestedIndentForBufferRow (bufferRow, tabLength, options) {
return this._suggestedIndentForTokenizedLineAtBufferRow(
bufferRow,
this.buffer.lineForRow(bufferRow),
this.tokenizedLineForRow(bufferRow),
tabLength,
options
)
}
// Get the suggested indentation level for a given line of text, if it were inserted at the given
@@ -88,9 +92,13 @@ class TokenizedBuffer {
// * bufferRow - A {Number} indicating the buffer row
//
// Returns a {Number}.
suggestedIndentForLineAtBufferRow (bufferRow, line, options) {
const tokenizedLine = this.buildTokenizedLineForRowWithText(bufferRow, line)
return this._suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
suggestedIndentForLineAtBufferRow (bufferRow, line, tabLength) {
return this._suggestedIndentForTokenizedLineAtBufferRow(
bufferRow,
line,
this.buildTokenizedLineForRowWithText(bufferRow, line),
tabLength
)
}
// Get the suggested indentation level for a line in the buffer on which the user is currently
@@ -101,9 +109,9 @@ class TokenizedBuffer {
// * bufferRow - The row {Number}
//
// Returns a {Number}.
suggestedIndentForEditedBufferRow (bufferRow) {
suggestedIndentForEditedBufferRow (bufferRow, tabLength) {
const line = this.buffer.lineForRow(bufferRow)
const currentIndentLevel = this.indentLevelForLine(line)
const currentIndentLevel = this.indentLevelForLine(line, tabLength)
if (currentIndentLevel === 0) return
const scopeDescriptor = this.scopeDescriptorForPosition([bufferRow, 0])
@@ -116,7 +124,7 @@ class TokenizedBuffer {
if (precedingRow == null) return
const precedingLine = this.buffer.lineForRow(precedingRow)
let desiredIndentLevel = this.indentLevelForLine(precedingLine)
let desiredIndentLevel = this.indentLevelForLine(precedingLine, tabLength)
const increaseIndentRegex = this.increaseIndentRegexForScopeDescriptor(scopeDescriptor)
if (increaseIndentRegex) {
@@ -133,7 +141,7 @@ class TokenizedBuffer {
return desiredIndentLevel
}
_suggestedIndentForTokenizedLineAtBufferRow (bufferRow, line, tokenizedLine, options) {
_suggestedIndentForTokenizedLineAtBufferRow (bufferRow, line, tokenizedLine, tabLength, options) {
const iterator = tokenizedLine.getTokenIterator()
iterator.next()
const scopeDescriptor = new ScopeDescriptor({scopes: iterator.getScopes()})
@@ -152,7 +160,7 @@ class TokenizedBuffer {
}
const precedingLine = this.buffer.lineForRow(precedingRow)
let desiredIndentLevel = this.indentLevelForLine(precedingLine)
let desiredIndentLevel = this.indentLevelForLine(precedingLine, tabLength)
if (!increaseIndentRegex) return desiredIndentLevel
if (!this.isRowCommented(precedingRow)) {
@@ -479,7 +487,7 @@ class TokenizedBuffer {
return scopes
}
indentLevelForLine (line, tabLength = this.tabLength) {
indentLevelForLine (line, tabLength) {
let indentLength = 0
for (let i = 0, {length} = line; i < length; i++) {
const char = line[i]