debian-mirror-gitlab/app/assets/javascripts/code_navigation/utils/index.js

29 lines
998 B
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
export const cachedData = new Map();
export const getCurrentHoverElement = () => cachedData.get('current');
2021-03-08 18:12:59 +05:30
export const setCurrentHoverElement = (el) => cachedData.set('current', el);
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
export const addInteractionClass = (path, d) => {
const lineNumber = d.start_line + 1;
const lines = document
.querySelector(`[data-path="${path}"]`)
.querySelectorAll(`.blob-content #LC${lineNumber}, .line_content:not(.old) #LC${lineNumber}`);
if (!lines?.length) return;
2021-03-08 18:12:59 +05:30
lines.forEach((line) => {
2020-04-22 19:07:51 +05:30
let charCount = 0;
const el = [...line.childNodes].find(({ textContent }) => {
if (charCount === d.start_char) return true;
charCount += textContent.length;
return false;
});
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
if (el) {
el.setAttribute('data-char-index', d.start_char);
el.setAttribute('data-line-index', d.start_line);
el.classList.add('cursor-pointer', 'code-navigation', 'js-code-navigation');
2020-07-28 23:09:34 +05:30
el.closest('.line').classList.add('code-navigation-line');
2020-04-22 19:07:51 +05:30
}
});
2020-03-13 15:44:24 +05:30
};