~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.13.0 Latest 2 packages, 1 image

1
10

Going back to code search shows the files loaded before

Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:web/code-search-kept
web/src/lib/pages.svelte.ts+23−0
@@ -3,10 +3,14 @@
import { goto, preloadData } from '$app/navigation';
import { page } from '$app/state';
import { tick } from 'svelte';
/** Part of a list, and the cursor to the part after it, if any. */
export type Page<T> = { items: T[]; cursor?: string };
/** The pages added below a list's first, and where the page was scrolled to. */
export type Kept<T> = Page<T> & { y: number };
/** The pages of a list shown so far, and the way to the next. */
export type Paged<T> = {
readonly items: T[];
@@ -61,6 +65,25 @@ export class Pages<D, T> {
return `${page.url.pathname}?${q}`;
}
/** The pages added below the loaded one, to keep with the history entry. */
capture(): Kept<T> | null {
const added = this.#added;
return added ? { items: added.items, cursor: added.cursor, y: scrollY } : null;
}
/**
* The pages `capture` kept, added again below the page loaded: going
* back to a list shows all it showed before, at the place it was left.
* SvelteKit scrolls back before it restores, while the page is only as
* long as its first page, so it is scrolled again once they are drawn.
*/
async restore(kept: Kept<T> | null) {
if (!kept) return;
this.#more = { after: this.#first.items, items: kept.items, cursor: kept.cursor };
await tick();
scrollTo(scrollX, kept.y);
}
/** Adds the next page below the rest, or opens it, when it loads as something else. */
async next() {
const href = this.href;
web/src/routes/search/+page.svelte+8−1
@@ -7,7 +7,9 @@
import Count from '#lib/atoms/Count.svelte';
import Empty from '#lib/molecules/Empty.svelte';
import More from '#lib/atoms/More.svelte';
import { Pages } from '#lib/pages.svelte.ts';
import { Pages, type Kept } from '#lib/pages.svelte.ts';
import type { FileView } from '#lib/lexicons/dev/knotless/searchCode.ts';
import type { Snapshot } from './$types';
import { plural, repoHref } from '#lib/format.ts';
let { data } = $props();
const q = $derived(data.query);
@@ -64,6 +66,11 @@
: { items: [] },
(f) => `${f.repo.did}/${f.repo.name}/${f.path}`
);
// The files loaded below the first page, kept for going back to it.
export const snapshot: Snapshot<Kept<FileView> | null> = {
capture: () => files.capture(),
restore: (kept) => files.restore(kept)
};
// How deep the pages go, as searchCode stops them.
const DEEPEST = 200;
const narrowed = (name: string) =>