Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.
TypeScript clipboardclipboard-managerdesktop-appdrag-and-dropelectronopen-sourceproductivityproductivity-toolwindows
feat(list): reopening at the top offers a way back to where you were
Deepender2554c5882a557a
diff --git a/src/components/ItemList.tsx b/src/components/ItemList.tsxindex dcbc409..8442adc 100644--- a/src/components/ItemList.tsx+++ b/src/components/ItemList.tsx@@ -19,6 +19,22 @@ import { playExpandSound, playButtonClickSound } from '../lib/soundEffects'import { useTranslation } from '../i18n'+/**+ * Reopening the shelf after this long (or after something new was copied)+ * starts it at the top, newest first; the back button offers the way back.+ */+const REOPEN_AT_TOP_AFTER_MS = 60_000+/** How long the back button offers the way back (paused while the pointer is on it). */+const BACK_BUTTON_MS = 6000++/** Where the list was when the shelf closed: the card at its leading edge. */+interface BackSpot {+ filter: string+ pos: number+ id?: string+ offset: number+}+export function ItemList() {const { t } = useTranslation()@@ -39,6 +55,10 @@ export function ItemList() {const prevFilterRef = useRef(typeFilter)const [showScrollTop, setShowScrollTop] = useState(false)+ // The way back to where the list was, offered for a moment after a reopen+ // started it at the top (null when there is nothing to go back to).+ const [backSpot, setBackSpot] = useState<BackSpot | null>(null)+ const closedSpot = useRef<BackSpot | null>(null)const [collapsedMap, setCollapsedMap] = useState<Record<string, boolean>>(() => {try {const saved = localStorage.getItem('edge_drop_pinned_collapsed_map')@@ -94,6 +114,44 @@ export function ItemList() {}}, [])+ // The card at the list's leading edge and how far into the list it sits, so+ // the way back lands on the same card even after new copies pushed it down.+ // Nothing to go back to when the list is within half a view of the top.+ const captureSpot = (): BackSpot | null => {+ const el = listRef.current+ if (!el) return null+ const pos = isHorizontal ? el.scrollLeft : el.scrollTop+ if (pos < (isHorizontal ? el.clientWidth : el.clientHeight) / 2) return null+ const box = el.getBoundingClientRect()+ const hit = isHorizontal+ ? document.elementFromPoint(box.left + 24, box.top + box.height / 2)+ : document.elementFromPoint(box.left + box.width / 2, box.top + 24)+ const card = hit?.closest('.list .item-main') as HTMLElement | null+ const at = card?.getBoundingClientRect()+ return {+ filter: useStore.getState().typeFilter || 'all',+ pos,+ id: card?.dataset.id,+ offset: at ? (isHorizontal ? at.left - box.left : at.top - box.top) : 0+ }+ }++ const goBack = () => {+ const spot = backSpot+ const el = listRef.current+ setBackSpot(null)+ if (!spot || !el) return+ playButtonClickSound()+ let target = spot.pos+ const card = spot.id ? (el.querySelector(`.item-main[data-id="${CSS.escape(spot.id)}"]`) as HTMLElement | null) : null+ if (card && !card.closest('.pinned-accordion:not(.is-expanded)')) {+ const box = el.getBoundingClientRect()+ const at = card.getBoundingClientRect()+ target = (isHorizontal ? el.scrollLeft + at.left - box.left : el.scrollTop + at.top - box.top) - spot.offset+ }+ el.scrollTo({ [isHorizontal ? 'left' : 'top']: Math.max(0, target), behavior: reduceMotion ? 'auto' : 'smooth' })+ }+const lastClosedAt = useRef<number>(Date.now())const lastClosedTopId = useRef<string | undefined>(topRecentId)const lastClosedTopTime = useRef<number | undefined>(topRecentTime)@@ -111,21 +169,29 @@ export function ItemList() {lastClosedTopId.current = prevTopRecentId.currentlastClosedTopTime.current = prevTopRecentTime.currentlastClosedTopPinnedTime.current = prevTopPinnedTime.current+ // and where the list is (the shape is still open here, so the card+ // at the list's leading edge can be found by hit testing)+ closedSpot.current = captureSpot()+ setBackSpot(null)} else if (isNowOpen && !lastOpen) {- // Panel just opened: check if closed >= 60s OR if a new copy happened while closed+ // Panel just opened: check if closed long enough OR if a new copy happened while closedconst timeSinceClosed = Date.now() - lastClosedAt.currentconst hasNewCopyWhileClosed =prevTopRecentId.current !== lastClosedTopId.current ||prevTopRecentTime.current !== lastClosedTopTime.current ||prevTopPinnedTime.current !== lastClosedTopPinnedTime.current- if (timeSinceClosed >= 60000 || hasNewCopyWhileClosed) {+ if (timeSinceClosed >= REOPEN_AT_TOP_AFTER_MS || hasNewCopyWhileClosed) {filterScrollMap.current = {}if (listRef.current) {if (isHorizontal) listRef.current.scrollLeft = 0else listRef.current.scrollTop = 0}+ // Never silently: offer the way back for a moment.+ const spot = closedSpot.current+ if (spot && spot.filter === (state.typeFilter || 'all')) setBackSpot(spot)}+ closedSpot.current = null}lastOpen = isNowOpen}@@ -159,6 +225,7 @@ export function ItemList() {if (!el) returnif (prevFilterRef.current !== typeFilter) {+ setBackSpot(null)// Save outgoing filter's scroll position before applying new filter's positionfilterScrollMap.current[prevFilterRef.current] = {top: el.scrollTop,@@ -181,6 +248,7 @@ export function ItemList() {useLayoutEffect(() => {if (prevQueryRef.current !== query) {prevQueryRef.current = query+ setBackSpot(null)if (listRef.current) {if (isHorizontal) listRef.current.scrollLeft = 0else listRef.current.scrollTop = 0@@ -193,6 +261,7 @@ export function ItemList() {useLayoutEffect(() => {if (prevStickPos.current !== stickPosition) {prevStickPos.current = stickPosition+ setBackSpot(null)filterScrollMap.current = {}if (listRef.current) {listRef.current.scrollTop = 0@@ -216,6 +285,8 @@ export function ItemList() {const scrollPos = isHorizontal ? el.scrollLeft : el.scrollTopconst next = scrollPos > 50setShowScrollTop((prev) => (prev === next ? prev : next))+ // Scrolling on your own: the offer is no longer needed.+ if (next) setBackSpot((prev) => (prev ? null : prev))}const scrollToTop = () => {@@ -475,6 +546,77 @@ export function ItemList() {</motion.button>)}</AnimatePresence>++ <AnimatePresence>+ {backSpot && (+ <BackButton+ key="back-button"+ horizontal={isHorizontal}+ reduceMotion={reduceMotion}+ label={t('item.backToSpot')}+ onBack={goBack}+ onDone={() => setBackSpot(null)}+ />+ )}+ </AnimatePresence></div>)}++/**+ * "Back to where you were": the scroll-to-top button's twin, in its corner+ * (free while the list is at the top), pointing the other way. A white ring+ * around its edge shrinks for as long as it is offered; the pointer on it+ * holds the time.+ */+function BackButton({ horizontal, reduceMotion, label, onBack, onDone }: {+ horizontal: boolean+ reduceMotion: boolean+ label: string+ onBack: () => void+ onDone: () => void+}) {+ const [held, setHeld] = useState(false)+ const timeLeft = useRef(BACK_BUTTON_MS)+ const done = useRef(onDone)+ done.current = onDone+ useEffect(() => {+ if (held) return+ const startedAt = performance.now()+ const timer = window.setTimeout(() => done.current(), timeLeft.current)+ return () => {+ window.clearTimeout(timer)+ timeLeft.current -= performance.now() - startedAt+ }+ }, [held])++ return (+ <motion.button+ type="button"+ className={`scroll-top-btn back-btn${horizontal ? ' horizontal' : ''}${held ? ' is-held' : ''}`}+ style={{ '--back-btn-ms': `${BACK_BUTTON_MS}ms` } as React.CSSProperties}+ initial={{ opacity: 0, scale: 0.85 }}+ animate={{ opacity: 1, scale: 1 }}+ exit={{ opacity: 0, scale: 0.85 }}+ transition={{ duration: reduceMotion ? 0.01 : 0.14, ease: 'easeOut' }}+ onClick={onBack}+ onPointerEnter={() => setHeld(true)}+ onPointerLeave={() => setHeld(false)}+ title={label}+ aria-label={label}+ >+ {horizontal ? (+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">+ <polyline points="9 18 15 12 9 6"></polyline>+ </svg>+ ) : (+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">+ <polyline points="6 9 12 15 18 9"></polyline>+ </svg>+ )}+ <svg className="back-btn-ring" viewBox="0 0 44 44" aria-hidden="true">+ <circle cx="22" cy="22" r="20.5" pathLength="100" />+ </svg>+ </motion.button>+ )+}diff --git a/src/i18n/translations.ts b/src/i18n/translations.tsindex b5a3a64..0b5edc1 100644--- a/src/i18n/translations.ts+++ b/src/i18n/translations.ts@@ -178,6 +178,7 @@ export interface TranslationKeys {moreFiles: stringsingleFile: stringscrollToTop: string+ backToSpot: stringclearLast1h?: stringclearLast6h?: stringclearLast24h?: string@@ -757,7 +758,8 @@ export const en: TranslationKeys = {"moreImages": "+{count} more images","moreFiles": "+{count} more files","singleFile": "1 file",- "scrollToTop": "Scroll to top"+ "scrollToTop": "Scroll to top",+ "backToSpot": "Back to where you were"},"menu": {"title": "Item actions",@@ -1154,6 +1156,7 @@ export const es: TranslationKeys = {"moreFiles": "+{count} archivos más","singleFile": "1 archivo","scrollToTop": "Volver arriba",+ "backToSpot": "Volver a donde estabas","clearLast1h": "Borrar la última hora","clearLast6h": "Borrar las últimas 6 horas","clearLast24h": "Borrar las últimas 24 horas",@@ -1554,6 +1557,7 @@ export const fr: TranslationKeys = {"moreFiles": "+{count} fichiers de plus","singleFile": "1 fichier","scrollToTop": "Remonter en haut",+ "backToSpot": "Revenir où vous étiez","clearLast1h": "Effacer la dernière heure","clearLast6h": "Effacer les 6 dernières heures","clearLast24h": "Effacer les 24 dernières heures",@@ -1954,6 +1958,7 @@ export const de: TranslationKeys = {"moreFiles": "+{count} weitere Dateien","singleFile": "1 Datei","scrollToTop": "Nach oben scrollen",+ "backToSpot": "Zurück zur letzten Stelle","clearLast1h": "Letzte Stunde löschen","clearLast6h": "Letzte 6 Stunden löschen","clearLast24h": "Letzte 24 Stunden löschen",@@ -2354,6 +2359,7 @@ export const it: TranslationKeys = {"moreFiles": "+{count} altri file","singleFile": "1 file","scrollToTop": "Torna in cima",+ "backToSpot": "Torna dove eri","clearLast1h": "Cancella ultima ora","clearLast6h": "Cancella ultime 6 ore","clearLast24h": "Cancella ultime 24 ore",@@ -2754,6 +2760,7 @@ export const pt: TranslationKeys = {"moreFiles": "+{count} arquivos a mais","singleFile": "1 arquivo","scrollToTop": "Voltar ao topo",+ "backToSpot": "Voltar para onde estava","clearLast1h": "Limpar última hora","clearLast6h": "Limpar últimas 6 horas","clearLast24h": "Limpar últimas 24 horas",@@ -3154,6 +3161,7 @@ export const ru: TranslationKeys = {"moreFiles": "+{count} ещё файлов","singleFile": "1 файл","scrollToTop": "Прокрутить наверх",+ "backToSpot": "Вернуться к прежнему месту","clearLast1h": "Очистить за последний час","clearLast6h": "Очистить за последние 6 часов","clearLast24h": "Очистить за последние 24 часа",@@ -3554,6 +3562,7 @@ export const ja: TranslationKeys = {"moreFiles": "+{count} 個のファイル","singleFile": "1 個のファイル","scrollToTop": "先頭へスクロール",+ "backToSpot": "前の位置に戻る","clearLast1h": "過去1時間を消去","clearLast6h": "過去6時間を消去","clearLast24h": "過去24時間を消去",@@ -3954,6 +3963,7 @@ export const ko: TranslationKeys = {"moreFiles": "+{count}개 파일 더","singleFile": "1개 파일","scrollToTop": "맨 위로 스크롤",+ "backToSpot": "보던 위치로 돌아가기","clearLast1h": "최근 1시간 지우기","clearLast6h": "최근 6시간 지우기","clearLast24h": "최근 24시간 지우기",@@ -4354,6 +4364,7 @@ export const zhCN: TranslationKeys = {"moreFiles": "+{count} 个更多文件","singleFile": "1 个文件","scrollToTop": "滚动到顶部",+ "backToSpot": "回到之前的位置","clearLast1h": "清除最近 1 小时","clearLast6h": "清除最近 6 小时","clearLast24h": "清除最近 24 小时",@@ -4754,6 +4765,7 @@ export const zhTW: TranslationKeys = {"moreFiles": "+{count} 個更多檔案","singleFile": "1 個檔案","scrollToTop": "捲動到頂部",+ "backToSpot": "回到之前的位置","clearLast1h": "清除最近 1 小時","clearLast6h": "清除最近 6 小時","clearLast24h": "清除最近 24 小時",@@ -5154,6 +5166,7 @@ export const hi: TranslationKeys = {"moreFiles": "+{count} और फ़ाइलें","singleFile": "1 फ़ाइल","scrollToTop": "शीर्ष पर स्क्रॉल करें",+ "backToSpot": "जहाँ थे वहीं लौटें","clearLast1h": "पिछले 1 घंटे को साफ़ करें","clearLast6h": "पिछले 6 घंटे साफ़ करें","clearLast24h": "पिछले 24 घंटे साफ़ करें",@@ -5554,6 +5567,7 @@ export const ar: TranslationKeys = {"moreFiles": "+{count} ملفات أخرى","singleFile": "ملف واحد","scrollToTop": "التمرير للأعلى",+ "backToSpot": "العودة إلى حيث كنت","clearLast1h": "مسح الساعة الأخيرة","clearLast6h": "مسح آخر 6 ساعات","clearLast24h": "مسح آخر 24 ساعة",@@ -5954,6 +5968,7 @@ export const fa: TranslationKeys = {"moreFiles": "+{count} فایل دیگه","singleFile": "۱ فایل","scrollToTop": "برو بالا",+ "backToSpot": "بازگشت به جای قبلی","clearLast1h": "پاک کردن یک ساعت گذشته","clearLast6h": "پاک کردن ۶ ساعت گذشته","clearLast24h": "پاک کردن ۲۴ ساعت گذشته",@@ -6354,6 +6369,7 @@ export const bn: TranslationKeys = {"moreFiles": "+{count} টি অতিরিক্ত ফাইল","singleFile": "১টি ফাইল","scrollToTop": "শীর্ষে স্ক্রোল করুন",+ "backToSpot": "আগের জায়গায় ফিরুন","clearLast1h": "গত ১ ঘণ্টা মুছুন","clearLast6h": "গত ৬ ঘণ্টা মুছুন","clearLast24h": "গত ২৪ ঘণ্টা মুছুন",@@ -6754,6 +6770,7 @@ export const tr: TranslationKeys = {"moreFiles": "+{count} dosya daha","singleFile": "1 dosya","scrollToTop": "Başa kaydır",+ "backToSpot": "Kaldığın yere dön","clearLast1h": "Son 1 saati temizle","clearLast6h": "Son 6 saati temizle","clearLast24h": "Son 24 saati temizle",@@ -7154,6 +7171,7 @@ export const vi: TranslationKeys = {"moreFiles": "+{count} tệp nữa","singleFile": "1 tệp","scrollToTop": "Cuộn lên đầu",+ "backToSpot": "Quay lại chỗ đang xem","clearLast1h": "Xóa 1 giờ qua","clearLast6h": "Xóa 6 giờ qua","clearLast24h": "Xóa 24 giờ qua",@@ -7554,6 +7572,7 @@ export const pl: TranslationKeys = {"moreFiles": "+{count} więcej plików","singleFile": "1 plik","scrollToTop": "Przewiń na górę",+ "backToSpot": "Wróć do poprzedniego miejsca","clearLast1h": "Wyczyść ostatnią godzinę","clearLast6h": "Wyczyść ostatnie 6 godzin","clearLast24h": "Wyczyść ostatnie 24 godziny",@@ -7954,6 +7973,7 @@ export const nl: TranslationKeys = {"moreFiles": "+{count} bestanden meer","singleFile": "1 bestand","scrollToTop": "Naar boven scrollen",+ "backToSpot": "Terug naar waar je was","clearLast1h": "Laatste uur wissen","clearLast6h": "Laatste 6 uur wissen","clearLast24h": "Laatste 24 uur wissen",@@ -8354,6 +8374,7 @@ export const sv: TranslationKeys = {"moreFiles": "+{count} fler filer","singleFile": "1 fil","scrollToTop": "Scrolla till toppen",+ "backToSpot": "Tillbaka dit du var","clearLast1h": "Rensa senaste timmen","clearLast6h": "Rensa senaste 6 timmarna","clearLast24h": "Rensa senaste 24 timmarna",@@ -8754,6 +8775,7 @@ export const id: TranslationKeys = {"moreFiles": "+{count} berkas lagi","singleFile": "1 berkas","scrollToTop": "Gulir ke atas",+ "backToSpot": "Kembali ke posisi sebelumnya","clearLast1h": "Hapus 1 jam terakhir","clearLast6h": "Hapus 6 jam terakhir","clearLast24h": "Hapus 24 jam terakhir",@@ -9154,6 +9176,7 @@ export const uk: TranslationKeys = {"moreFiles": "+{count} більше файлів","singleFile": "1 файл","scrollToTop": "Прокрутити вгору",+ "backToSpot": "Повернутися до попереднього місця","clearLast1h": "Очистити за останню годину","clearLast6h": "Очистити за останні 6 годин","clearLast24h": "Очистити за останні 24 години",@@ -9554,6 +9577,7 @@ export const el: TranslationKeys = {"moreFiles": "+{count} περισσότερα αρχεία","singleFile": "1 αρχείο","scrollToTop": "Κύλιση στην κορυφή",+ "backToSpot": "Επιστροφή εκεί που ήσουν","clearLast1h": "Εκκαθάριση τελευταίας ώρας","clearLast6h": "Εκκαθάριση τελευταίων 6 ωρών","clearLast24h": "Εκκαθάριση τελευταίων 24 ωρών",@@ -9954,6 +9978,7 @@ export const cs: TranslationKeys = {"moreFiles": "+{count} dalších souborů","singleFile": "1 soubor","scrollToTop": "Přejít nahoru",+ "backToSpot": "Zpět tam, kde jste byli","clearLast1h": "Vymazat poslední hodinu","clearLast6h": "Vymazat posledních 6 hodin","clearLast24h": "Vymazat posledních 24 hodin",@@ -10354,6 +10379,7 @@ export const ro: TranslationKeys = {"moreFiles": "+{count} fișiere mai mult","singleFile": "1 fișier","scrollToTop": "Derulează sus",+ "backToSpot": "Înapoi unde erai","clearLast1h": "Șterge ultima oră","clearLast6h": "Șterge ultimele 6 ore","clearLast24h": "Șterge ultimele 24 de ore",@@ -10754,6 +10780,7 @@ export const hu: TranslationKeys = {"moreFiles": "+{count} további fájl","singleFile": "1 fájl","scrollToTop": "Görgetés a tetejére",+ "backToSpot": "Vissza oda, ahol jártál","clearLast1h": "Elmúlt óra törlése","clearLast6h": "Elmúlt 6 óra törlése","clearLast24h": "Elmúlt 24 óra törlése",@@ -11154,6 +11181,7 @@ export const da: TranslationKeys = {"moreFiles": "+{count} flere filer","singleFile": "1 fil","scrollToTop": "Rul til toppen",+ "backToSpot": "Tilbage til hvor du var","clearLast1h": "Ryd sidste time","clearLast6h": "Ryd sidste 6 timer","clearLast24h": "Ryd sidste 24 timer",@@ -11554,6 +11582,7 @@ export const fi: TranslationKeys = {"moreFiles": "+{count} tiedostoa lisää","singleFile": "1 tiedosto","scrollToTop": "Vieritä ylös",+ "backToSpot": "Takaisin edelliseen kohtaan","clearLast1h": "Tyhjennä viimeinen tunti","clearLast6h": "Tyhjennä viimeiset 6 tuntia","clearLast24h": "Tyhjennä viimeiset 24 tuntia",@@ -11954,6 +11983,7 @@ export const th: TranslationKeys = {"moreFiles": "+{count} ไฟล์เพิ่มเติม","singleFile": "1 ไฟล์","scrollToTop": "เลื่อนไปที่ด้านบน",+ "backToSpot": "กลับไปยังตำแหน่งเดิม","clearLast1h": "ล้างข้อมูล 1 ชั่วโมงล่าสุด","clearLast6h": "ล้างข้อมูล 6 ชั่วโมงล่าสุด","clearLast24h": "ล้างข้อมูล 24 ชั่วโมงล่าสุด",@@ -12354,6 +12384,7 @@ export const he: TranslationKeys = {"moreFiles": "+{count} קבצים נוספים","singleFile": "קובץ 1","scrollToTop": "גלול לראש",+ "backToSpot": "חזרה למקום שבו היית","clearLast1h": "נקה את השעה האחרונה","clearLast6h": "נקה את 6 השעות האחרונות","clearLast24h": "נקה את 24 השעות האחרונות",@@ -12754,6 +12785,7 @@ export const no: TranslationKeys = {"moreFiles": "+{count} flere filer","singleFile": "1 fil","scrollToTop": "Rull til toppen",+ "backToSpot": "Tilbake dit du var","clearLast1h": "Tøm siste time","clearLast6h": "Tøm siste 6 timer","clearLast24h": "Tøm siste 24 timer",diff --git a/src/styles/item.css b/src/styles/item.cssindex f22518a..a1d2575 100644--- a/src/styles/item.css+++ b/src/styles/item.css@@ -272,6 +272,43 @@transform: scale(0.96);}+/* "Back to where you were": the scroll-to-top button itself (same class, same+ corner, which is free while the list is at the top), pointing the other way.+ A white ring around its edge shrinks while it is offered and holds while+ the pointer is on it. */+.back-btn-ring {+ position: absolute;+ inset: 0;+ width: 100%;+ height: 100%;+ transform: rotate(-90deg);+ pointer-events: none;+}++.back-btn-ring circle {+ fill: none;+ stroke: rgba(255, 255, 255, 0.9);+ stroke-width: 2px;+ stroke-linecap: round;+ stroke-dasharray: 100;+ stroke-dashoffset: 0;+ animation: back-btn-ring var(--back-btn-ms, 6000ms) linear forwards;+}++.back-btn.is-held .back-btn-ring circle {+ animation-play-state: paused;+}++/* Reduced motion shortens every animation to nothing: keep the button, drop the ring. */+:root[data-motion='reduce'] .back-btn-ring {+ display: none;+}++@keyframes back-btn-ring {+ from { stroke-dashoffset: 0; }+ to { stroke-dashoffset: 100; }+}+.bundle-stack {display: flex;align-items: center;diff --git a/tests/backPill.test.ts b/tests/backPill.test.tsnew file mode 100644index 0000000..05e3afb--- /dev/null+++ b/tests/backPill.test.ts@@ -0,0 +1,59 @@+import { describe, expect, it } from 'vitest'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { TRANSLATIONS } from '../src/i18n/translations'++// Reopening the shelf after a while (or after a new copy) starts the list at+// the top. It used to do that silently; now a round button offers the way back.++const read = (p: string) => readFileSync(join(process.cwd(), p), 'utf8').replace(/\r\n/g, '\n')+const list = read('src/components/ItemList.tsx')+const css = read('src/styles/item.css')++describe('reopen at the top, never silently', () => {+ it('starts at the top after 1 minute closed or a new copy, and then offers the way back', () => {+ expect(list).toContain('const REOPEN_AT_TOP_AFTER_MS = 60_000')+ expect(list).toMatch(/if \(timeSinceClosed >= REOPEN_AT_TOP_AFTER_MS \|\| hasNewCopyWhileClosed\) \{[\s\S]{0,400}if \(spot && spot\.filter === \(state\.typeFilter \|\| 'all'\)\) setBackSpot\(spot\)/)+ })++ it('remembers the card at the leading edge when the shelf closes, so going back lands on it even after new copies', () => {+ expect(list).toMatch(/if \(!isNowOpen && lastOpen\) \{[\s\S]{0,500}closedSpot\.current = captureSpot\(\)/)+ expect(list).toContain("const card = hit?.closest('.list .item-main') as HTMLElement | null")+ expect(list).toMatch(/target = \(isHorizontal \? el\.scrollLeft \+ at\.left - box\.left : el\.scrollTop \+ at\.top - box\.top\) - spot\.offset/)+ // nothing to go back to within half a view of the top+ expect(list).toContain('if (pos < (isHorizontal ? el.clientWidth : el.clientHeight) / 2) return null')+ })++ it('is offered for 6 seconds, held while the pointer is on it', () => {+ expect(list).toContain('const BACK_BUTTON_MS = 6000')+ expect(list).toMatch(/onPointerEnter=\{\(\) => setHeld\(true\)\}\s+onPointerLeave=\{\(\) => setHeld\(false\)\}/)+ expect(list).toMatch(/if \(held\) return\s+const startedAt = performance\.now\(\)\s+const timer = window\.setTimeout\(\(\) => done\.current\(\), timeLeft\.current\)/)+ expect(css).toMatch(/\.back-btn\.is-held \.back-btn-ring circle \{\s+animation-play-state: paused;/)+ })++ it('goes away as soon as it is not needed: own scroll, filter, search, dock change, shelf closing', () => {+ expect(list).toMatch(/if \(next\) setBackSpot\(\(prev\) => \(prev \? null : prev\)\)/)+ expect(list).toMatch(/if \(prevFilterRef\.current !== typeFilter\) \{\s+setBackSpot\(null\)/)+ expect(list).toMatch(/prevQueryRef\.current = query\s+setBackSpot\(null\)/)+ expect(list).toMatch(/prevStickPos\.current = stickPosition\s+setBackSpot\(null\)/)+ expect(list).toMatch(/closedSpot\.current = captureSpot\(\)\s+setBackSpot\(null\)/)+ })++ it('is the scroll-to-top button itself, no text, with a white ring around its edge that shrinks for the 6 seconds', () => {+ expect(list).toMatch(/className=\{`scroll-top-btn back-btn\$\{horizontal \? ' horizontal' : ''\}/)+ const button = list.slice(list.indexOf('function BackButton'))+ expect(button).not.toMatch(/<span/)+ expect(button).toMatch(/title=\{label\}\s+aria-label=\{label\}/)+ expect(button).toContain('<circle cx="22" cy="22" r="20.5" pathLength="100" />')+ expect(css).toMatch(/\.back-btn-ring circle \{[^}]*stroke: rgba\(255, 255, 255, 0\.9\);[^}]*stroke-dasharray: 100;[^}]*animation: back-btn-ring var\(--back-btn-ms, 6000ms\) linear forwards;/)+ expect(css).toMatch(/@keyframes back-btn-ring \{\s+from \{ stroke-dashoffset: 0; \}\s+to \{ stroke-dashoffset: 100; \}/)+ expect(css).toMatch(/:root\[data-motion='reduce'\] \.back-btn-ring \{\s+display: none;/)+ })++ it('has its text in every language', () => {+ const langs = Object.keys(TRANSLATIONS)+ expect(langs.length).toBe(31)+ for (const lang of langs) expect(TRANSLATIONS[lang].item.backToSpot, lang).toMatch(/\S/)+ expect(TRANSLATIONS.en.item.backToSpot).toBe('Back to where you were')+ })+})