use shortName as fallback for some entries if no snippet

This commit is contained in:
Dominik Kundel 2014-08-05 11:19:15 +02:00
parent f09b3c4792
commit 84c0fbd01f
2 changed files with 9 additions and 4 deletions

View file

@ -72,7 +72,7 @@ module.exports = class SpellPaletteEntryView extends CocoView
onClick: (e) =>
if key.shift
Backbone.Mediator.publish 'tome:insert-snippet', doc: @options.doc, language: @options.language
Backbone.Mediator.publish 'tome:insert-snippet', doc: @options.doc, language: @options.language, formatted: @doc
return
@togglePinned()
Backbone.Mediator.publish 'tome:palette-clicked', thang: @thang, prop: @doc.name, entry: @

View file

@ -663,10 +663,15 @@ module.exports = class SpellView extends CocoView
@reloadCode true if wasDefault
onInsertSnippet: (e) ->
console.log 'doc', e.doc
return unless e.doc.snippets?[e.language]?.code
console.log 'doc', e.doc, e.formatted
snippetCode = null
if e.doc.snippets?[e.language]?.code
snippetCode = e.doc.snippets[e.language].code
else if (e.formatted.type isnt 'snippet') and e.formatted.shortName?
snippetCode = e.formatted.shortName
return unless snippetCode?
snippetManager = ace.require('ace/snippets').snippetManager
snippetManager.insertSnippet @ace, e.doc.snippets[e.language].code
snippetManager.insertSnippet @ace, snippetCode
return
dismiss: ->