Use a legitimate replace method in AceAdaptor.

Fixes comment toggling in coffeescript, and requires a better implementation of findMatchingBracket in AceAdaptor for outdent to work.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-06-15 11:56:09 -07:00
parent a9a326f626
commit 8d516fe4fe
3 changed files with 69 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
Range = require 'range'
module.exports =
class AceAdaptor
foldWidgets: {}
@@ -22,12 +24,5 @@ class AceAdaptor
range = Range.fromObject(range)
@buffer.change(range, text)
# We don't care where the bracket is; we always outdent one level
findMatchingBracket: ({row, column}) ->
{row: 0, column: 0}
# Does not actually replace text; always outdents one level
replace: (range, text) ->
start = range.start
end = {row: range.start.row, column: range.start.column + @tokenizedBuffer.tabText.length}
@buffer.change([start, end], "")
@tokenizedBuffer.findOpeningBracket([row, column])

View File

@@ -141,6 +141,36 @@ class TokenizedBuffer
return unless keepLooping
bufferColumn += token.bufferDelta
backwardsIterateTokensInBufferRange: (bufferRange, iterator) ->
bufferRange = Range.fromObject(bufferRange)
{ start, end } = bufferRange
keepLooping = true
stop = -> keepLooping = false
for bufferRow in [end.row..start.row]
bufferColumn = @buffer.lineLengthForRow(bufferRow)
for token in new Array(@screenLines[bufferRow].tokens...).reverse()
bufferColumn -= token.bufferDelta
startOfToken = new Point(bufferRow, bufferColumn)
iterator(token, startOfToken, { stop }) if bufferRange.containsPoint(startOfToken)
return unless keepLooping
findOpeningBracket: (startBufferPosition) ->
range = [[0,0], startBufferPosition]
position = null
depth = 0
@backwardsIterateTokensInBufferRange range, (token, startPosition, { stop }) ->
if token.type.match /lparen|rparen/
if token.value == '}'
depth++
else if token.value == '{'
depth--
if depth == 0
position = startPosition
stop()
position
findClosingBracket: (startBufferPosition) ->
range = [startBufferPosition, @buffer.getEofPosition()]
position = null