From 50517431db6eefc6b62b33f5e73b880a9368a0f0 Mon Sep 17 00:00:00 2001 From: Dominik Kundel Date: Mon, 4 Aug 2014 23:02:54 +0200 Subject: [PATCH] added support for inserting snippets by shift+click --- app/views/play/level/tome/SpellPaletteEntryView.coffee | 3 +++ app/views/play/level/tome/SpellView.coffee | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/views/play/level/tome/SpellPaletteEntryView.coffee b/app/views/play/level/tome/SpellPaletteEntryView.coffee index 3b7f53c71..ee3b2e892 100644 --- a/app/views/play/level/tome/SpellPaletteEntryView.coffee +++ b/app/views/play/level/tome/SpellPaletteEntryView.coffee @@ -71,6 +71,9 @@ module.exports = class SpellPaletteEntryView extends CocoView Backbone.Mediator.publish 'tome:palette-pin-toggled', entry: @, pinned: @popoverPinned onClick: (e) => + if key.shift + Backbone.Mediator.publish 'tome:insert-snippet', doc: @options.doc, language: @options.language + return @togglePinned() Backbone.Mediator.publish 'tome:palette-clicked', thang: @thang, prop: @doc.name, entry: @ diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee index ee979cc38..a00f72126 100644 --- a/app/views/play/level/tome/SpellView.coffee +++ b/app/views/play/level/tome/SpellView.coffee @@ -47,6 +47,7 @@ module.exports = class SpellView extends CocoView 'tome:change-language': 'onChangeLanguage' 'tome:change-config': 'onChangeEditorConfig' 'tome:update-snippets': 'addZatannaSnippets' + 'tome:insert-snippet': 'onInsertSnippet' 'spell-beautify': 'onSpellBeautify' events: @@ -661,6 +662,13 @@ module.exports = class SpellView extends CocoView @spell.setLanguage e.language @reloadCode true if wasDefault + onInsertSnippet: (e) -> + console.log 'doc', e.doc + return unless e.doc.snippets?[e.language]?.code + snippetManager = ace.require('ace/snippets').snippetManager + snippetManager.insertSnippet @ace, e.doc.snippets[e.language].code + return + dismiss: -> @spell.hasChangedSignificantly @getSource(), null, (hasChanged) => @recompile() if hasChanged