1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

add ctrl+enter for running queries #35

This commit is contained in:
lana-k
2021-04-22 14:53:14 +02:00
parent fdbac941d5
commit 9e29a12ebb
3 changed files with 48 additions and 3 deletions

View File

@@ -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.

View File

@@ -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()

View File

@@ -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: {