mirror of
https://github.com/atom/atom.git
synced 2026-02-18 10:31:54 -05:00
@@ -77,6 +77,13 @@ describe "Snippets extension", ->
|
||||
expect(buffer.lineForRow(0)).toBe "this is a testvar quicksort = function () {"
|
||||
expect(editor.getCursorScreenPosition()).toEqual [0, 14]
|
||||
|
||||
it "inserts a real tab the next time a tab is pressed after the snippet is expanded", ->
|
||||
editor.insertText("t1")
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(buffer.lineForRow(0)).toBe "this is a testvar quicksort = function () {"
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(buffer.lineForRow(0)).toBe "this is a test var quicksort = function () {"
|
||||
|
||||
describe "when the snippet contains tab stops", ->
|
||||
it "places the cursor at the first tab-stop, and moves the cursor in response to 'next-tab-stop' events", ->
|
||||
anchorCountBefore = editor.activeEditSession.getAnchors().length
|
||||
|
||||
@@ -12,12 +12,13 @@ class SnippetExpansion
|
||||
startPosition = @editSession.getCursorBufferPosition()
|
||||
@editSession.transact =>
|
||||
@editSession.insertText(snippet.body, autoIndent: false)
|
||||
editSession.pushOperation
|
||||
do: =>
|
||||
@subscribe @editSession, 'cursor-moved.snippet-expansion', (e) => @cursorMoved(e)
|
||||
@placeTabStopAnchorRanges(startPosition, snippet.tabStops)
|
||||
@editSession.snippetExpansion = this
|
||||
undo: => @destroy()
|
||||
if snippet.tabStops.length > 0
|
||||
editSession.pushOperation
|
||||
do: =>
|
||||
@subscribe @editSession, 'cursor-moved.snippet-expansion', (e) => @cursorMoved(e)
|
||||
@placeTabStopAnchorRanges(startPosition, snippet.tabStops)
|
||||
@editSession.snippetExpansion = this
|
||||
undo: => @destroy()
|
||||
@indentSubsequentLines(startPosition.row, snippet) if snippet.lineCount > 1
|
||||
|
||||
cursorMoved: ({oldBufferPosition, newBufferPosition}) ->
|
||||
@@ -29,8 +30,6 @@ class SnippetExpansion
|
||||
@destroy() unless _.intersect(oldTabStops, newTabStops).length
|
||||
|
||||
placeTabStopAnchorRanges: (startPosition, tabStopRanges) ->
|
||||
return unless @snippet.tabStops.length > 0
|
||||
|
||||
@tabStopAnchorRanges = tabStopRanges.map ({start, end}) =>
|
||||
anchorRange = @editSession.addAnchorRange([startPosition.add(start), startPosition.add(end)])
|
||||
@subscribe anchorRange, 'destroyed', =>
|
||||
|
||||
Reference in New Issue
Block a user