Skip to content

Commit

Permalink
feat: query tabs auto focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Dec 11, 2020
1 parent 3ed5ea0 commit f81312a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/renderer/components/QueryEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ monaco.languages.registerCompletionItemProvider('sql', completionItemProvider(mo
export default {
name: 'QueryEditor',
props: {
value: String
value: String,
autoFocus: { type: Boolean, default: false }
},
data () {
return {
Expand All @@ -40,6 +41,12 @@ export default {
const content = this.editor.getValue();
this.$emit('update:value', content);
});
if (this.autoFocus) {
setTimeout(() => {
this.editor.focus();
}, 20);
}
},
beforeDestroy () {
this.editor && this.editor.dispose();
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/components/WorkspacePropsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
</div>
</div>
<div class="th">
<div class="column-resizable">
<div class="column-resizable min-100">
<div class="table-column-title">
{{ $t('word.name') }}
</div>
</div>
</div>
<div class="th">
<div class="column-resizable">
<div class="column-resizable min-100">
<div class="table-column-title">
{{ $t('word.type') }}
</div>
Expand Down Expand Up @@ -231,4 +231,8 @@ export default {
.vscroll {
overflow: auto;
}
.min-100 {
min-width: 100px !important;
}
</style>
6 changes: 5 additions & 1 deletion src/renderer/components/WorkspaceQueryTab.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless">
<div class="workspace-query-runner column col-12">
<QueryEditor v-if="isSelected" :value.sync="query" />
<QueryEditor
v-if="isSelected"
:auto-focus="true"
:value.sync="query"
/>
<div class="workspace-query-runner-footer">
<div class="workspace-query-buttons">
<button
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/store/modules/workspaces.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ export default {
}
: workspace);
},
NEW_TAB (state, uid) {
NEW_TAB (state, { uid, tab }) {
tabIndex[uid] = tabIndex[uid] ? ++tabIndex[uid] : 1;

const newTab = {
uid: uidGen('T'),
uid: tab,
index: tabIndex[uid],
selected: false,
type: 'query',
Expand Down Expand Up @@ -338,7 +337,10 @@ export default {
lastBreadcrumbs = { ...breadcrumbsObj, ...payload };
},
newTab ({ commit }, uid) {
commit('NEW_TAB', uid);
const tab = uidGen('T');

commit('NEW_TAB', { uid, tab });
commit('SELECT_TAB', { uid, tab });
},
removeTab ({ commit }, payload) {
commit('REMOVE_TAB', payload);
Expand Down

0 comments on commit f81312a

Please sign in to comment.