mirror of
https://github.com/atom/atom.git
synced 2026-02-10 22:55:09 -05:00
Tab stops are associated with anchors so we can jump to them event when the buffer changes
This commit is contained in:
@@ -239,6 +239,11 @@ class EditSession
|
||||
@anchors.push(anchor)
|
||||
anchor
|
||||
|
||||
addAnchorAtBufferPosition: (bufferPosition) ->
|
||||
anchor = @addAnchor()
|
||||
anchor.setBufferPosition(bufferPosition)
|
||||
anchor
|
||||
|
||||
removeAnchor: (anchor) ->
|
||||
_.remove(@anchors, anchor)
|
||||
|
||||
|
||||
@@ -11,18 +11,19 @@ class Snippet
|
||||
bodyText = []
|
||||
|
||||
[row, column] = [0, 0]
|
||||
for bodyLine in bodyLines
|
||||
for bodyLine, i in bodyLines
|
||||
lineText = []
|
||||
for segment in bodyLine
|
||||
if _.isNumber(segment)
|
||||
tabStopsByIndex[segment] = new Point(row, column)
|
||||
else
|
||||
bodyText.push(segment)
|
||||
lineText.push(segment)
|
||||
column += segment.length
|
||||
bodyText.push('\n')
|
||||
bodyText.push(lineText.join(''))
|
||||
row++; column = 0
|
||||
|
||||
@tabStops = []
|
||||
for index in _.keys(tabStopsByIndex).sort()
|
||||
@tabStops.push tabStopsByIndex[index]
|
||||
|
||||
bodyText.join('')
|
||||
bodyText.join('\n')
|
||||
|
||||
@@ -34,6 +34,7 @@ module.exports =
|
||||
|
||||
|
||||
class SnippetsSession
|
||||
tabStopAnchors: null
|
||||
constructor: (@editSession, @snippetsByExtension) ->
|
||||
|
||||
expandSnippet: ->
|
||||
@@ -43,15 +44,19 @@ class SnippetsSession
|
||||
@editSession.selectToBeginningOfWord()
|
||||
@activeSnippetStartPosition = @editSession.getCursorBufferPosition()
|
||||
@editSession.insertText(@activeSnippet.body)
|
||||
@placeTabStopAnchors()
|
||||
@setTabStopIndex(0) if @activeSnippet.tabStops.length
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
placeTabStopAnchors: ->
|
||||
@tabStopAnchors = @activeSnippet.tabStops.map (position) =>
|
||||
@editSession.addAnchorAtBufferPosition(position)
|
||||
|
||||
goToNextTabStop: ->
|
||||
return false unless @activeSnippet
|
||||
@setTabStopIndex(@tabStopIndex + 1)
|
||||
|
||||
setTabStopIndex: (@tabStopIndex) ->
|
||||
tabStopPosition = @activeSnippet.tabStops[@tabStopIndex].subtract(@activeSnippetStartPosition)
|
||||
@editSession.setCursorBufferPosition(tabStopPosition)
|
||||
@editSession.setCursorBufferPosition(@tabStopAnchors[@tabStopIndex].getBufferPosition())
|
||||
|
||||
Reference in New Issue
Block a user