diff --git a/apps/desktop/src/components/redis/RedisGroupedKeyList.vue b/apps/desktop/src/components/redis/RedisGroupedKeyList.vue index c102044232..a84359ab92 100644 --- a/apps/desktop/src/components/redis/RedisGroupedKeyList.vue +++ b/apps/desktop/src/components/redis/RedisGroupedKeyList.vue @@ -13,7 +13,7 @@ import RedisGroupHeader from "./RedisGroupHeader.vue"; import { createRedisKeyViewYield } from "@/lib/redis/redisKeyViewScheduler"; const props = defineProps<{ keys: readonly RedisKeyInfo[]; config: RedisKeyGrouping; separator: string; scope: string; structureRevision: number; selected: string | null; checked: ReadonlySet; busy: boolean; metadataEpoch: number; treeAllowed?: boolean }>(); -const emit = defineEmits<{ select: [RedisKeyInfo]; check: [RedisKeyInfo, MouseEvent]; delete: [RedisKeyInfo, MouseEvent]; copy: [RedisKeyInfo]; scroll: [Event]; resize: []; requestList: [] }>(); +const emit = defineEmits<{ select: [RedisKeyInfo]; check: [RedisKeyInfo, MouseEvent]; pointerdown: [RedisKeyInfo, PointerEvent]; delete: [RedisKeyInfo, MouseEvent]; copy: [RedisKeyInfo]; scroll: [Event]; resize: []; requestList: [] }>(); const { t } = useI18n(); const expanded = shallowRef(new Set()); const working = ref(false); @@ -94,6 +94,7 @@ function firstUnobscuredRowIndex() { } defineExpose({ getScrollElement: () => scroller.value?.$el as HTMLElement | undefined, + getKeyRawsInDisplayOrder: () => source.filter((row): row is Extract => row.kind === "key").map((row) => row.key.key_raw), getViewportAnchor: () => { const rowIndex = firstUnobscuredRowIndex(); const row = source[rowIndex]; @@ -213,10 +214,12 @@ onDeactivated(() => { />
diff --git a/apps/desktop/src/components/redis/RedisKeyBrowser.vue b/apps/desktop/src/components/redis/RedisKeyBrowser.vue index 3678eeda2c..7576420fd2 100644 --- a/apps/desktop/src/components/redis/RedisKeyBrowser.vue +++ b/apps/desktop/src/components/redis/RedisKeyBrowser.vue @@ -182,6 +182,10 @@ const keyMetadataEpoch = ref(0); /** Bumped only when a TTL refresh changes membership in the no-expiry projection. */ const noExpiryProjectionEpoch = ref(0); const selectionAnchorRowId = ref(null); +const dragSelection = ref<{ startRaw: string; baseChecked: Set; active: boolean; lastEndRaw?: string; startX: number; startY: number } | null>(null); +// A click fires after pointerup on the same gesture; an active rubber-band drag +// must not fall through to opening the row it started (or ended) on. +const suppressNextRowClick = ref(false); const selectedGroupLeafCounts = shallowRef>(new Map()); const deletingKeys = ref(false); const showBatchExpiryDialog = ref(false); @@ -746,6 +750,66 @@ function setKeysChecked(keyRaws: Iterable, checked: boolean) { selectionEpoch.value++; } +function dragSelectionRows(startRaw: string, endRaw: string, baseChecked: ReadonlySet) { + const groupedDisplayKeys = customGrouping.value.enabled ? groupedKeyListRef.value?.getKeyRawsInDisplayOrder?.() : undefined; + const keys = groupedDisplayKeys?.length ? groupedDisplayKeys : visibleRows.value.flatMap((row) => (row.node.kind === "leaf" ? [row.node.keyRaw] : [])); + const start = keys.indexOf(startRaw); + const end = keys.indexOf(endRaw); + if (start < 0 || end < 0) return; + const range = new Set(keys.slice(Math.min(start, end), Math.max(start, end) + 1)); + // Keep earlier batches selected, while letting the current drag range shrink + // or expand as the pointer moves back and forth. Each row is toggled against + // the selection snapshot, so mixed ranges add unselected rows and remove + // selected rows in the same gesture. + const next = new Set(baseChecked); + for (const keyRaw of range) { + if (baseChecked.has(keyRaw)) next.delete(keyRaw); + else next.add(keyRaw); + } + checkedKeys.value = next; + selectedGroupLeafCounts.value = groupLeafCountsFromChecked(next); + selectionEpoch.value++; +} + +function onKeyPointerDown(node: RedisKeyTreeNode, event: PointerEvent) { + if (event.button !== 0 || selectionBusy.value || node.kind !== "leaf" || (event.target as HTMLElement | null)?.closest("input,button")) return; + suppressNextRowClick.value = false; + dragSelection.value = { startRaw: node.keyRaw, baseChecked: new Set(checkedKeys.value), active: false, startX: event.clientX, startY: event.clientY }; +} + +function onKeyPointerMove(event: PointerEvent) { + const drag = dragSelection.value; + if (!drag || selectionBusy.value) return; + // A missed pointerup (or a touch/pen takeover) leaves the drag armed; hover + // moves with no button pressed must not keep toggling rows. + if ((event.buttons & 1) === 0) { + if (drag.active) suppressNextRowClick.value = true; + dragSelection.value = null; + return; + } + if (!drag.active && Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) < 4) return; + const row = (event.target as HTMLElement | null)?.closest("[data-redis-key-raw]"); + const endRaw = row?.dataset.redisKeyRaw; + if (!endRaw) return; + drag.active = true; + event.preventDefault(); + // Recomputing the range walks the full display order; skip while the pointer + // stays on the same row (visibleRows can hold 100k+ keys after Fetch All). + if (drag.lastEndRaw === endRaw) return; + drag.lastEndRaw = endRaw; + dragSelectionRows(drag.startRaw, endRaw, drag.baseChecked); +} + +function onKeyPointerUp() { + if (dragSelection.value?.active) suppressNextRowClick.value = true; + dragSelection.value = null; +} + +function onKeyPointerCancel() { + if (dragSelection.value?.active) suppressNextRowClick.value = true; + dragSelection.value = null; +} + function nodeKeyRaws(node: RedisKeyTreeNode): string[] { return node.kind === "leaf" ? [node.keyRaw] : collectRedisGroupKeyRaws(node); } @@ -1558,6 +1622,10 @@ function toggleGroup(groupId: string) { } function onRowClick(node: RedisKeyTreeNode, event?: MouseEvent) { + if (suppressNextRowClick.value) { + suppressNextRowClick.value = false; + return; + } if (event && !selectionBusy.value && (event.shiftKey || event.ctrlKey || event.metaKey)) { toggleNodeCheck(node, event); if (node.kind === "leaf") { @@ -3059,6 +3127,9 @@ function onCommandInputKeydown(event: KeyboardEvent) { } onMounted(async () => { + window.addEventListener("pointermove", onKeyPointerMove); + window.addEventListener("pointerup", onKeyPointerUp); + window.addEventListener("pointercancel", onKeyPointerCancel); resumeRedisBrowserBackgroundWork(); void autofocusSearchOnce(); try { @@ -3092,6 +3163,9 @@ onActivated(async () => { onDeactivated(pauseRedisBrowserBackgroundWork); onUnmounted(() => { + window.removeEventListener("pointermove", onKeyPointerMove); + window.removeEventListener("pointerup", onKeyPointerUp); + window.removeEventListener("pointercancel", onKeyPointerCancel); pauseRedisBrowserBackgroundWork(); if (redisInfiniteScrollFrame) cancelAnimationFrame(redisInfiniteScrollFrame); redisInfiniteScrollFrame = 0; @@ -3429,6 +3503,7 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand }); @scroll="onRedisKeyScroll" @resize="maybeAutoLoadMoreRedisKeys" @select="(key) => onRowClick(redisKeyToFlatTreeRow(key, db).node)" + @pointerdown="(key, event) => onKeyPointerDown(redisKeyToFlatTreeRow(key, db).node, event)" @check="(key, event) => toggleNodeCheck(redisKeyToFlatTreeRow(key, db).node, event)" @copy="(key) => copyRedisKeyName(key.key_display)" @delete="(key, event) => requestKeyDelete(redisKeyToFlatTreeRow(key, db).node, event)" @@ -3457,6 +3532,7 @@ defineExpose({ focusSearch, insertCommand, executeCommand: executeAiCommand });