Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

svelte: Remove full page scrolling of repo pages #62024

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

fkling
Copy link
Contributor

@fkling fkling commented Apr 18, 2024

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.

NOTE: Due to these changes we lost scroll restoration for repo root and directory pages. This will be fixed in a separate PR.

Test plan

pnpm test passes

Manual testing:

  • Open file page in new tab -> file is scrolled to the top

  • Open file page with selected line in new tab -> selected line is scrolled into view

  • Navigate to new file via file tree -> new file is scrolled to the top

  • Scroll file, navigate to new file and back -> scroll position is restored

  • Scroll file, navigate back, navigate forward -> scroll position is restored

  • Preview panel appears to be working (can scroll and navigate between matches)

  • Directory page is scrollable

  • Repo root page is scrollable

@fkling fkling added the team/code-search Issues owned by the code search team label Apr 18, 2024
@fkling fkling added this to the Web app rewrite/2 milestone Apr 18, 2024
@fkling fkling self-assigned this Apr 18, 2024
@cla-bot cla-bot bot added the cla-signed label Apr 18, 2024
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Apr 18, 2024

📖 Storybook live preview

Comment on lines +168 to +178
const extensionsCompartment = createCompartments({
selectableLineNumbers: null,
syntaxHighlighting: null,
lineWrapping: null,
temporaryTooltip,
codeIntelExtension: null,
staticExtensions,
staticHighlightExtension: null,
blameDataExtension: null,
blameColumnExtension: null,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had introduced this helper function when refactoring the search input and it seems to make sense to use it here too to get more fine grained control over updating individual extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file make it possible to set the initial selected line without scrolling it into view. It was necessary to do this otherwise the selected line would be scrolled into view after restoring the scroll position (most likely because requestAnimationFrame schedules the update to be run after the scroll restoration).

@camdencheek
Copy link
Member

camdencheek commented Apr 18, 2024

I noticed horizontal scroll for blob view scrolls the whole codemirror blob. I think this is unrelated to this PR (also see it on s2), but wanted to point it out in case it was an easy fix with the new changes

https://share.cleanshot.com/fp9KhR0T

Copy link
Member

@camdencheek camdencheek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks Felix!

const lineWrap = writable<boolean>(false)
let cmblob: CodeMirrorBlob | null = null
let blob: Awaited<PageData['blob']> | null = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about Awaited

@fkling
Copy link
Contributor Author

fkling commented Apr 18, 2024

I noticed horizontal scroll for blob view scrolls the whole codemirror blob. I think this is unrelated to this PR (also see it on s2), but wanted to point it out in case it was an easy fix with the new changes

Looks like that only happens when the blame view is enabled. I think we "unfix" the line number gutter when it's enabled, so it scrolls, but I don't know anymore why we do this.

Base automatically changed from fkling/sk/fix-preview-build to main April 18, 2024 20:45
fkling added 3 commits April 18, 2024 22:48
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.

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.
@fkling fkling force-pushed the fkling/sk/remove-full-page-scrolling branch from 5cb4a4e to 8c08d08 Compare April 18, 2024 20:51
@fkling fkling merged commit ff1ea37 into main Apr 18, 2024
@fkling fkling deleted the fkling/sk/remove-full-page-scrolling branch April 18, 2024 22:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed team/code-search Issues owned by the code search team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants