Skip to content

Commit

Permalink
WIP #1025 Added keybinding customization
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed May 11, 2017
1 parent c131e30 commit 5e62391
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/visualizers/widgets/TextEditor/TextEditorWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ define([
var TextEditorWidget,
WIDGET_CLASS = 'text-editor',
DEFAULT_SETTINGS = {
keybindings: 'default',
theme: 'solarized_dark',
fontSize: 12
};
Expand Down Expand Up @@ -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',
Expand All @@ -127,24 +127,15 @@ define([
'Eclipse',
'Monokai'
],
keybindings = [
'default',
'vim',
'emacs'
],
menuItems = {
setKeybindings: {
name: 'Keybindings...',
items: {
ace: {
name: '<span style="font-weight: bold">default</span>',
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...',
Expand Down Expand Up @@ -194,6 +185,26 @@ define([
};
});

keybindings.forEach(name => {
var handler = name.toLowerCase().replace(/ /g, '_'),
isSet = handler === this.editorSettings.keybindings;

if (isSet) {
name = '<span style="font-weight: bold">' + name + '</span>';
}

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;
};

Expand Down

0 comments on commit 5e62391

Please sign in to comment.