Skip to content

Commit 2f9719c

Browse files
committed
feat(folders): unify tree hover with accent-hover and add snippet drag indication
1 parent f1881b8 commit 2f9719c

1 file changed

Lines changed: 42 additions & 10 deletions

File tree

src/renderer/components/sidebar/folders/TreeNode.vue

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const hasChildren = computed(
6161
6262
const isFirst = computed(() => props.index === 0)
6363
64+
const isDraggingSnippet = ref(false)
65+
6466
const isHovered = computed(() => {
6567
return props.node.id === hoveredId.value && overPosition.value === 'center'
6668
})
@@ -98,11 +100,11 @@ const betweenLineStyle = computed(() => {
98100
}
99101
100102
if (overPosition.value === 'before') {
101-
style.top = '-6px'
103+
style.top = '-4px'
102104
}
103105
104106
if (overPosition.value === 'after') {
105-
style.bottom = '-6px'
107+
style.bottom = '-4px'
106108
}
107109
108110
return style
@@ -229,6 +231,14 @@ function onDragEnter() {
229231
function onDragOver(e: DragEvent) {
230232
hoveredId.value = props.node.id
231233
234+
if (e.dataTransfer?.types.includes('snippetids')) {
235+
isDraggingSnippet.value = true
236+
overPosition.value = 'center'
237+
return
238+
}
239+
240+
isDraggingSnippet.value = false
241+
232242
const isDraggingNode
233243
= store.dragNodes?.some(node => node.id === props.node.id)
234244
|| store.dragNode?.id === props.node.id
@@ -254,6 +264,7 @@ function onDragOver(e: DragEvent) {
254264
function onDragLeave() {
255265
hoveredId.value = undefined
256266
overPosition.value = undefined
267+
isDraggingSnippet.value = false
257268
}
258269
259270
async function onDrop(e: DragEvent) {
@@ -265,6 +276,9 @@ async function onDrop(e: DragEvent) {
265276
if (snippets && snippets.length > 0) {
266277
// Если все сниппеты уже в папке и не удалены
267278
if (snippets.every(s => s.folder?.id === props.node.id && !s.isDeleted)) {
279+
hoveredId.value = undefined
280+
overPosition.value = undefined
281+
isDraggingSnippet.value = false
268282
return
269283
}
270284
@@ -280,6 +294,11 @@ async function onDrop(e: DragEvent) {
280294
if (state.snippetId && ids.includes(state.snippetId)) {
281295
selectFirstSnippet()
282296
}
297+
298+
hoveredId.value = undefined
299+
overPosition.value = undefined
300+
isDraggingSnippet.value = false
301+
return
283302
}
284303
285304
if (!store.dragNode || !isAllowed.value)
@@ -329,7 +348,7 @@ if (focusHandler)
329348
<template>
330349
<div
331350
data-folder-tree-node
332-
class="node user-select-none relative *:mt-[2px]"
351+
class="node user-select-none relative"
333352
:class="{
334353
'has-children': hasChildren,
335354
'is-dragged': isDragged,
@@ -344,10 +363,12 @@ if (focusHandler)
344363
<div
345364
:id="String(node.id)"
346365
ref="rowRef"
347-
class="node__row user-select-none relative flex"
366+
class="node__row user-select-none relative flex py-px"
348367
:class="{
349368
'is-hovered':
350-
(isHovered && isAllowed) || hoveredNodeId === String(node.id),
369+
(isHovered && isAllowed)
370+
|| (isHovered && isDraggingSnippet)
371+
|| hoveredNodeId === String(node.id),
351372
'is-selected': isSelected,
352373
'is-multi-selected': isMultiSelected,
353374
'is-focused': isFocused,
@@ -432,6 +453,7 @@ if (focusHandler)
432453
</template>
433454
<svg
434455
v-if="isShowBetweenLine"
456+
class="pointer-events-none z-20"
435457
height="10"
436458
:style="betweenLineStyle"
437459
>
@@ -469,23 +491,33 @@ if (focusHandler)
469491
&::before {
470492
content: "";
471493
left: v-bind(hoveredOffsetStyle);
472-
@apply bg-primary absolute top-0 right-0 bottom-0 z-0 rounded-md;
494+
@apply absolute top-0 right-0 bottom-0 z-0 rounded-md;
473495
}
474496
}
475-
&.is-selected {
497+
&:hover:not(.is-selected):not(.is-focused):not(.is-multi-selected) {
476498
@apply text-accent-foreground;
499+
&::before {
500+
content: "";
501+
left: v-bind(hoveredOffsetStyle);
502+
@apply bg-accent-hover absolute top-0 right-0 bottom-0 z-0 rounded-md;
503+
}
504+
}
505+
&.is-hovered {
506+
&::before {
507+
@apply bg-accent-hover;
508+
}
509+
}
510+
&.is-selected {
477511
&::before {
478512
@apply bg-accent;
479513
}
480514
}
481515
&.is-multi-selected {
482-
@apply text-accent-foreground;
483516
&::before {
484517
@apply bg-accent/80;
485518
}
486519
}
487-
&.is-focused,
488-
&.is-hovered {
520+
&.is-focused {
489521
@apply text-primary-foreground;
490522
&::before {
491523
@apply bg-primary;

0 commit comments

Comments
 (0)