Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add pull request files line selections#36014

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
lunny wants to merge20 commits intogo-gitea:main
base:main
Choose a base branch
Loading
fromlunny:lunny/add_pr_files_selection

Conversation

@lunny
Copy link
Member

@lunnylunny commentedNov 24, 2025
edited
Loading

This PR allows select multiple lines on the pull request files view page.

image

lafriks, splitt3r, anbraten, and didim99 reacted with heart emoji
@lunnylunny added this to the1.26.0 milestoneNov 24, 2025
@lunnylunny added type/enhancementAn improvement of existing functionality topic/uiChange the appearance of the Gitea UI labelsNov 24, 2025
@GiteaBotGiteaBot added the lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelNov 24, 2025
@github-actionsgithub-actionsbot added modifies/templatesThis PR modifies the template files modifies/frontend labelsNov 24, 2025
@lunnylunny marked this pull request as draftNovember 24, 2025 01:40
@lunnylunny marked this pull request as ready for reviewNovember 24, 2025 18:41
@GiteaBotGiteaBot added lgtm/need 1This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. labelsNov 25, 2025
@GiteaBotGiteaBot added lgtm/doneThis PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1This PR needs approval from one additional maintainer to be merged. labelsNov 25, 2025
{{else}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $linectx.Locale}}
<tdclass="lines-num lines-num-old"data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><spanrel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
<tdclass="lines-num lines-num-old"data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><spanrel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"{{if $line.LeftIdx}}id="diff-{{$.FileNameHash}}L{{$line.LeftIdx}}"{{end}}></span></td>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why duplicaterel= andid=?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

{{else}}
{{$inlineDiff := $.section.GetComputedInlineDiffFor $linectx.Locale}}
<tdclass="lines-num lines-num-old"data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><spanrel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
<tdclass="lines-num lines-num-old"data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><spanrel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"{{if $line.LeftIdx}}id="diff-{{$.FileNameHash}}L{{$line.LeftIdx}}"{{end}}></span></td>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have a clear defination likediff-{hash}-{L|R}xxx?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Comment on lines 16 to 22
functionchangeHash(hash:string){
if(window.history.pushState){
window.history.pushState(null,null,hash);
}else{
window.location.hash=hash;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this?

Copy link
Member

Choose a reason for hiding this comment

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

If it stays, it should be moved toweb_src/js/utils/dom.ts as a general DOM utility.

But I think it's pointless to test for existancewindow.history.pushState, every browser released in the last 15 years should have that function, so we can just assume it's there, and in which case this function makes no sense and it should just usewindow.history.pushState directly.

Oh and please pass'' as second argument to it, typescript wants it that way.

Copy link
Member

Choose a reason for hiding this comment

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

Oh and likely this should usewindow.history.replaceState (see other comment below).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

}

exportfunctionparseDiffHashRange(hashValue:string):DiffSelectionRange|null{
if(!hashValue.startsWith('diff-'))returnnull;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not the first time see the same logicstartsWith('diff-' ....

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

}
}

if(!applyDiffLineSelection(container,range,{updateHash:false}))returnfalse;
Copy link
Contributor

Choose a reason for hiding this comment

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

updateHash option is an over-design.

You can simply:

if (!applyDiffLineSelection(container, range)) return false;updateHash(.....);

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Comment on lines 146 to 148
// Scroll to the first selected line (scroll to the tr element, not the span)
// The span is an inline element inside td, we need to scroll to the tr for better visibility
awaitsleep(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

It can't be right

Copy link
Member

@silverwindsilverwindNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Maybe it needs asleep(0) orrequestAnimationFrame? Both should flush the JS event loop of pending tasks with the latter being faster.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@wxiaoguangwxiaoguang marked this pull request as draftNovember 25, 2025 23:33
return{anchor, fragment, side, line};
}

functionapplyDiffLineSelection(container:HTMLElement,range:DiffSelectionRange,options?:{updateHash?:boolean}):boolean{
Copy link
Contributor

Choose a reason for hiding this comment

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

All the complex logic needs tests if it is testable in frontend unit test.

Copy link
Member

Choose a reason for hiding this comment

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

Basic DOM interactions should be testable, thought I'm not sure if it's really worth it for this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can fully understand the logic and confirm its right, then not worth.

Copy link
Member

@silverwindsilverwindNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Replicating the DOM structure in a unit test will be hard. Ideally we should have e2e tests for this kind of stuff, but we don't (yet). If possible, extract testable functions here which ideally have no DOM interaction.

Copy link
Contributor

@wxiaoguangwxiaoguangNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Purely logic code:

Detailsimage

Copy link
Contributor

@wxiaoguangwxiaoguangNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

And DOM operations without layout & backend:

Detailsimage

Copy link
Member

Choose a reason for hiding this comment

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

Yeah such non-DOM logic is easily testable and should be tested.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

unit test added at4f65ae3

// Expand the file using the setFileFolding utility
setFileFolding(container,foldBtn,false);
// Wait a bit for the expansion animation
awaitsleep(100);
Copy link
Member

@silverwindsilverwindNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Can usehttps://developer.mozilla.org/en-US/docs/Web/API/Element/transitionend_event to detect when a transition has finished but it may be better to make setFileFolding return a Promise that resolves when the transition has ended.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

awaitsleep(10);
consttargetTr=targetSpan.closest('tr');
if(targetTr){
targetTr.scrollIntoView({behavior:'smooth',block:'center'});
Copy link
Member

Choose a reason for hiding this comment

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

I personally hate smooth scrolling, maybe scroll instantly?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

window.history.pushState(null,null,window.location.pathname+window.location.search);
}else{
window.location.hash='';
}
Copy link
Member

@silverwindsilverwindNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Maybe you actually want to usewindow.history.replaceState? I hate sites that push useless history entries because it pollutes the "back" stack, making the user hit the back button more than is necessary.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@lunnylunny marked this pull request as ready for reviewDecember 14, 2025 01:39
returnmax;
}

functionwaitForTransitionEnd(element:Element):Promise<void>{
Copy link
Contributor

Choose a reason for hiding this comment

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

It is 100% garbage function .....

// avoid reentrance when we are changing the hash to scroll and trigger ":target" selection
constattrAutoScrollRunning='data-auto-scroll-running';
if(document.body.hasAttribute(attrAutoScrollRunning))return;
if(document.body.hasAttribute(diffAutoScrollAttr))return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it is calleddiffAutoScrollAttr? See the comment, theattrAutoScrollRunning was designed for "issue comment scrolling"

lettargetSpan=document.querySelector<HTMLElement>(`#${CSS.escape(targetId)}`);
if(!targetSpan){
// Flush pending DOM mutations (htmx, folding animations, etc.) before giving up
awaitwaitNextAnimationFrame();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it needs to wait for the animation?

@wxiaoguang
Copy link
Contributor

The logic is quite complex, I would suggest to carefully review every line and make sure every line is clear. Or you can also help to answer my questions. Thank you.@lafriks@Zettat123

@GiteaBotGiteaBot removed the lgtm/doneThis PR has enough approvals to get merged. There are no important open reservations anymore. labelDec 14, 2025
@GiteaBotGiteaBot added lgtm/need 1This PR needs approval from one additional maintainer to be merged. lgtm/need 2This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1This PR needs approval from one additional maintainer to be merged. labelsDec 14, 2025
if(e.defaultPrevented)return;
handleDiffLineNumberClick(cell,e);
});
window.addEventListener('hashchange',()=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why duplicate "hashchange" listeners? Won't it conflict withwindow.addEventListener('hashchange', onLocationHashChange);?

Comment on lines +19 to +20
window.location.hash='';
window.location.hash=currentHash;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think readers can understand why it needs these two lines?

When you copy code, why not also copy the comments? Or, why not introduce a common function for such requirement?

if(targetElement){
// Try again to highlight and scroll now that the element is loaded
constsuccess=awaithighlightDiffSelectionFromHash();
if(success)return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this loop still right?

If the selected line are in the expanded area (blob excerpt), now you just keep "loading more files", but the selected range can never be really loaded.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@silverwindsilverwindsilverwind left review comments

@wxiaoguangwxiaoguangwxiaoguang left review comments

@lafrikslafriksAwaiting requested review from lafriks

@Zettat123Zettat123Awaiting requested review from Zettat123

Assignees

No one assigned

Labels

lgtm/need 2This PR needs two approvals by maintainers to be considered for merging.modifies/frontendmodifies/templatesThis PR modifies the template filestopic/uiChange the appearance of the Gitea UItype/enhancementAn improvement of existing functionality

Projects

None yet

Milestone

1.26.0

Development

Successfully merging this pull request may close these issues.

6 participants

@lunny@wxiaoguang@silverwind@lafriks@Zettat123@GiteaBot

[8]ページ先頭

©2009-2025 Movatter.jp