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

fix(files): Do not add drag handlers on rename #42242

Merged
merged 2 commits into from
Dec 13, 2023
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
42 changes: 33 additions & 9 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
:data-cy-files-list-row-name="source.basename"
:draggable="canDrag"
class="files-list__row"
@contextmenu="onRightClick"
@dragover="onDragOver"
@dragleave="onDragLeave"
@dragstart="onDragStart"
@dragend="onDragEnd"
@drop="onDrop">
v-on="rowListeners">
<!-- Failed indicator -->
<span v-if="source.attributes.failed" class="files-list__row--failed" />

Expand Down Expand Up @@ -110,7 +105,7 @@ import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { vOnClickOutside } from '@vueuse/components'
import moment from '@nextcloud/moment'
import Vue from 'vue'
import Vue, { defineComponent } from 'vue'

import { action as sidebarAction } from '../actions/sidebarAction.ts'
import { getDragAndDropPreview } from '../utils/dragUtils.ts'
Expand All @@ -132,7 +127,7 @@ import logger from '../logger.js'

Vue.directive('onClickOutside', vOnClickOutside)

export default Vue.extend({
export default defineComponent({
name: 'FileEntry',

components: {
Expand Down Expand Up @@ -194,6 +189,26 @@ export default Vue.extend({
},

computed: {
/**
* Conditionally add drag and drop listeners
* Do not add drag start and over listeners on renaming to allow to drag and drop text
*/
rowListeners() {
const conditionals = this.isRenaming
? {}
: {
dragstart: this.onDragStart,
dragover: this.onDragOver,
}

return {
...conditionals,
contextmenu: this.onRightClick,
dragleave: this.onDragLeave,
dragend: this.onDragEnd,
drop: this.onDrop,
}
},
currentView(): View {
return this.$navigation.active as View
},
Expand Down Expand Up @@ -303,6 +318,10 @@ export default Vue.extend({
},

canDrag() {
if (this.isRenaming) {
return false
}

const canDrag = (node: Node): boolean => {
return (node?.permissions & Permission.UPDATE) !== 0
}
Expand Down Expand Up @@ -449,7 +468,12 @@ export default Vue.extend({
logger.debug('Drag ended')
},

async onDrop(event) {
async onDrop(event: DragEvent) {
// skip if native drop like text drag and drop from files names
if (!this.draggingFiles && !event.dataTransfer?.files?.length) {
return
}

event.preventDefault()
event.stopPropagation()

Expand Down
4 changes: 3 additions & 1 deletion apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
</template>

<script lang="ts">
import type { PropType } from 'vue'

import { emit } from '@nextcloud/event-bus'
import { FileType, NodeStatus, Permission } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import Vue, { PropType } from 'vue'
import Vue from 'vue'

import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading