mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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])
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user