Skip to content

Commit 02e6cf7

Browse files
authored
Merge pull request #42277 from nextcloud/fix/backport-files-drag-handler
[stable28] fix(files): Conditionally add drag handlers
2 parents 056401b + 040c767 commit 02e6cf7

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

apps/files/src/components/FileEntry.vue

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
:data-cy-files-list-row-name="source.basename"
2828
:draggable="canDrag"
2929
class="files-list__row"
30-
@contextmenu="onRightClick"
31-
@dragover="onDragOver"
32-
@dragleave="onDragLeave"
33-
@dragstart="onDragStart"
34-
@dragend="onDragEnd"
35-
@drop="onDrop">
30+
v-on="rowListeners">
3631
<!-- Failed indicator -->
3732
<span v-if="source.attributes.failed" class="files-list__row--failed" />
3833

@@ -110,7 +105,7 @@ import { showError } from '@nextcloud/dialogs'
110105
import { translate as t } from '@nextcloud/l10n'
111106
import { vOnClickOutside } from '@vueuse/components'
112107
import moment from '@nextcloud/moment'
113-
import Vue from 'vue'
108+
import Vue, { defineComponent } from 'vue'
114109
115110
import { action as sidebarAction } from '../actions/sidebarAction.ts'
116111
import { getDragAndDropPreview } from '../utils/dragUtils.ts'
@@ -132,7 +127,7 @@ import logger from '../logger.js'
132127
133128
Vue.directive('onClickOutside', vOnClickOutside)
134129
135-
export default Vue.extend({
130+
export default defineComponent({
136131
name: 'FileEntry',
137132
138133
components: {
@@ -194,6 +189,26 @@ export default Vue.extend({
194189
},
195190
196191
computed: {
192+
/**
193+
* Conditionally add drag and drop listeners
194+
* Do not add drag start and over listeners on renaming to allow to drag and drop text
195+
*/
196+
rowListeners() {
197+
const conditionals = this.isRenaming
198+
? {}
199+
: {
200+
dragstart: this.onDragStart,
201+
dragover: this.onDragOver,
202+
}
203+
204+
return {
205+
...conditionals,
206+
contextmenu: this.onRightClick,
207+
dragleave: this.onDragLeave,
208+
dragend: this.onDragEnd,
209+
drop: this.onDrop,
210+
}
211+
},
197212
currentView(): View {
198213
return this.$navigation.active as View
199214
},
@@ -303,6 +318,10 @@ export default Vue.extend({
303318
},
304319
305320
canDrag() {
321+
if (this.isRenaming) {
322+
return false
323+
}
324+
306325
const canDrag = (node: Node): boolean => {
307326
return (node?.permissions & Permission.UPDATE) !== 0
308327
}
@@ -449,7 +468,12 @@ export default Vue.extend({
449468
logger.debug('Drag ended')
450469
},
451470
452-
async onDrop(event) {
471+
async onDrop(event: DragEvent) {
472+
// skip if native drop like text drag and drop from files names
473+
if (!this.draggingFiles && !event.dataTransfer?.files?.length) {
474+
return
475+
}
476+
453477
event.preventDefault()
454478
event.stopPropagation()
455479

apps/files/src/components/FileEntry/FileEntryName.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
</template>
5555

5656
<script lang="ts">
57+
import type { PropType } from 'vue'
58+
5759
import { emit } from '@nextcloud/event-bus'
5860
import { FileType, NodeStatus, Permission } from '@nextcloud/files'
5961
import { loadState } from '@nextcloud/initial-state'
6062
import { showError, showSuccess } from '@nextcloud/dialogs'
6163
import { translate as t } from '@nextcloud/l10n'
6264
import axios from '@nextcloud/axios'
63-
import Vue, { PropType } from 'vue'
65+
import Vue from 'vue'
6466
6567
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
6668

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)