From fa8ca1193f0c4690e700688dfc407a4924f5c91f Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 28 Jan 2013 16:35:41 -0700 Subject: [PATCH] Correctly place tab stop anchor ranges in snippets with blank lines --- src/packages/snippets/spec/snippets-spec.coffee | 17 +++++++++++++++++ src/packages/snippets/src/snippet.coffee | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/packages/snippets/spec/snippets-spec.coffee b/src/packages/snippets/spec/snippets-spec.coffee index c8d5b99ae..d47e0ea13 100644 --- a/src/packages/snippets/spec/snippets-spec.coffee +++ b/src/packages/snippets/spec/snippets-spec.coffee @@ -66,6 +66,15 @@ describe "Snippets extension", -> ${2:placeholder ending second line} """ + "contains empty lines": + prefix: "t7" + body: """ + first line $1 + + + fourth line after blanks $2 + """ + describe "when the letters preceding the cursor trigger a snippet", -> describe "when the snippet contains no tab stops", -> it "replaces the prefix with the snippet text and places the cursor at its end", -> @@ -140,6 +149,14 @@ describe "Snippets extension", -> editor.trigger keydownEvent('tab', target: editor[0]) expect(editor.getSelectedBufferRange()).toEqual [[0, 5], [0, 10]] + describe "when tab stops are separated by blank lines", -> + it "correctly places the tab stops (regression)", -> + buffer.setText('') + editor.insertText 't7' + editor.trigger 'snippets:expand' + editor.trigger 'snippets:next-tab-stop' + expect(editSession.getCursorBufferPosition()).toEqual [3, 25] + describe "when the cursor is moved beyond the bounds of a tab stop", -> it "terminates the snippet", -> editor.setCursorScreenPosition([2, 0]) diff --git a/src/packages/snippets/src/snippet.coffee b/src/packages/snippets/src/snippet.coffee index ef7c3d0aa..6e0069862 100644 --- a/src/packages/snippets/src/snippet.coffee +++ b/src/packages/snippets/src/snippet.coffee @@ -30,7 +30,7 @@ class Snippet bodyText.push(segment) segmentLines = segment.split('\n') column += segmentLines.shift().length - while nextLine = segmentLines.shift() + while (nextLine = segmentLines.shift())? row += 1 column = nextLine.length