mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-26 12:50:31 -04:00
Merge pull request #545 from dkundel/master
Implemented editor config to allow Vim & Emacs key bindings as proposed in #99
This commit is contained in:
commit
c28d2bb576
10 changed files with 144 additions and 5 deletions
app
locale
styles/play/level/modal
templates/play/level
views/play/level
server/users
|
@ -206,7 +206,16 @@ module.exports = nativeDescription: "Deutsch", englishDescription: "German", tra
|
|||
tome_available_spells: "Verfügbare Zauber"
|
||||
hud_continue: "Weiter (drücke Shift + Leertaste)"
|
||||
spell_saved: "Zauber gespeichert"
|
||||
# skip_tutorial: "Skip (esc)"
|
||||
skip_tutorial: "Überspringen (Esc)"
|
||||
editor_config: "Editor Einstellungen"
|
||||
editor_config_title: "Editor Einstellungen"
|
||||
editor_config_keybindings_label: "Tastenbelegung"
|
||||
editor_config_keybindings_default: "Standard (Ace)"
|
||||
editor_config_keybindings_description: "Fügt zusätzliche Tastenkombinationen, bekannt aus anderen Editoren, hinzu"
|
||||
editor_config_invisibles_label: "Zeige unsichtbare Zeichen"
|
||||
editor_config_invisibles_description: "Zeigt unsichtbare Zeichen wie Leertasten an."
|
||||
editor_config_indentguides_label: "Zeige Einrückungshilfe"
|
||||
editor_config_indentguides_description: "Zeigt vertikale Linien an um Einrückungen besser zu sehen."
|
||||
|
||||
admin:
|
||||
av_title: "Administrator Übersicht"
|
||||
|
|
|
@ -207,6 +207,15 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
|
|||
hud_continue: "Continue (shift+space)"
|
||||
spell_saved: "Spell Saved"
|
||||
skip_tutorial: "Skip (esc)"
|
||||
editor_config: "Editor Config"
|
||||
editor_config_title: "Editor Configuration"
|
||||
editor_config_keybindings_label: "Key Bindings"
|
||||
editor_config_keybindings_default: "Default (Ace)"
|
||||
editor_config_keybindings_description: "Adds additional shortcuts known from the common editors."
|
||||
editor_config_invisibles_label: "Show Invisibles"
|
||||
editor_config_invisibles_description: "Displays invisibles such as spaces or tabs."
|
||||
editor_config_indentguides_label: "Show Indent Guides"
|
||||
editor_config_indentguides_description: "Displays vertical lines to see indentation better."
|
||||
|
||||
admin:
|
||||
av_title: "Admin Views"
|
||||
|
|
12
app/styles/play/level/modal/editor_config.sass
Normal file
12
app/styles/play/level/modal/editor_config.sass
Normal file
|
@ -0,0 +1,12 @@
|
|||
#level-editor-config-modal
|
||||
.select-group
|
||||
display: block
|
||||
min-height: 20px
|
||||
margin-top: 10px
|
||||
margin-bottom: 10px
|
||||
padding-left: 20px
|
||||
vertical-align: middle
|
||||
|
||||
label
|
||||
font-weight: normal
|
||||
margin-right: 20px
|
27
app/templates/play/level/modal/editor_config.jade
Normal file
27
app/templates/play/level/modal/editor_config.jade
Normal file
|
@ -0,0 +1,27 @@
|
|||
.modal-dialog
|
||||
.modal-header
|
||||
button(type='button', data-dismiss="modal", aria-hidden="true").close ×
|
||||
h3(data-i18n="play_level.editor_config_title") Editor Configuration
|
||||
|
||||
.modal-body
|
||||
.form
|
||||
.form-group.select-group
|
||||
label.control-label(for="keyBindings" data-i18n="play_level.editor_config_keybindings_label") Key Bindings
|
||||
select#keyBindings(name="keyBindings", type="checkbox", checked=multiplayer)
|
||||
option(value="default" selected=(keyBindings === "default") data-i18n="play_level.editor_config_keybindings_default") Default (Ace)
|
||||
option(value="vim" selected=(keyBindings === "vim")) Vim
|
||||
option(value="emacs" selected=(keyBindings === "emacs")) Emacs
|
||||
span.help-block(data-i18n="play_level.editor_config_keybindings_description") Adds additional shortcuts known from the common editors.
|
||||
.form-group.checkbox
|
||||
label(for="invisibles")
|
||||
input#invisibles(name="invisibles", type="checkbox", checked=invisibles)
|
||||
span(data-i18n="play_level.editor_config_invisibles_label") Show Invisibles
|
||||
span.help-block(data-i18n="play_level.editor_config_invisibles_description") Displays invisibles such as spaces or tabs.
|
||||
.form-group.checkbox
|
||||
label(for="indentGuides")
|
||||
input#indentGuides(name="indentGuides", type="checkbox", checked=indentGuides)
|
||||
span(data-i18n="play_level.editor_config_indentguides_label") Show Indent Guides
|
||||
span.help-block(data-i18n="play_level.editor_config_indentguides_description") Displays vertical lines to see indentation better.
|
||||
|
||||
.modal-footer
|
||||
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="modal.close").btn.btn-primary Close
|
|
@ -37,3 +37,6 @@ button.btn.btn-xs.btn-inverse#music-button(title="Toggle Music")
|
|||
li.selectable#edit-wizard-settings
|
||||
i.icon-user
|
||||
span(data-i18n="play_level.customize_wizard") Customize Wizard
|
||||
li.selectable#edit-editor-config
|
||||
i.icon-edit
|
||||
span(data-i18n="play_level.editor_config") Editor Config
|
||||
|
|
54
app/views/play/level/modal/editor_config_modal.coffee
Normal file
54
app/views/play/level/modal/editor_config_modal.coffee
Normal file
|
@ -0,0 +1,54 @@
|
|||
View = require 'views/kinds/ModalView'
|
||||
template = require 'templates/play/level/modal/editor_config'
|
||||
{me} = require('lib/auth')
|
||||
|
||||
module.exports = class EditorConfigModal extends View
|
||||
id: 'level-editor-config-modal'
|
||||
template: template
|
||||
aceConfig: {}
|
||||
|
||||
defaultConfig:
|
||||
keyBindings: 'default'
|
||||
invisibles: false
|
||||
indentGuides: false
|
||||
|
||||
events:
|
||||
'click textarea': 'onClickLink'
|
||||
'change #invisibles': 'updateInvisiblesSelection'
|
||||
'change #keyBindings': 'updateKeyBindingsSelection'
|
||||
'change #indentGuides': 'updateIndentGuides'
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
|
||||
getRenderData: ->
|
||||
@aceConfig = _.cloneDeep me.get('aceConfig') || {}
|
||||
@aceConfig = _.defaults @aceConfig, @defaultConfig
|
||||
c = super()
|
||||
c.keyBindings = @aceConfig.keyBindings
|
||||
c.invisibles = @aceConfig.invisibles
|
||||
c.indentGuides = @aceConfig.indentGuides
|
||||
c
|
||||
|
||||
updateInvisiblesSelection: ->
|
||||
@aceConfig.invisibles = @$el.find('#invisibles').prop('checked')
|
||||
|
||||
updateKeyBindingsSelection: ->
|
||||
@aceConfig.keyBindings = @$el.find('#keyBindings').val()
|
||||
|
||||
updateIndentGuides: ->
|
||||
@aceConfig.indentGuides = @$el.find('#indentGuides').prop('checked')
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
|
||||
onHidden: ->
|
||||
@aceConfig.invisibles = @$el.find('#invisibles').prop('checked')
|
||||
@aceConfig.keyBindings = @$el.find('#keyBindings').val()
|
||||
@aceConfig.indentGuides = @$el.find('#indentGuides').prop('checked')
|
||||
me.set 'aceConfig', @aceConfig
|
||||
Backbone.Mediator.publish 'change:editor-config'
|
||||
me.save()
|
||||
|
||||
destroy: ->
|
||||
super()
|
|
@ -2,6 +2,8 @@ View = require 'views/kinds/CocoView'
|
|||
template = require 'templates/play/level/playback'
|
||||
{me} = require 'lib/auth'
|
||||
|
||||
EditorConfigModal = require './modal/editor_config_modal'
|
||||
|
||||
module.exports = class PlaybackView extends View
|
||||
id: "playback-view"
|
||||
template: template
|
||||
|
@ -25,6 +27,7 @@ module.exports = class PlaybackView extends View
|
|||
'click #debug-toggle': 'onToggleDebug'
|
||||
'click #grid-toggle': 'onToggleGrid'
|
||||
'click #edit-wizard-settings': 'onEditWizardSettings'
|
||||
'click #edit-editor-config': 'onEditEditorConfig'
|
||||
'click #music-button': 'onToggleMusic'
|
||||
'click #zoom-in-button': -> Backbone.Mediator.publish('camera-zoom-in') unless @disabled
|
||||
'click #zoom-out-button': -> Backbone.Mediator.publish('camera-zoom-out') unless @disabled
|
||||
|
@ -77,6 +80,9 @@ module.exports = class PlaybackView extends View
|
|||
onEditWizardSettings: ->
|
||||
Backbone.Mediator.publish 'edit-wizard-settings'
|
||||
|
||||
onEditEditorConfig: ->
|
||||
@openModalView(new EditorConfigModal())
|
||||
|
||||
onDisableControls: (e) ->
|
||||
if not e.controls or 'playback' in e.controls
|
||||
@disabled = true
|
||||
|
|
|
@ -15,6 +15,11 @@ module.exports = class SpellView extends View
|
|||
eventsSuppressed: true
|
||||
writable: true
|
||||
|
||||
keyBindings:
|
||||
'default': null
|
||||
'vim': 'ace/keyboard/vim'
|
||||
'emacs': 'ace/keyboard/emacs'
|
||||
|
||||
subscriptions:
|
||||
'level-disable-controls': 'onDisableControls'
|
||||
'level-enable-controls': 'onEnableControls'
|
||||
|
@ -30,6 +35,7 @@ module.exports = class SpellView extends View
|
|||
'focus-editor': 'focus'
|
||||
'tome:spell-statement-index-updated': 'onStatementIndexUpdated'
|
||||
'spell-beautify': 'onSpellBeautify'
|
||||
'change:editor-config': 'onChangeEditorConfig'
|
||||
|
||||
events:
|
||||
'mouseout': 'onMouseOut'
|
||||
|
@ -56,6 +62,7 @@ module.exports = class SpellView extends View
|
|||
|
||||
createACE: ->
|
||||
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
|
||||
aceConfig = me.get 'aceConfig'
|
||||
@ace = ace.edit @$el.find('.ace')[0]
|
||||
@aceSession = @ace.getSession()
|
||||
@aceDoc = @aceSession.getDocument()
|
||||
|
@ -66,11 +73,12 @@ module.exports = class SpellView extends View
|
|||
@aceSession.setNewLineMode "unix"
|
||||
@aceSession.setUseSoftTabs true
|
||||
@ace.setTheme 'ace/theme/textmate'
|
||||
@ace.setDisplayIndentGuides false
|
||||
@ace.setDisplayIndentGuides (aceConfig.indentGuides || false)
|
||||
@ace.setShowPrintMargin false
|
||||
@ace.setShowInvisibles false
|
||||
@ace.setShowInvisibles (aceConfig.invisibles || false)
|
||||
@ace.setBehavioursEnabled false
|
||||
@ace.setAnimatedScroll true
|
||||
@ace.setKeyboardHandler (@keyBindings[aceConfig.keyBindings] || null)
|
||||
@toggleControls null, @writable
|
||||
@aceSession.selection.on 'changeCursor', @onCursorActivity
|
||||
$(@ace.container).find('.ace_gutter').on 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick
|
||||
|
@ -551,6 +559,12 @@ module.exports = class SpellView extends View
|
|||
pretty = @spellThang.aether.beautify ugly
|
||||
@ace.setValue pretty
|
||||
|
||||
onChangeEditorConfig: (e) ->
|
||||
aceConfig = me.get 'aceConfig'
|
||||
@ace.setDisplayIndentGuides (aceConfig.indentGuides || false)
|
||||
@ace.setShowInvisibles (aceConfig.invisibles || false)
|
||||
@ace.setKeyboardHandler (@keyBindings[aceConfig.keyBindings] || null)
|
||||
|
||||
dismiss: ->
|
||||
@recompile() if @spell.hasChangedSignificantly @getSource()
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ errors = require '../commons/errors'
|
|||
async = require 'async'
|
||||
|
||||
serverProperties = ['passwordHash', 'emailLower', 'nameLower', 'passwordReset']
|
||||
privateProperties = ['permissions', 'email', 'firstName', 'lastName', 'gender', 'facebookID', 'music', 'volume']
|
||||
privateProperties = ['permissions', 'email', 'firstName', 'lastName', 'gender', 'facebookID', 'music', 'volume', 'aceConfig']
|
||||
|
||||
UserHandler = class UserHandler extends Handler
|
||||
modelClass: User
|
||||
|
@ -18,7 +18,7 @@ UserHandler = class UserHandler extends Handler
|
|||
'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume',
|
||||
'firstName', 'lastName', 'gender', 'facebookID', 'emailSubscriptions',
|
||||
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
|
||||
'wizard'
|
||||
'wizard', 'aceConfig'
|
||||
]
|
||||
|
||||
jsonSchema: schema
|
||||
|
|
|
@ -45,6 +45,11 @@ UserSchema = c.object {},
|
|||
wizard: c.object {},
|
||||
colorConfig: c.object {additionalProperties: c.colorConfig()}
|
||||
|
||||
aceConfig: c.object {},
|
||||
keyBindings: {type: 'string', 'default': 'default', 'enum': ['default', 'vim', 'emacs']}
|
||||
invisibles: {type: 'boolean', 'default': false}
|
||||
indentGuides: {type: 'boolean', 'default': false}
|
||||
|
||||
c.extendBasicProperties UserSchema, 'user'
|
||||
|
||||
module.exports = UserSchema
|
||||
|
|
Loading…
Add table
Reference in a new issue