Skip to content

Commit

Permalink
feature: add ability to open directories in new tab with mouse-middle…
Browse files Browse the repository at this point in the history
…-button
  • Loading branch information
aleksey-hoffman committed Sep 11, 2021
1 parent 8969a6f commit a631a66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/DirItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Copyright © 2021 - present Aleksey Hoffman. All rights reserved.
@mousedown="handleDirItemMouseDown($event, source, index)"
@mouseenter="handleDirItemMouseEnter($event, source)"
@mouseleave="handleDirItemMouseLeave($event, source)"
@mousedown.middle="handleDirItemMiddleMouseDown($event, source)"
:id="`item-index-${index}`"
:data-item-id="source.id"
:index="index"
Expand Down Expand Up @@ -708,7 +709,11 @@ export default {
if (this.isDirItemSelected(item)) {
this.$store.dispatch('DESELECT_DIR_ITEM', item)
}
}
},
handleDirItemMiddleMouseDown (event, item) {
event.preventDefault()
this.$store.dispatch('ADD_TAB', {item})
},
}
}
</script>
Expand Down
11 changes: 9 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2817,14 +2817,21 @@ export default new Vuex.Store({
}
}
},
ADD_TAB (store) {
let item = store.state.navigatorView.selectedDirItems.getLast()
ADD_TAB (store, params) {
let item = params?.item
? params?.item
: store.state.navigatorView.selectedDirItems.getLast()
let isDirectory = item.type.includes('directory')

if (!isDirectory) {return}

let tabs = [...store.getters.selectedWorkspace.tabs]
let newTab = {
name: item.name,
path: item.path
}
const tabIndex = store.getters.selectedWorkspace.tabs.findIndex(tab => tab.path === newTab.path)

if (tabIndex === -1) {
tabs.push(newTab)
store.dispatch('SET_TABS', tabs)
Expand Down

0 comments on commit a631a66

Please sign in to comment.