Skip to content

Commit

Permalink
Make keyboard shortcuts work again
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr committed Nov 28, 2016
1 parent dca8998 commit 14d4606
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 11 additions & 1 deletion client/app/pages/queries/query-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'brace/mode/python';
import 'brace/mode/sql';
import 'brace/mode/json';
import 'brace/ext/language_tools';
import { map } from 'underscore';
import { each, map } from 'underscore';

// By default Ace will try to load snippet files for the different modes and fail.
// We don't need them, so we use these placeholders until we define our own.
Expand All @@ -25,6 +25,7 @@ function queryEditor(QuerySnippet) {
query: '=',
schema: '=',
syntax: '=',
shortcuts: '=',
},
template: '<div ui-ace="editorOptions" ng-model="query.query"></div>',
link: {
Expand All @@ -42,6 +43,15 @@ function queryEditor(QuerySnippet) {
autoScrollEditorIntoView: true,
},
onLoad(editor) {
// Release Cmd/Ctrl+L to the browser
editor.commands.bindKey('Cmd+L', null);
editor.commands.bindKey('Ctrl+L', null);

each($scope.shortcuts, (fn, key) => {
key = key.replace('meta', 'Cmd').replace('ctrl', 'Ctrl');
editor.commands.bindKey(key, () => fn());
});

QuerySnippet.query((snippets) => {
window.ace.acequire(['ace/snippets'], (snippetsModule) => {
const snippetManager = snippetsModule.snippetManager;
Expand Down
6 changes: 4 additions & 2 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ <h3>
</div>
</div>
<p style="height:calc(100% - 40px);">
<query-editor query="query" schema="schema" syntax="dataSource.syntax"
lock="queryFormatting"></query-editor>
<query-editor query="query"
schema="schema"
syntax="dataSource.syntax"
shortcuts="shortcuts"></query-editor>
</p>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions client/app/pages/queries/source-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function QuerySourceCtrl(Events, toastr, $controller, $scope, $location, $http,
},
});

const shortcuts = {
$scope.shortcuts = {
'meta+s': function save() {
if ($scope.canEdit) {
$scope.saveQuery();
Expand All @@ -46,7 +46,7 @@ function QuerySourceCtrl(Events, toastr, $controller, $scope, $location, $http,
'ctrl+enter': $scope.executeQuery,
};

KeyboardShortcuts.bind(shortcuts);
KeyboardShortcuts.bind($scope.shortcuts);

// @override
$scope.saveQuery = (options, data) => {
Expand Down Expand Up @@ -108,7 +108,7 @@ function QuerySourceCtrl(Events, toastr, $controller, $scope, $location, $http,
});

$scope.$on('$destroy', () => {
KeyboardShortcuts.unbind(shortcuts);
KeyboardShortcuts.unbind($scope.shortcuts);
});
}

Expand Down

0 comments on commit 14d4606

Please sign in to comment.