From 5e62391bb0fdb51b67c3349a1a098a0ad8425529 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Thu, 11 May 2017 07:45:42 -0500 Subject: [PATCH] WIP #1025 Added keybinding customization --- .../widgets/TextEditor/TextEditorWidget.js | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/visualizers/widgets/TextEditor/TextEditorWidget.js b/src/visualizers/widgets/TextEditor/TextEditorWidget.js index e60ad0df3..058bb7fdc 100644 --- a/src/visualizers/widgets/TextEditor/TextEditorWidget.js +++ b/src/visualizers/widgets/TextEditor/TextEditorWidget.js @@ -18,6 +18,7 @@ define([ var TextEditorWidget, WIDGET_CLASS = 'text-editor', DEFAULT_SETTINGS = { + keybindings: 'default', theme: 'solarized_dark', fontSize: 12 }; @@ -118,7 +119,6 @@ define([ // // maybe some of these should be under a "Settings" option... - // TODO: get the component settings var fontSizes = [8, 10, 11, 12, 14], themes = [ 'Solarized Light', @@ -127,24 +127,15 @@ define([ 'Eclipse', 'Monokai' ], + keybindings = [ + 'default', + 'vim', + 'emacs' + ], menuItems = { setKeybindings: { name: 'Keybindings...', - items: { - ace: { - name: 'default', - isHtmlName: true, - callback: () => console.log('setting keybindings to def') - }, - vim: { - name: 'vim', - callback: () => console.log('setting keybindings to vim') - }, - emacs: { - name: 'emacs', - callback: () => console.log('setting keybindings to emacs') - } - } + items: {} }, setFontSize: { name: 'Font...', @@ -194,6 +185,26 @@ define([ }; }); + keybindings.forEach(name => { + var handler = name.toLowerCase().replace(/ /g, '_'), + isSet = handler === this.editorSettings.keybindings; + + if (isSet) { + name = '' + name + ''; + } + + menuItems.setKeybindings.items[handler] = { + name: name, + isHtmlName: isSet, + callback: () => { + this.editorSettings.keybindings = handler; + this.editor.setKeyboardHandler(handler === 'default' ? + null : 'ace/keyboard/' + handler); + // TODO + } + }; + }); + return menuItems; };