Merge pull request #1422 from dkundel/master

Fixed issue #1420 and pasting snippets on click
This commit is contained in:
Nick Winter 2014-08-11 12:47:36 -07:00
commit 2bc92f1a6e
2 changed files with 21 additions and 0 deletions

View file

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

View file

@ -3,6 +3,7 @@ template = require 'templates/play/level/tome/spell'
{me} = require 'lib/auth' {me} = require 'lib/auth'
filters = require 'lib/image_filter' filters = require 'lib/image_filter'
Range = ace.require('ace/range').Range Range = ace.require('ace/range').Range
UndoManager = ace.require('ace/undomanager').UndoManager
Problem = require './Problem' Problem = require './Problem'
SpellDebugView = require './SpellDebugView' SpellDebugView = require './SpellDebugView'
SpellToolbarView = require './SpellToolbarView' SpellToolbarView = require './SpellToolbarView'
@ -47,6 +48,7 @@ module.exports = class SpellView extends CocoView
'tome:change-language': 'onChangeLanguage' 'tome:change-language': 'onChangeLanguage'
'tome:change-config': 'onChangeEditorConfig' 'tome:change-config': 'onChangeEditorConfig'
'tome:update-snippets': 'addZatannaSnippets' 'tome:update-snippets': 'addZatannaSnippets'
'tome:insert-snippet': 'onInsertSnippet'
'spell-beautify': 'onSpellBeautify' 'spell-beautify': 'onSpellBeautify'
events: events:
@ -174,6 +176,7 @@ module.exports = class SpellView extends CocoView
fillACE: -> fillACE: ->
@ace.setValue @spell.source @ace.setValue @spell.source
@aceSession.setUndoManager(new UndoManager())
@ace.clearSelection() @ace.clearSelection()
addZatannaSnippets: (e) -> addZatannaSnippets: (e) ->
@ -208,6 +211,7 @@ module.exports = class SpellView extends CocoView
@loaded = false @loaded = false
@previousSource = @ace.getValue() @previousSource = @ace.getValue()
@ace.setValue('') @ace.setValue('')
@aceSession.setUndoManager(new UndoManager())
fireURL = 'https://codecombat.firebaseio.com/' + @spell.pathComponents.join('/') fireURL = 'https://codecombat.firebaseio.com/' + @spell.pathComponents.join('/')
@fireRef = new Firebase fireURL @fireRef = new Firebase fireURL
firepadOptions = userId: me.id firepadOptions = userId: me.id
@ -222,6 +226,7 @@ module.exports = class SpellView extends CocoView
@spell.source = firepadSource @spell.source = firepadSource
else else
@ace.setValue @previousSource @ace.setValue @previousSource
@aceSession.setUndoManager(new UndoManager())
@ace.clearSelection() @ace.clearSelection()
@onAllLoaded() @onAllLoaded()
@ -302,6 +307,7 @@ module.exports = class SpellView extends CocoView
@firepad.setText source @firepad.setText source
else else
@ace.setValue source @ace.setValue source
@aceSession.setUndoManager(new UndoManager())
@eventsSuppressed = false @eventsSuppressed = false
try try
@ace.resize true # hack: @ace may not have updated its text properly, so we force it to refresh @ace.resize true # hack: @ace may not have updated its text properly, so we force it to refresh
@ -661,6 +667,18 @@ module.exports = class SpellView extends CocoView
@spell.setLanguage e.language @spell.setLanguage e.language
@reloadCode true if wasDefault @reloadCode true if wasDefault
onInsertSnippet: (e) ->
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, snippetCode
return
dismiss: -> dismiss: ->
@spell.hasChangedSignificantly @getSource(), null, (hasChanged) => @spell.hasChangedSignificantly @getSource(), null, (hasChanged) =>
@recompile() if hasChanged @recompile() if hasChanged