Commit 7f3cf96c85

7f3cf96c85eb4521d39fab1c392008f6618c9e5b

parent: 002c6123df

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-09 14:07 UTC

fixing text selection of scrapetable

Layout: unified · split

docs/.vitepress/theme/components/ScrapeTable.vue +38 −10
@@ -85,11 +85,14 @@ const headerHeight = computed(() => {
8585// Drag to scroll + scroll indicator
8686const wrapRef = ref<HTMLElement | null>(null)
8787const canScrollRight = ref(false)
88let isDragging = false
88const isDragging = ref(false)
89let isPending = false
8990let startX = 0
9091let scrollStart = 0
92let pendingPointerId = -1
9193
9294const SCROLL_END_PX = 2
95const DRAG_THRESHOLD_PX = 5
9396
9497function checkScroll() {
9598 const el = wrapRef.value
@@ -97,26 +100,52 @@ function checkScroll() {
97100 canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - SCROLL_END_PX
98101}
99102
103function isTextTarget(e: PointerEvent) {
104 const target = e.target as Node | null
105 if (!target) return false
106 const node = target.nodeType === Node.TEXT_NODE ? target.parentElement : target as Element
107 if (!node) return false
108 const style = window.getComputedStyle(node as Element)
109 return style.userSelect !== 'none' && style.cursor !== 'default' || (node as Element).closest('td.site-name, th') !== null
110}
111
100112function onPointerDown(e: PointerEvent) {
113 if (e.button !== 0) return
101114 const el = wrapRef.value
102115 if (!el) return
103 isDragging = true
116 // Don't initiate drag when clicking on selectable text elements
117 if (isTextTarget(e)) return
118 isPending = true
104119 startX = e.clientX
105120 scrollStart = el.scrollLeft
106 el.setPointerCapture(e.pointerId)
107 el.style.cursor = 'grabbing'
121 pendingPointerId = e.pointerId
108122}
109123
110124function onPointerMove(e: PointerEvent) {
111 if (!isDragging || !wrapRef.value) return
112 wrapRef.value.scrollLeft = scrollStart - (e.clientX - startX)
125 const el = wrapRef.value
126 if (!el) return
127
128 // If user is actively selecting text, abort drag
129 if (isPending && window.getSelection()?.type === 'Range') {
130 isPending = false
131 return
132 }
133
134 if (isPending && Math.abs(e.clientX - startX) > DRAG_THRESHOLD_PX) {
135 isPending = false
136 isDragging.value = true
137 el.setPointerCapture(pendingPointerId)
138 }
139
140 if (!isDragging.value) return
141 el.scrollLeft = scrollStart - (e.clientX - startX)
113142}
114143
115144function onPointerUp(e: PointerEvent) {
116 isDragging = false
145 isPending = false
146 isDragging.value = false
117147 if (wrapRef.value) {
118148 wrapRef.value.releasePointerCapture(e.pointerId)
119 wrapRef.value.style.cursor = ''
120149 }
121150}
122151
@@ -132,6 +161,7 @@ onMounted(() => {
132161 <div
133162 ref="wrapRef"
134163 class="scrape-table-wrap"
164 :style="{ cursor: isDragging ? 'grabbing' : 'auto', userSelect: isDragging ? 'none' : 'auto' }"
135165 @pointerdown="onPointerDown"
136166 @pointermove="onPointerMove"
137167 @pointerup="onPointerUp"
@@ -182,8 +212,6 @@ onMounted(() => {
182212.scrape-table-wrap {
183213 overflow-x: auto;
184214 max-width: 100%;
185 cursor: grab;
186 user-select: none;
187215}
188216
189217.scroll-indicator {