Skip to content

Commit

Permalink
Refactor/slim code
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Jun 22, 2022
1 parent 05ede64 commit 75d91c7
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/web-app-files/src/components/FilesList/KeymapActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Resource } from '../../helpers/resource'
import { mapActions, mapState, mapMutations } from 'vuex'
export default {
props: {},
data: () => {
return {
selectionCursor: 0
Expand Down Expand Up @@ -66,13 +64,13 @@ export default {
},
handleFileActionsShortcuts(key, ctrl) {
if (!ctrl /* CTRL | CMD */) return
const isCopyAction = key === 67
const isPasteAction = key === 86
const isCutAction = key === 88
if (isCopyAction) return this.copySelectedFiles()
if (isPasteAction) return this.handlePasteAction()
if (isCutAction) return this.cutSelectedFiles()
if (isCopyAction && ctrl) return this.copySelectedFiles()
if (isPasteAction && ctrl) return this.handlePasteAction()
if (isCutAction && ctrl) return this.cutSelectedFiles()
},
handleFileSelectionShortcuts(key, shift, ctrl, event) {
Expand Down Expand Up @@ -100,12 +98,7 @@ export default {
},
handleShiftUpAction() {
const latestSelectedRow = document.querySelectorAll(
`[data-item-id='${this.latestSelectedId}']`
)[0]
const nextRow = latestSelectedRow.previousSibling as HTMLElement
if (nextRow === null) return
const nextResourceId = nextRow.getAttribute('data-item-id')
const nextResourceId = this.getNextResourceId(true)
if (this.selectionCursor > 0) {
// deselect
this.toggleFileSelection({ id: this.latestSelectedId })
Expand All @@ -118,13 +111,7 @@ export default {
},
handleShiftDownAction() {
const latestSelectedRow = document.querySelectorAll(
`[data-item-id='${this.latestSelectedId}']`
)[0]
const nextRow = latestSelectedRow.nextSibling as HTMLElement
if (nextRow === null) return
const nextResourceId = nextRow.getAttribute('data-item-id')
const nextResourceId = this.getNextResourceId()
if (this.selectionCursor < 0) {
// deselect
this.toggleFileSelection({ id: this.latestSelectedId })
Expand All @@ -147,7 +134,17 @@ export default {
$ngettext: this.$ngettext,
upsertResource: this.UPSERT_RESOURCE
})
}
},
getNextResourceId(previous=false) {
const latestSelectedRow = document.querySelectorAll(
`[data-item-id='${this.latestSelectedId}']`
)[0]
const nextRow = (previous ? latestSelectedRow.previousSibling : latestSelectedRow.nextSibling) as HTMLElement
if (nextRow === null) return
const nextResourceId = nextRow.getAttribute('data-item-id')
return nextResourceId
}
}
}
</script>

0 comments on commit 75d91c7

Please sign in to comment.