diff options
author | Phil Hughes <me@iamphill.com> | 2018-04-26 10:13:10 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-04-26 10:13:10 +0100 |
commit | c83ed559e107476a4cf9d50fd35874d523506486 (patch) | |
tree | 3565d13bb447ba3b7a9c06e2991543514714de64 /app/assets/javascripts/ide/lib | |
parent | 70affaa0663f8fd4aa1aa08f85e35d312e78fee1 (diff) | |
parent | 9f35f6d9d53638aeb8ee917a388705458ddd87d7 (diff) | |
download | gitlab-ce-c83ed559e107476a4cf9d50fd35874d523506486.tar.gz |
Merge branch 'ide-workbench-bar' into ide-activity-bar-review-mode
Diffstat (limited to 'app/assets/javascripts/ide/lib')
-rw-r--r-- | app/assets/javascripts/ide/lib/editor.js | 33 | ||||
-rw-r--r-- | app/assets/javascripts/ide/lib/keymap.json | 11 |
2 files changed, 44 insertions, 0 deletions
diff --git a/app/assets/javascripts/ide/lib/editor.js b/app/assets/javascripts/ide/lib/editor.js index af506f1d0ea..489c7c1a03a 100644 --- a/app/assets/javascripts/ide/lib/editor.js +++ b/app/assets/javascripts/ide/lib/editor.js @@ -1,10 +1,12 @@ import _ from 'underscore'; +import store from '../stores'; import DecorationsController from './decorations/controller'; import DirtyDiffController from './diff/controller'; import Disposable from './common/disposable'; import ModelManager from './common/model_manager'; import editorOptions, { defaultEditorOptions } from './editor_options'; import gitlabTheme from './themes/gl_theme'; +import keymap from './keymap.json'; export const clearDomElement = el => { if (!el || !el.firstChild) return; @@ -53,6 +55,8 @@ export default class Editor { )), ); + this.addCommands(); + window.addEventListener('resize', this.debouncedUpdate, false); } } @@ -70,6 +74,8 @@ export default class Editor { })), ); + this.addCommands(); + window.addEventListener('resize', this.debouncedUpdate, false); } } @@ -186,4 +192,31 @@ export default class Editor { static renderSideBySide(domElement) { return domElement.offsetWidth >= 700; } + + addCommands() { + const getKeyCode = key => { + const monacoKeyMod = key.indexOf('KEY_') === 0; + + return monacoKeyMod ? this.monaco.KeyCode[key] : this.monaco.KeyMod[key]; + }; + + keymap.forEach(command => { + const keybindings = command.bindings.map(binding => { + const keys = binding.split('+'); + + // eslint-disable-next-line no-bitwise + return keys.length > 1 ? getKeyCode(keys[0]) | getKeyCode(keys[1]) : getKeyCode(keys[0]); + }); + + this.instance.addAction({ + id: command.id, + label: command.label, + keybindings, + run() { + store.dispatch(command.action.name, command.action.params); + return null; + }, + }); + }); + } } diff --git a/app/assets/javascripts/ide/lib/keymap.json b/app/assets/javascripts/ide/lib/keymap.json new file mode 100644 index 00000000000..131abfebbed --- /dev/null +++ b/app/assets/javascripts/ide/lib/keymap.json @@ -0,0 +1,11 @@ +[ + { + "id": "file-finder", + "label": "File finder", + "bindings": ["CtrlCmd+KEY_P"], + "action": { + "name": "toggleFileFinder", + "params": true + } + } +] |