mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Move autoIndent code into LanguageMode
This commit is contained in:
@@ -210,6 +210,13 @@ class EditSession
|
||||
isFoldedAtScreenRow: (screenRow) ->
|
||||
@lineForScreenRow(screenRow).fold?
|
||||
|
||||
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
|
||||
return { text } unless @autoIndent
|
||||
@languageMode.autoIndentTextAfterBufferPosition(text, bufferPosition)
|
||||
|
||||
autoOutdent: ->
|
||||
@languageMode.autoOutdentText()
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
@languageMode.toggleLineCommentsInRange(range)
|
||||
|
||||
|
||||
@@ -48,6 +48,18 @@ class LanguageMode
|
||||
else
|
||||
null
|
||||
|
||||
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
|
||||
{ row, column} = bufferPosition
|
||||
state = @stateForRow(row)
|
||||
lineBeforeCursor = @buffer.lineForRow(row)[0...column]
|
||||
if text[0] == "\n"
|
||||
indent = @aceMode.getNextLineIndent(state, lineBeforeCursor, @tabText)
|
||||
text = text[0] + indent + text[1..]
|
||||
else if @aceMode.checkOutdent(state, lineBeforeCursor, text)
|
||||
shouldOutdent = true
|
||||
|
||||
{text, shouldOutdent}
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
oldRange = e.oldRange.copy()
|
||||
newRange = e.newRange.copy()
|
||||
|
||||
@@ -197,18 +197,7 @@ class Selection
|
||||
@cursor.setBufferPosition([range.end.row + 1, 0])
|
||||
|
||||
autoIndentText: (text) ->
|
||||
if @editSession.autoIndent
|
||||
mode = @editSession.getCurrentMode()
|
||||
row = @cursor.getCurrentScreenRow()
|
||||
state = @editSession.stateForScreenRow(row)
|
||||
lineBeforeCursor = @cursor.getCurrentBufferLine()[0...@cursor.getBufferPosition().column]
|
||||
if text[0] == "\n"
|
||||
indent = mode.getNextLineIndent(state, lineBeforeCursor, @editSession.tabText)
|
||||
text = text[0] + indent + text[1..]
|
||||
else if mode.checkOutdent(state, lineBeforeCursor, text)
|
||||
shouldOutdent = true
|
||||
|
||||
{text, shouldOutdent}
|
||||
@editSession.autoIndentTextAfterBufferPosition(text, @cursor.getBufferPosition())
|
||||
|
||||
autoOutdentText: ->
|
||||
screenRow = @cursor.getCurrentScreenRow()
|
||||
|
||||
Reference in New Issue
Block a user