Commit a3566506 authored by Phil Hughes's avatar Phil Hughes

added keymap to editor to open file finder

clear file finder on close
esc closes the file finder
parent ba4dde7c
...@@ -45,7 +45,14 @@ export default { ...@@ -45,7 +45,14 @@ export default {
}, },
watch: { watch: {
fileFindVisible() { fileFindVisible() {
this.$nextTick(() => this.$refs.searchInput.focus()); this.$nextTick(() => {
if (!this.fileFindVisible) {
this.searchText = '';
this.focusedIndex = 0;
} else {
this.$refs.searchInput.focus();
}
});
}, },
searchText() { searchText() {
if (this.searchText.trim() !== '') { if (this.searchText.trim() !== '') {
...@@ -77,6 +84,10 @@ export default { ...@@ -77,6 +84,10 @@ export default {
// ENTER // ENTER
this.openFile(this.filteredBlobs[this.focusedIndex]); this.openFile(this.filteredBlobs[this.focusedIndex]);
break; break;
case 27:
// ESC
this.toggleFileFinder(false);
break;
default: default:
break; break;
} }
......
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
return returnValue; return returnValue;
}; };
Mousetrap.bind('t', e => { Mousetrap.bind(['t', 'command+p', 'ctrl+p'], e => {
e.preventDefault(); e.preventDefault();
this.toggleFileFinder(true); this.toggleFileFinder(true);
}); });
......
import _ from 'underscore'; import _ from 'underscore';
import store from '../stores';
import DecorationsController from './decorations/controller'; import DecorationsController from './decorations/controller';
import DirtyDiffController from './diff/controller'; import DirtyDiffController from './diff/controller';
import Disposable from './common/disposable'; import Disposable from './common/disposable';
import ModelManager from './common/model_manager'; import ModelManager from './common/model_manager';
import editorOptions, { defaultEditorOptions } from './editor_options'; import editorOptions, { defaultEditorOptions } from './editor_options';
import gitlabTheme from './themes/gl_theme'; import gitlabTheme from './themes/gl_theme';
import keymap from './keymap.json';
export const clearDomElement = el => { export const clearDomElement = el => {
if (!el || !el.firstChild) return; if (!el || !el.firstChild) return;
...@@ -53,6 +55,8 @@ export default class Editor { ...@@ -53,6 +55,8 @@ export default class Editor {
)), )),
); );
this.addCommands();
window.addEventListener('resize', this.debouncedUpdate, false); window.addEventListener('resize', this.debouncedUpdate, false);
} }
} }
...@@ -73,6 +77,8 @@ export default class Editor { ...@@ -73,6 +77,8 @@ export default class Editor {
})), })),
); );
this.addCommands();
window.addEventListener('resize', this.debouncedUpdate, false); window.addEventListener('resize', this.debouncedUpdate, false);
} }
} }
...@@ -189,4 +195,30 @@ export default class Editor { ...@@ -189,4 +195,30 @@ export default class Editor {
static renderSideBySide(domElement) { static renderSideBySide(domElement) {
return domElement.offsetWidth >= 700; return domElement.offsetWidth >= 700;
} }
addCommands() {
const getKeyCode = key => {
const monacoKeyMod = key.indexOf('KEY_') === 0;
return monacoKeyMod ? monaco.KeyCode[key] : monaco.KeyMod[key];
};
keymap.forEach(command => {
const keybindings = command.bindings.map(binding => {
const keys = binding.split('+');
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;
},
});
});
}
} }
[
{
"id": "file-finder",
"label": "File finder",
"bindings": ["CtrlCmd+KEY_P"],
"action": {
"name": "toggleFileFinder",
"params": true
}
}
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment