Use an overloaded 'tab' keybinding and the new abortKeyBinding method to implement conditional snippet expansion

If the current word prefix doesn't correspond to a valid snippet, we abort the key binding and try the next one, which ends up being the standard tab binding so a typical tab gets inserted. This is a mechanism that could support overloading of arbitrary keys.
This commit is contained in:
Nathan Sobo
2012-06-20 22:47:05 -06:00
parent 68cb9992fc
commit f1678fdafe
3 changed files with 18 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ describe "Snippets extension", ->
editor = rootView.activeEditor()
buffer = editor.buffer
rootView.simulateDomAttachment()
rootView.enableKeymap()
describe "when 'tab' is triggered on the editor", ->
beforeEach ->
@@ -25,13 +26,14 @@ describe "Snippets extension", ->
first go here:$1 then here:$2
endsnippet
"""
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", ->
editor.insertText("t1")
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
editor.trigger 'tab'
editor.trigger keydownEvent('tab', target: editor[0])
expect(buffer.lineForRow(0)).toBe "this is a testvar quicksort = function () {"
expect(editor.getCursorScreenPosition()).toEqual [0, 14]
@@ -59,7 +61,7 @@ describe "Snippets extension", ->
expect(fs.read).toHaveBeenCalledWith('/tmp/foo/js.snippets')
editor.insertText("t1")
editor.trigger 'tab'
editor.trigger 'snippets:expand'
expect(buffer.lineForRow(0)).toBe "this is a test 1var quicksort = function () {"
describe "Snippets parser", ->