mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Move autoOutdent code to LanguageMode
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
Range = require 'range'
|
||||
|
||||
module.exports =
|
||||
class AceOutdentAdaptor
|
||||
constructor: (@editSession) ->
|
||||
@@ -12,11 +10,8 @@ class AceOutdentAdaptor
|
||||
findMatchingBracket: ({row, column}) ->
|
||||
{row: 0, column: 0}
|
||||
|
||||
# Does not actually replace text, just line at range.start outdents one level
|
||||
# Does not actually replace text; always outdents one level
|
||||
replace: (range, text) ->
|
||||
{row, column} = @editSession.getCursorBufferPosition()
|
||||
start = range.start
|
||||
end = {row: range.start.row, column: range.start.column + @editSession.tabText.length}
|
||||
@buffer.change(new Range(start, end), "")
|
||||
@editSession.setCursorBufferPosition({row, column: column - @editSession.tabText.length})
|
||||
|
||||
@buffer.change([start, end], "")
|
||||
|
||||
@@ -214,8 +214,8 @@ class EditSession
|
||||
return { text } unless @autoIndent
|
||||
@languageMode.autoIndentTextAfterBufferPosition(text, bufferPosition)
|
||||
|
||||
autoOutdent: ->
|
||||
@languageMode.autoOutdentText()
|
||||
autoOutdentBufferRow: (bufferRow) ->
|
||||
@languageMode.autoOutdentBufferRow(bufferRow)
|
||||
|
||||
toggleLineCommentsInRange: (range) ->
|
||||
@languageMode.toggleLineCommentsInRange(range)
|
||||
|
||||
@@ -6,6 +6,7 @@ Range = require 'range'
|
||||
Point = require 'point'
|
||||
AceLineCommentAdaptor = require 'ace-line-comment-adaptor'
|
||||
AceFoldAdaptor = require 'ace-fold-adaptor'
|
||||
AceOutdentAdaptor = require 'ace-outdent-adaptor'
|
||||
|
||||
module.exports =
|
||||
class LanguageMode
|
||||
@@ -20,6 +21,7 @@ class LanguageMode
|
||||
@buffer.on "change.languageMode#{@id}", (e) => @handleBufferChange(e)
|
||||
@aceLineCommentAdaptor = new AceLineCommentAdaptor(@buffer)
|
||||
@aceFoldAdaptor = new AceFoldAdaptor(this)
|
||||
@aceOutdentAdaptor = new AceOutdentAdaptor(this)
|
||||
|
||||
requireAceMode: ->
|
||||
extension = if @buffer.getPath() then @buffer.getPath().split('/').pop().split('.').pop() else null
|
||||
@@ -60,6 +62,10 @@ class LanguageMode
|
||||
|
||||
{text, shouldOutdent}
|
||||
|
||||
autoOutdentBufferRow: (bufferRow) ->
|
||||
state = @stateForRow(bufferRow)
|
||||
@aceMode.autoOutdent(state, @aceOutdentAdaptor, bufferRow)
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
oldRange = e.oldRange.copy()
|
||||
newRange = e.newRange.copy()
|
||||
|
||||
@@ -130,7 +130,7 @@ class Selection
|
||||
@clear()
|
||||
newBufferRange = @editSession.buffer.change(oldBufferRange, text)
|
||||
@cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed
|
||||
@autoOutdentText() if shouldOutdent
|
||||
@autoOutdent() if shouldOutdent
|
||||
|
||||
backspace: ->
|
||||
@editSession.destroyFoldsContainingBufferRow(@getBufferRange().end.row)
|
||||
@@ -199,11 +199,8 @@ class Selection
|
||||
autoIndentText: (text) ->
|
||||
@editSession.autoIndentTextAfterBufferPosition(text, @cursor.getBufferPosition())
|
||||
|
||||
autoOutdentText: ->
|
||||
screenRow = @cursor.getCurrentScreenRow()
|
||||
bufferRow = @cursor.getCurrentBufferRow()
|
||||
state = @editSession.stateForScreenRow(screenRow)
|
||||
@editSession.getCurrentMode().autoOutdent(state, new AceOutdentAdaptor(@editSession), bufferRow)
|
||||
autoOutdent: ->
|
||||
@editSession.autoOutdentBufferRow(@cursor.getCurrentBufferRow())
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
@modifyScreenRange =>
|
||||
|
||||
Reference in New Issue
Block a user