Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion web_src/css/repo/file-view.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.file-view tr.active {
.file-view tr.active .lines-num,
.file-view tr.active .lines-escape,
.file-view tr.active .lines-code {
background: var(--color-highlight-bg);
}

/* set correct border radius on the last active lines, to avoid border overflow */
.file-view tr.active:last-of-type .lines-code {
border-bottom-right-radius: var(--border-radius);
}
Expand All @@ -10,6 +13,7 @@
position: relative;
}

/* add a darker "handler" at the beginning of the active line */
.file-view tr.active .lines-num::before {
content: "";
position: absolute;
Expand Down
7 changes: 5 additions & 2 deletions web_src/js/features/repo-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ function showLineButton() {
}

export function initRepoCodeView() {
if (!document.querySelector('.code-view .lines-num')) return;
if (!document.querySelector('.file-view.code-view')) return;

// "file code view" and "blame" pages need this "line number button" feature
let selRangeStart: string;
addDelegatedEventListener(document, 'click', '.lines-num span', (el: HTMLElement, e: KeyboardEvent) => {
addDelegatedEventListener(document, 'click', '.code-view .lines-num span', (el: HTMLElement, e: KeyboardEvent) => {
if (!selRangeStart || !e.shiftKey) {
selRangeStart = el.getAttribute('id');
selectRange(selRangeStart);
Expand All @@ -125,8 +126,10 @@ export function initRepoCodeView() {
showLineButton();
});

// apply the selected range from the URL hash
const onHashChange = () => {
if (!window.location.hash) return;
if (!document.querySelector('.code-view .lines-num')) return;
const range = window.location.hash.substring(1);
const first = selectRange(range);
if (first) {
Expand Down
27 changes: 20 additions & 7 deletions web_src/js/modules/tippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function createTippy(target: Element, opts: TippyOpts = {}): Instance {
}
}
visibleInstances.add(instance);
target.setAttribute('aria-controls', instance.popper.id);
return onShow?.(instance);
},
arrow: arrow ?? (theme === 'bare' ? false : arrowSvg),
Expand Down Expand Up @@ -180,13 +181,25 @@ export function initGlobalTooltips(): void {
}

export function showTemporaryTooltip(target: Element, content: Content): void {
// if the target is inside a dropdown, the menu will be hidden soon
// so display the tooltip on the dropdown instead
target = target.closest('.ui.dropdown') || target;
const tippy = target._tippy ?? attachTooltip(target, content);
tippy.setContent(content);
if (!tippy.state.isShown) tippy.show();
tippy.setProps({
// if the target is inside a dropdown or tippy popup, the menu will be hidden soon
// so display the tooltip on the "aria-controls" element or dropdown instead
let refClientRect: DOMRect;
const popupTippyId = target.closest(`[data-tippy-root]`)?.id;
if (popupTippyId) {
// for example, the "Copy Permalink" button in the "File View" page for the selected lines
target = document.body;
refClientRect = document.querySelector(`[aria-controls="${CSS.escape(popupTippyId)}"]`)?.getBoundingClientRect();
refClientRect = refClientRect ?? new DOMRect(0, 0, 0, 0); // fallback to empty rect if not found, tippy doesn't accept null
} else {
// for example, the "Copy Link" button in the issue header dropdown menu
target = target.closest('.ui.dropdown') ?? target;
refClientRect = target.getBoundingClientRect();
}
const tooltipTippy = target._tippy ?? attachTooltip(target, content);
tooltipTippy.setContent(content);
tooltipTippy.setProps({getReferenceClientRect: () => refClientRect});
if (!tooltipTippy.state.isShown) tooltipTippy.show();
tooltipTippy.setProps({
onHidden: (tippy) => {
// reset the default tooltip content, if no default, then this temporary tooltip could be destroyed
if (!attachTooltip(target)) {
Expand Down