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:
@@ -60,7 +60,7 @@ Result panel has two modes: table view (fig. 3, fig. 4) and chart view (fig. 2).
|
|||||||
|
|
||||||
#### Run a query
|
#### 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.
|
> **Note:** Running is not available if a database was not chosen or a query for the current tab is not specified.
|
||||||
|
|
||||||
|
|||||||
@@ -170,8 +170,8 @@ export default {
|
|||||||
},
|
},
|
||||||
_keyListener (e) {
|
_keyListener (e) {
|
||||||
if (this.$route.path === '/editor') {
|
if (this.$route.path === '/editor') {
|
||||||
// Run query Ctrl+R
|
// Run query Ctrl+R or Ctrl+Enter
|
||||||
if (e.key === 'r' && (e.ctrlKey || e.metaKey)) {
|
if ((e.key === 'r' || e.key === 'Enter') && (e.ctrlKey || e.metaKey)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!this.runDisabled) {
|
if (!this.runDisabled) {
|
||||||
this.currentQuery.execute()
|
this.currentQuery.execute()
|
||||||
|
|||||||
@@ -227,6 +227,51 @@ describe('MainMenu.vue', () => {
|
|||||||
expect(state.currentTab.execute.calledTwice).to.equal(true)
|
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 () => {
|
it('Ctrl B calls createNewQuery', async () => {
|
||||||
const state = {
|
const state = {
|
||||||
currentTab: {
|
currentTab: {
|
||||||
|
|||||||
Reference in New Issue
Block a user