Skip to content

Commit

Permalink
feat(UI): textarea autofocus selecting a query tab, closes #166
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jan 9, 2022
1 parent d9a3eab commit b4545b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 6 additions & 11 deletions src/renderer/components/Workspace.vue
Expand Up @@ -18,7 +18,6 @@
<li
v-for="(tab, i) of draggableTabs"
:key="i"
:ref="selectedTab === tab.uid ? 'tab-selected' : ''"
class="tab-item tab-draggable"
draggable="true"
:class="{'active': selectedTab === tab.uid}"
Expand Down Expand Up @@ -568,7 +567,7 @@ export default {
return this.workspace ? this.workspace.selectedTab : null;
},
queryTabs () {
return this.workspace.tabs.filter(tab => tab.type === 'query');
return this.workspace ? this.workspace.tabs.filter(tab => tab.type === 'query') : [];
},
schemaChild () {
for (const key in this.workspace.breadcrumbs) {
Expand All @@ -584,16 +583,12 @@ export default {
}
},
watch: {
selectedTab (newVal, oldVal) {
if (newVal !== oldVal) {
queryTabs: function (newVal, oldVal) {
if (newVal.length > oldVal.length) {
setTimeout(() => {
const element = this.$refs['tab-selected'] ? this.$refs['tab-selected'][0] : null;
if (element) {
element.setAttribute('tabindex', '-1');
element.focus();
element.removeAttribute('tabindex');
}
}, 50);
const scroller = this.$refs.tabWrap;
if (scroller) scroller.$el.scrollLeft = scroller.$el.scrollWidth;
}, 0);
}
}
},
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/components/WorkspaceTabQuery.vue
Expand Up @@ -218,8 +218,13 @@ export default {
},
watch: {
isSelected (val) {
if (val)
if (val) {
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
setTimeout(() => {
if (this.$refs.queryEditor)
this.$refs.queryEditor.editor.focus();
}, 0);
}
},
selectedSchema () {
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
Expand Down

0 comments on commit b4545b1

Please sign in to comment.