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

Lost focus in SQL query editor #54

This commit is contained in:
lana-k
2021-05-19 22:50:56 +02:00
parent 3e503f85a9
commit 414a116f94
4 changed files with 16 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
<template>
<div class="codemirror-container">
<codemirror v-model="query" :options="cmOptions" @changes="onChange" />
<codemirror ref="cm" v-model="query" :options="cmOptions" @changes="onChange" />
</div>
</template>
@@ -28,7 +28,6 @@ export default {
theme: 'neo',
lineNumbers: true,
line: true,
autofocus: true,
autoRefresh: true,
extraKeys: { 'Ctrl-Space': showHintOnDemand }
}
@@ -40,7 +39,10 @@ export default {
}
},
methods: {
onChange: debounce(showHint, 400)
onChange: debounce(showHint, 400),
focus () {
this.$refs.cm.codemirror.focus()
}
}
}
</script>

View File

@@ -8,7 +8,7 @@
>
<template #left-pane>
<div class="query-editor">
<sql-editor v-model="query" />
<sql-editor ref="sqlEditor" v-model="query" />
</div>
</template>
<template #right-pane>
@@ -86,9 +86,6 @@ export default {
return this.id === this.$store.state.currentTabId
}
},
created () {
this.$store.commit('setCurrentTab', this)
},
mounted () {
this.resizeObserver = new ResizeObserver(this.handleResize)
this.resizeObserver.observe(this.$refs.bottomPane)
@@ -98,9 +95,14 @@ export default {
this.resizeObserver.unobserve(this.$refs.bottomPane)
},
watch: {
isActive () {
if (this.isActive) {
this.$store.commit('setCurrentTab', this)
isActive: {
immediate: true,
async handler () {
if (this.isActive) {
this.$store.commit('setCurrentTab', this)
await this.$nextTick()
this.$refs.sqlEditor.focus()
}
}
},
query () {

View File

@@ -112,7 +112,7 @@ describe('fileIo.js', () => {
file = { type: 'application/x-sqlite3' }
expect(fu.isDatabase(file)).to.equal(true)
file = { type: '', name: 'test.db' }
expect(fu.isDatabase(file)).to.equal(true)

View File

@@ -115,6 +115,7 @@ describe('Tab.vue', () => {
})
state.currentTabId = 1
await wrapper.vm.$nextTick()
expect(mutations.setCurrentTab.calledOnceWith(state, wrapper.vm)).to.equal(true)
})