Skip to content

Commit 64825ec

Browse files
committed
Fixed #31144
1 parent c363bd0 commit 64825ec

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

templates/repo/diff/box.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@
164164
<input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
165165
</label>
166166
{{end}}
167-
<div class="ui dropdown basic">
167+
<div class="ui tiny js-btn-diff-file-menu">
168168
{{svg "octicon-kebab-horizontal" 18 "icon tw-mx-2"}}
169-
<div class="ui menu">
169+
<div class="tippy-target">
170170
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
171-
<button class="unescape-button item">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
172-
<button class="escape-button tw-hidden item">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
171+
<a class="unescape-button item">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</a>
172+
<a class="escape-button tw-hidden item">{{ctx.Locale.Tr "repo.escape_control_characters"}}</a>
173173
{{end}}
174174
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
175175
{{if $file.IsDeleted}}

web_src/js/features/repo-diff.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import $ from 'jquery';
2+
import {createTippy} from '../modules/tippy.ts';
23
import {initCompReactionSelector} from './comp/ReactionSelector.ts';
34
import {initRepoIssueContentHistory} from './repo-issue-content.ts';
45
import {initDiffFileTree, initDiffFileList} from './repo-diff-filetree.ts';
@@ -225,3 +226,23 @@ export function initRepoDiffView() {
225226
initViewedCheckboxListenerFor();
226227
initExpandAndCollapseFilesButton();
227228
}
229+
230+
export function initRepoDiffFileMenu() {
231+
let tippyIndex = 0;
232+
$('.js-btn-diff-file-menu').each(function () {
233+
tippyIndex++;
234+
this.setAttribute('data-diff-file-menu-tippy-target-id', tippyIndex);
235+
const $menu = $(this).find('.tippy-target');
236+
if ($menu.length < 1) return;
237+
$menu[0].setAttribute('data-diff-file-menu-tippy-id', tippyIndex);
238+
createTippy(this, {
239+
content: $menu[0],
240+
role: 'menu',
241+
theme: 'menu',
242+
trigger: 'click',
243+
placement: 'bottom',
244+
interactive: true,
245+
hideOnClick: true,
246+
});
247+
});
248+
}

web_src/js/features/repo-unicode-escape.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export function initUnicodeEscapeButton() {
77

88
e.preventDefault();
99

10-
const fileContent = btn.closest('.file-content, .non-diff-file-content');
10+
let fileContent = btn.closest('.file-content, .non-diff-file-content');
11+
if (!fileContent) {
12+
const tippyTarget = btn.closest('.tippy-target');
13+
if (tippyTarget) {
14+
fileContent = document.querySelectorAll(`[data-diff-file-menu-tippy-target-id="${tippyTarget.getAttribute('data-diff-file-menu-tippy-id')}"]`)[0].closest('.file-content, .non-diff-file-content');
15+
}
16+
}
1117
const fileView = fileContent?.querySelectorAll('.file-code, .file-view');
18+
if (!fileView) return;
1219
if (btn.matches('.escape-button')) {
1320
for (const el of fileView) el.classList.add('unicode-escaped');
1421
hideElem(btn);

web_src/js/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {initSshKeyFormParser} from './features/sshkey-helper.ts';
4242
import {initUserSettings} from './features/user-settings.ts';
4343
import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/repo-common.ts';
4444
import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
45-
import {initRepoDiffView} from './features/repo-diff.ts';
45+
import {initRepoDiffView, initRepoDiffFileMenu} from './features/repo-diff.ts';
4646
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.ts';
4747
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
4848
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
@@ -212,6 +212,7 @@ onDomReady(() => {
212212
initUserAuthWebAuthnRegister,
213213
initUserSettings,
214214
initRepoDiffView,
215+
initRepoDiffFileMenu,
215216
initPdfViewer,
216217
initScopedAccessTokenCategories,
217218
initColorPickers,

0 commit comments

Comments
 (0)