diff --git a/README.md b/README.md index 23afdf8..cd6460c 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Result panel has two modes: table view (fig. 3, fig. 4) and chart view (fig. 2). #### Run a query -Press `Run` button in the top toolbar or use `Ctrl+r`(`Cmd+r` for MacOS) keyboard shortcut to execute a query in the current opened tab. +Press `Run` button in the top toolbar or use `Ctrl+r` or `Ctrl+Enter`(`Cmd+r` or `Cmd+Enter` for MacOS) keyboard shortcut to execute a query in the current opened tab. > **Note:** Running is not available if a database was not chosen or a query for the current tab is not specified. diff --git a/src/components/MainMenu.vue b/src/components/MainMenu.vue index 0169c2c..98c2a7d 100644 --- a/src/components/MainMenu.vue +++ b/src/components/MainMenu.vue @@ -170,8 +170,8 @@ export default { }, _keyListener (e) { if (this.$route.path === '/editor') { - // Run query Ctrl+R - if (e.key === 'r' && (e.ctrlKey || e.metaKey)) { + // Run query Ctrl+R or Ctrl+Enter + if ((e.key === 'r' || e.key === 'Enter') && (e.ctrlKey || e.metaKey)) { e.preventDefault() if (!this.runDisabled) { this.currentQuery.execute() diff --git a/tests/components/MainMenu.spec.js b/tests/components/MainMenu.spec.js index be7bc17..c4693db 100644 --- a/tests/components/MainMenu.spec.js +++ b/tests/components/MainMenu.spec.js @@ -227,6 +227,51 @@ describe('MainMenu.vue', () => { expect(state.currentTab.execute.calledTwice).to.equal(true) }) + it('Ctrl Enter calls currentTab.execute if running is enabled and route.path is "/editor"', + async () => { + const state = { + currentTab: { + query: 'SELECT * FROM foo', + execute: sinon.stub(), + tabIndex: 0 + }, + tabs: [{ isUnsaved: true }], + schema: [] + } + const store = new Vuex.Store({ state }) + const $route = { path: '/editor' } + const $router = { push: sinon.stub() } + + wrapper = shallowMount(MainMenu, { + store, + mocks: { $route, $router }, + stubs: ['router-link'] + }) + + const ctrlEnter = new KeyboardEvent('keydown', { key: 'Enter', ctrlKey: true }) + const metaEnter = new KeyboardEvent('keydown', { key: 'Enter', metaKey: true }) + // Running is enabled and route path is editor + document.dispatchEvent(ctrlEnter) + expect(state.currentTab.execute.calledOnce).to.equal(true) + document.dispatchEvent(metaEnter) + expect(state.currentTab.execute.calledTwice).to.equal(true) + + // Running is disabled and route path is editor + await wrapper.vm.$set(state, 'schema', null) + document.dispatchEvent(ctrlEnter) + expect(state.currentTab.execute.calledTwice).to.equal(true) + document.dispatchEvent(metaEnter) + expect(state.currentTab.execute.calledTwice).to.equal(true) + + // Running is enabled and route path is not editor + await wrapper.vm.$set(state, 'schema', []) + await wrapper.vm.$set($route, 'path', '/my-queries') + document.dispatchEvent(ctrlEnter) + expect(state.currentTab.execute.calledTwice).to.equal(true) + document.dispatchEvent(metaEnter) + expect(state.currentTab.execute.calledTwice).to.equal(true) + }) + it('Ctrl B calls createNewQuery', async () => { const state = { currentTab: {