|
|
@ -16,8 +16,16 @@ function changeHash(hash) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function selectRange($list, $select, $from) { |
|
|
|
function isBlame() { |
|
|
|
$list.removeClass('active'); |
|
|
|
return Boolean(document.querySelector('div.blame')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getLineEls() { |
|
|
|
|
|
|
|
return document.querySelectorAll(`.code-view td.lines-code${isBlame() ? '.blame-code' : ''}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { |
|
|
|
|
|
|
|
$linesEls.closest('tr').removeClass('active'); |
|
|
|
|
|
|
|
|
|
|
|
// add hashchange to permalink
|
|
|
|
// add hashchange to permalink
|
|
|
|
const $refInNewIssue = $('a.ref-in-new-issue'); |
|
|
|
const $refInNewIssue = $('a.ref-in-new-issue'); |
|
|
@ -25,7 +33,7 @@ function selectRange($list, $select, $from) { |
|
|
|
const $viewGitBlame = $('a.view_git_blame'); |
|
|
|
const $viewGitBlame = $('a.view_git_blame'); |
|
|
|
|
|
|
|
|
|
|
|
const updateIssueHref = function (anchor) { |
|
|
|
const updateIssueHref = function (anchor) { |
|
|
|
if ($refInNewIssue.length === 0) { |
|
|
|
if (!$refInNewIssue.length) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
const urlIssueNew = $refInNewIssue.attr('data-url-issue-new'); |
|
|
|
const urlIssueNew = $refInNewIssue.attr('data-url-issue-new'); |
|
|
@ -35,9 +43,7 @@ function selectRange($list, $select, $from) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const updateViewGitBlameFragment = function (anchor) { |
|
|
|
const updateViewGitBlameFragment = function (anchor) { |
|
|
|
if ($viewGitBlame.length === 0) { |
|
|
|
if (!$viewGitBlame.length) return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let href = $viewGitBlame.attr('href'); |
|
|
|
let href = $viewGitBlame.attr('href'); |
|
|
|
href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`; |
|
|
|
href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`; |
|
|
|
if (anchor.length !== 0) { |
|
|
|
if (anchor.length !== 0) { |
|
|
@ -47,17 +53,15 @@ function selectRange($list, $select, $from) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const updateCopyPermalinkUrl = function(anchor) { |
|
|
|
const updateCopyPermalinkUrl = function(anchor) { |
|
|
|
if ($copyPermalink.length === 0) { |
|
|
|
if (!$copyPermalink.length) return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let link = $copyPermalink.attr('data-url'); |
|
|
|
let link = $copyPermalink.attr('data-url'); |
|
|
|
link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`; |
|
|
|
link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`; |
|
|
|
$copyPermalink.attr('data-url', link); |
|
|
|
$copyPermalink.attr('data-url', link); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if ($from) { |
|
|
|
if ($selectionStartEls) { |
|
|
|
let a = parseInt($select.attr('rel').slice(1)); |
|
|
|
let a = parseInt($selectionEndEl.attr('rel').slice(1)); |
|
|
|
let b = parseInt($from.attr('rel').slice(1)); |
|
|
|
let b = parseInt($selectionStartEls.attr('rel').slice(1)); |
|
|
|
let c; |
|
|
|
let c; |
|
|
|
if (a !== b) { |
|
|
|
if (a !== b) { |
|
|
|
if (a > b) { |
|
|
|
if (a > b) { |
|
|
@ -69,7 +73,9 @@ function selectRange($list, $select, $from) { |
|
|
|
for (let i = a; i <= b; i++) { |
|
|
|
for (let i = a; i <= b; i++) { |
|
|
|
classes.push(`[rel=L${i}]`); |
|
|
|
classes.push(`[rel=L${i}]`); |
|
|
|
} |
|
|
|
} |
|
|
|
$list.filter(classes.join(',')).addClass('active'); |
|
|
|
$linesEls.filter(classes.join(',')).each(function () { |
|
|
|
|
|
|
|
$(this).closest('tr').addClass('active'); |
|
|
|
|
|
|
|
}); |
|
|
|
changeHash(`#L${a}-L${b}`); |
|
|
|
changeHash(`#L${a}-L${b}`); |
|
|
|
|
|
|
|
|
|
|
|
updateIssueHref(`L${a}-L${b}`); |
|
|
|
updateIssueHref(`L${a}-L${b}`); |
|
|
@ -78,12 +84,12 @@ function selectRange($list, $select, $from) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$select.addClass('active'); |
|
|
|
$selectionEndEl.closest('tr').addClass('active'); |
|
|
|
changeHash(`#${$select.attr('rel')}`); |
|
|
|
changeHash(`#${$selectionEndEl.attr('rel')}`); |
|
|
|
|
|
|
|
|
|
|
|
updateIssueHref($select.attr('rel')); |
|
|
|
updateIssueHref($selectionEndEl.attr('rel')); |
|
|
|
updateViewGitBlameFragment($select.attr('rel')); |
|
|
|
updateViewGitBlameFragment($selectionEndEl.attr('rel')); |
|
|
|
updateCopyPermalinkUrl($select.attr('rel')); |
|
|
|
updateCopyPermalinkUrl($selectionEndEl.attr('rel')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function showLineButton() { |
|
|
|
function showLineButton() { |
|
|
@ -96,10 +102,10 @@ function showLineButton() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// find active row and add button
|
|
|
|
// find active row and add button
|
|
|
|
const tr = document.querySelector('.code-view td.lines-code.active').closest('tr'); |
|
|
|
const tr = document.querySelector('.code-view tr.active'); |
|
|
|
const td = tr.querySelector('td'); |
|
|
|
const td = tr.querySelector('td.lines-num'); |
|
|
|
const btn = document.createElement('button'); |
|
|
|
const btn = document.createElement('button'); |
|
|
|
btn.classList.add('code-line-button'); |
|
|
|
btn.classList.add('code-line-button', 'ui', 'basic', 'button'); |
|
|
|
btn.innerHTML = svg('octicon-kebab-horizontal'); |
|
|
|
btn.innerHTML = svg('octicon-kebab-horizontal'); |
|
|
|
td.prepend(btn); |
|
|
|
td.prepend(btn); |
|
|
|
|
|
|
|
|
|
|
@ -123,14 +129,18 @@ function showLineButton() { |
|
|
|
export function initRepoCodeView() { |
|
|
|
export function initRepoCodeView() { |
|
|
|
if ($('.code-view .lines-num').length > 0) { |
|
|
|
if ($('.code-view .lines-num').length > 0) { |
|
|
|
$(document).on('click', '.lines-num span', function (e) { |
|
|
|
$(document).on('click', '.lines-num span', function (e) { |
|
|
|
const $select = $(this); |
|
|
|
const linesEls = getLineEls(); |
|
|
|
let $list; |
|
|
|
const selectedEls = Array.from(linesEls).filter((el) => { |
|
|
|
if ($('div.blame').length) { |
|
|
|
return el.matches(`[rel=${this.getAttribute('id')}]`); |
|
|
|
$list = $('.code-view td.lines-code.blame-code'); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
$list = $('.code-view td.lines-code'); |
|
|
|
let from; |
|
|
|
|
|
|
|
if (e.shiftKey) { |
|
|
|
|
|
|
|
from = Array.from(linesEls).filter((el) => { |
|
|
|
|
|
|
|
return el.closest('tr').classList.contains('active'); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null)); |
|
|
|
selectRange($(linesEls), $(selectedEls), from ? $(from) : null); |
|
|
|
|
|
|
|
|
|
|
|
if (window.getSelection) { |
|
|
|
if (window.getSelection) { |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
@ -138,28 +148,20 @@ export function initRepoCodeView() { |
|
|
|
document.selection.empty(); |
|
|
|
document.selection.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// show code view menu marker (don't show in blame page)
|
|
|
|
showLineButton(); |
|
|
|
if ($('div.blame').length === 0) { |
|
|
|
|
|
|
|
showLineButton(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$(window).on('hashchange', () => { |
|
|
|
$(window).on('hashchange', () => { |
|
|
|
let m = window.location.hash.match(rangeAnchorRegex); |
|
|
|
let m = window.location.hash.match(rangeAnchorRegex); |
|
|
|
let $list; |
|
|
|
const $linesEls = $(getLineEls()); |
|
|
|
if ($('div.blame').length) { |
|
|
|
|
|
|
|
$list = $('.code-view td.lines-code.blame-code'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$list = $('.code-view td.lines-code'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let $first; |
|
|
|
let $first; |
|
|
|
if (m) { |
|
|
|
if (m) { |
|
|
|
$first = $list.filter(`[rel=${m[1]}]`); |
|
|
|
$first = $linesEls.filter(`[rel=${m[1]}]`); |
|
|
|
if ($first.length) { |
|
|
|
if ($first.length) { |
|
|
|
selectRange($list, $first, $list.filter(`[rel=${m[2]}]`)); |
|
|
|
selectRange($linesEls, $first, $linesEls.filter(`[rel=${m[2]}]`)); |
|
|
|
|
|
|
|
|
|
|
|
// show code view menu marker (don't show in blame page)
|
|
|
|
// show code view menu marker (don't show in blame page)
|
|
|
|
if ($('div.blame').length === 0) { |
|
|
|
if (!isBlame()) { |
|
|
|
showLineButton(); |
|
|
|
showLineButton(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -169,12 +171,12 @@ export function initRepoCodeView() { |
|
|
|
} |
|
|
|
} |
|
|
|
m = window.location.hash.match(singleAnchorRegex); |
|
|
|
m = window.location.hash.match(singleAnchorRegex); |
|
|
|
if (m) { |
|
|
|
if (m) { |
|
|
|
$first = $list.filter(`[rel=L${m[2]}]`); |
|
|
|
$first = $linesEls.filter(`[rel=L${m[2]}]`); |
|
|
|
if ($first.length) { |
|
|
|
if ($first.length) { |
|
|
|
selectRange($list, $first); |
|
|
|
selectRange($linesEls, $first); |
|
|
|
|
|
|
|
|
|
|
|
// show code view menu marker (don't show in blame page)
|
|
|
|
// show code view menu marker (don't show in blame page)
|
|
|
|
if ($('div.blame').length === 0) { |
|
|
|
if (!isBlame()) { |
|
|
|
showLineButton(); |
|
|
|
showLineButton(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|