Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor legacy line-number and scroll code #33094

Merged
merged 5 commits into from
Jan 4, 2025

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Jan 3, 2025

  1. remove jquery
  2. rewrite the "line number selection", fix various edge cases
  3. fix the scroll

Now 7 "import jquery" files left.

Some fixes could be backport to 1.23 (not blocking the release)

image

image

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 3, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 3, 2025
@wxiaoguang wxiaoguang force-pushed the refactor-line-scroll branch from c64d476 to 6bc2439 Compare January 3, 2025 15:48
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 3, 2025
web_src/js/features/repo-code.ts Show resolved Hide resolved
@@ -693,6 +693,7 @@ input:-webkit-autofill:active,

.ui.dropdown .menu > .header {
font-size: 0.8em;
text-transform: none; /* reset fomantic's "uppercase" */
Copy link
Member

Choose a reason for hiding this comment

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

do we really want this?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, we have fixed all "uppercase" headers in history, modern UI doesn't use uppercase.

This is the last one.

Copy link
Contributor Author

@wxiaoguang wxiaoguang Jan 4, 2025

Choose a reason for hiding this comment

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

ps: many languages do not have "uppercase".

Fine tuned the font size: 31e9deb

image

// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
if (window.history.scrollRestoration !== 'manual') window.history.scrollRestoration = 'manual';
// wait for a while because some elements (eg: image, editor, etc.) may change the viewport's height.
setTimeout(() => commentDiv.scrollIntoView({block: 'start'}), 100);
Copy link
Member

Choose a reason for hiding this comment

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

maybe center better?

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 have tested, "center" is not good enough. For example, when the comment is quite long.

}
};
onHashChange();
window.addEventListener('hashchange', onHashChange);
Copy link
Member

Choose a reason for hiding this comment

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

just to inform, history.pushState does not fire hashchange event, so not sure if this listener does something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the case when user manually change the URL, eg:

/file#L1 => /file#L1-L3

And that's the old logic, I think it is good to keep it

if (first) {
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
if (window.history.scrollRestoration !== 'manual') window.history.scrollRestoration = 'manual';
first.scrollIntoView({block: 'start'});
Copy link
Member

Choose a reason for hiding this comment

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

same here. maybe center better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to my test, I think "start" is better.

web_src/js/features/repo-code.ts Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 3, 2025
lafriks pushed a commit that referenced this pull request Jan 3, 2025
Partially backport #33094 

Fix the scroll bug in issue/pr view page.

Fix a JS error when line number exceeds the max
@wxiaoguang wxiaoguang force-pushed the refactor-line-scroll branch from 5f7018d to 31e9deb Compare January 4, 2025 02:31
@wxiaoguang wxiaoguang merged commit 2b064b8 into go-gitea:main Jan 4, 2025
26 checks passed
@GiteaBot GiteaBot added this to the 1.24.0 milestone Jan 4, 2025
@wxiaoguang wxiaoguang deleted the refactor-line-scroll branch January 4, 2025 02:56
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 6, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Fix dropdown menu header and mobile view (go-gitea#33108)
  workflow_dispatch use workflow from trigger branch (go-gitea#33098)
  [skip ci] Updated translations via Crowdin
  Trivial fixes (go-gitea#33103)
  Fix empty git repo handling logic (go-gitea#33101)
  Refactor legacy line-number and scroll code (go-gitea#33094)
  Use `Project-URL` metadata field to get a PyPI package's homepage URL (go-gitea#33089)
  Clean up legacy form CSS styles (go-gitea#33081)
  [skip ci] Updated translations via Crowdin
  add myself to maintainers (go-gitea#33088)
  Make Gitea always use its internal config, ignore `/etc/gitconfig` (go-gitea#33076)
  Fix "stop time tracking button" on navbar (go-gitea#33084)
  Fix bleve fuzziness search (go-gitea#33078)
  Try to fix ACME directory problem (go-gitea#33072)
  Refactor env var related code (go-gitea#33075)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants