From ff1ea373c8eea1bf768b9bf66b654d5940338b44 Mon Sep 17 00:00:00 2001 From: Felix Kling Date: Fri, 19 Apr 2024 00:04:28 +0200 Subject: [PATCH] svelte: Remove full page scrolling of repo pages (#62024) This commit removes the full page scrolling behavior for repo root, directory and file pages. The implementation had several issues. In the new implementation the scroll container is CodeMirror itself. It provides the following behavior: - Show the top of the file when navigating to a new file. - Scroll the selected line into view when opening a URL containing a position. - Do not scroll when selecting a line (currently broken). - Restore previous scroll position when navigating backward or forward in the browser history. - Toggling the blame view maintains the current line view (well, almost but that's as best as we can do at the moment). Additional changes in this commit: - Removed logic to enable/disable full page scrolling. - Remove CSS for making elements `sticky`. - Update "scroll selected line into view" logic to prevent scrolling when restoring the previous scroll position. - Update `codemirror/view` to include a recent fix for a scroll related bug. --- .../src/lib/CodeMirrorBlob.svelte | 174 ++++++++++++------ .../web-sveltekit/src/lib/codemirror/utils.ts | 105 ++++++++--- .../src/lib/repo/FileHeader.svelte | 2 - client/web-sveltekit/src/lib/stores.ts | 2 - client/web-sveltekit/src/lib/web.ts | 1 + .../web-sveltekit/src/routes/+layout.svelte | 16 +- .../(validrev)/(code)/+layout.svelte | 45 +---- .../(code)/-/blob/[...path]/+page.svelte | 108 +++++++---- .../(code)/-/blob/[...path]/page.spec.ts | 136 +++++++++++++- .../(code)/-/tree/[...path]/+page.svelte | 3 +- .../src/repo/blob/codemirror/linenumbers.ts | 87 +++++---- package.json | 2 +- pnpm-lock.yaml | 46 ++--- 13 files changed, 491 insertions(+), 236 deletions(-) diff --git a/client/web-sveltekit/src/lib/CodeMirrorBlob.svelte b/client/web-sveltekit/src/lib/CodeMirrorBlob.svelte index 095a5e60baa..1fc7dcca3b7 100644 --- a/client/web-sveltekit/src/lib/CodeMirrorBlob.svelte +++ b/client/web-sveltekit/src/lib/CodeMirrorBlob.svelte @@ -28,8 +28,6 @@ languages: string[] } - const extensionsCompartment = new Compartment() - const defaultTheme = EditorView.theme({ '&': { height: '100%', @@ -42,6 +40,7 @@ lineHeight: '1rem', fontFamily: 'var(--code-font-family)', fontSize: 'var(--code-font-size)', + overflow: 'auto', }, '.cm-content': { padding: 0, @@ -106,20 +105,12 @@ defaultTheme, linkify, ] - - function configureSyntaxHighlighting(content: string, lsif: string): Extension { - return lsif ? syntaxHighlight.of({ content, lsif }) : [] - } - - function configureMiscSettings({ wrapLines }: { wrapLines: boolean }): Extension { - return [wrapLines ? EditorView.lineWrapping : []] - } {#if browser} @@ -273,9 +330,10 @@ diff --git a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/+layout.svelte b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/+layout.svelte index 10b7c48345a..03cb92719c9 100644 --- a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/+layout.svelte +++ b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/+layout.svelte @@ -1,7 +1,7 @@ -
+