Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Bugfix: Paste action (keyboard) not working in project spaces #7514

Merged
merged 9 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-keyboard-not-working-spaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Paste action (keyboard) not working in project spaces

We've fixed a bug which caused the user to be unable to paste in project spaces.

https://github.com/owncloud/web/issues/7510
https://github.com/owncloud/web/pull/7514
33 changes: 23 additions & 10 deletions packages/web-app-files/src/components/FilesList/KeyboardActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default defineComponent({
type: Array,
required: true
},
keybindOnElementId: {
type: String,
keybindOnElementIds: {
type: Array,
required: false,
default: 'files-view'
default: () => ['files-view', 'web-nav-sidebar']
}
},
setup() {
Expand All @@ -40,10 +40,14 @@ export default defineComponent({
},

mounted() {
const filesList = document.getElementById(this.keybindOnElementId)
if (filesList) {
filesList.addEventListener('keydown', this.handleShortcut, false)
for (const elementId of this.keybindOnElementIds) {
const element = document.getElementById(elementId)
if (element) {
element.addEventListener('keydown', this.handleSelectionShortcuts, false)
}
}
document.addEventListener('keydown', this.handleClipboardShortcuts)

const fileListClickedEvent = bus.subscribe('app.files.list.clicked', this.resetSelectionCursor)
const fileListClickedMetaEvent = bus.subscribe(
'app.files.list.clicked.meta',
Expand All @@ -58,7 +62,13 @@ export default defineComponent({
bus.unsubscribe('app.files.list.clicked', fileListClickedEvent)
bus.unsubscribe('app.files.list.clicked.meta', fileListClickedMetaEvent)
bus.unsubscribe('app.files.list.clicked.shift', fileListClickedShiftEvent)
filesList.removeEventListener('keydown', this.handleShortcut)
for (const elementId of this.keybindOnElementIds) {
const element = document.getElementById(elementId)
if (element) {
element.removeEventListener('keydown', this.handleSelectionShortcuts)
}
}
document.removeEventListener('keydown', this.handleClipboardShortcuts)
})
},

Expand All @@ -78,20 +88,23 @@ export default defineComponent({
addFileSelection: 'ADD_FILE_SELECTION'
}),

handleShortcut(event) {
handleSelectionShortcuts(event) {
const key = event.keyCode || event.which
const ctrl = window.navigator.platform.match('Mac') ? event.metaKey : event.ctrlKey
const shift = event.shiftKey

this.handleFileActionsShortcuts(key, ctrl)
this.handleFileSelectionShortcuts(key, shift, ctrl, event)
},

handleFileActionsShortcuts(key, ctrl) {
handleClipboardShortcuts(event) {
const key = event.keyCode || event.which
const ctrl = window.navigator.platform.match('Mac') ? event.metaKey : event.ctrlKey
const isCopyAction = key === 67
const isPasteAction = key === 86
const isCutAction = key === 88
const isTextSelected = window.getSelection().type === 'Range'

if (isTextSelected) return
if (isCopyAction && ctrl) return this.copySelectedFiles()
if (isPasteAction && ctrl) return this.handlePasteAction()
if (isCutAction && ctrl) return this.cutSelectedFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Spaces project view space image should show if given 1`] = `
<div class="space-overview oc-flex">
<keyboard-actions-stub paginatedresources="" keybindonelementid="files-view"></keyboard-actions-stub>
<keyboard-actions-stub paginatedresources="" keybindonelementids="files-view,web-nav-sidebar"></keyboard-actions-stub>
<files-view-wrapper-stub>
<app-bar-stub breadcrumbs="" breadcrumbscontextactionsitems="[object Object]" hasbulkactions="true" hassidebartoggle="true" hasviewoptions="true" showactionsonselection="true"></app-bar-stub>
<div>
Expand Down Expand Up @@ -41,7 +41,7 @@ exports[`Spaces project view space image should show if given 1`] = `

exports[`Spaces project view space readme should show if given 1`] = `
<div class="space-overview oc-flex">
<keyboard-actions-stub paginatedresources="" keybindonelementid="files-view"></keyboard-actions-stub>
<keyboard-actions-stub paginatedresources="" keybindonelementids="files-view,web-nav-sidebar"></keyboard-actions-stub>
<files-view-wrapper-stub>
<app-bar-stub breadcrumbs="" breadcrumbscontextactionsitems="[object Object]" hasbulkactions="true" hassidebartoggle="true" hasviewoptions="true" showactionsonselection="true"></app-bar-stub>
<div>
Expand Down