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(() => {
85// Drag to scroll + scroll indicator 85// Drag to scroll + scroll indicator
86const wrapRef = ref<HTMLElement | null>(null) 86const wrapRef = ref<HTMLElement | null>(null)
87const canScrollRight = ref(false) 87const canScrollRight = ref(false)
88let isDragging = false 88const isDragging = ref(false)
89let isPending = false
89let startX = 0 90let startX = 0
90let scrollStart = 0 91let scrollStart = 0
92let pendingPointerId = -1
91 93
92const SCROLL_END_PX = 2 94const SCROLL_END_PX = 2
95const DRAG_THRESHOLD_PX = 5
93 96
94function checkScroll() { 97function checkScroll() {
95 const el = wrapRef.value 98 const el = wrapRef.value
@@ -97,26 +100,52 @@ function checkScroll() {
97 canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - SCROLL_END_PX 100 canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - SCROLL_END_PX
98} 101}
99 102
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
100function onPointerDown(e: PointerEvent) { 112function onPointerDown(e: PointerEvent) {
113 if (e.button !== 0) return
101 const el = wrapRef.value 114 const el = wrapRef.value
102 if (!el) return 115 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
104 startX = e.clientX 119 startX = e.clientX
105 scrollStart = el.scrollLeft 120 scrollStart = el.scrollLeft
106 el.setPointerCapture(e.pointerId) 121 pendingPointerId = e.pointerId
107 el.style.cursor = 'grabbing'
108} 122}
109 123
110function onPointerMove(e: PointerEvent) { 124function onPointerMove(e: PointerEvent) {
111 if (!isDragging || !wrapRef.value) return 125 const el = wrapRef.value
112 wrapRef.value.scrollLeft = scrollStart - (e.clientX - startX) 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)
113} 142}
114 143
115function onPointerUp(e: PointerEvent) { 144function onPointerUp(e: PointerEvent) {
116 isDragging = false 145 isPending = false
146 isDragging.value = false
117 if (wrapRef.value) { 147 if (wrapRef.value) {
118 wrapRef.value.releasePointerCapture(e.pointerId) 148 wrapRef.value.releasePointerCapture(e.pointerId)
119 wrapRef.value.style.cursor = ''
120 } 149 }
121} 150}
122 151
@@ -132,6 +161,7 @@ onMounted(() => {
132 <div 161 <div
133 ref="wrapRef" 162 ref="wrapRef"
134 class="scrape-table-wrap" 163 class="scrape-table-wrap"
164 :style="{ cursor: isDragging ? 'grabbing' : 'auto', userSelect: isDragging ? 'none' : 'auto' }"
135 @pointerdown="onPointerDown" 165 @pointerdown="onPointerDown"
136 @pointermove="onPointerMove" 166 @pointermove="onPointerMove"
137 @pointerup="onPointerUp" 167 @pointerup="onPointerUp"
@@ -182,8 +212,6 @@ onMounted(() => {
182.scrape-table-wrap { 212.scrape-table-wrap {
183 overflow-x: auto; 213 overflow-x: auto;
184 max-width: 100%; 214 max-width: 100%;
185 cursor: grab;
186 user-select: none;
187} 215}
188 216
189.scroll-indicator { 217.scroll-indicator {