Browse Source

Fix diff indentation (#613)

master
Federico Brigante 7 years ago
committed by Sindre Sorhus
parent
commit
5403bbcc49
  1. 10
      extension/content.css
  2. 44
      src/content.js
  3. 2
      src/libs/utils.js

10
extension/content.css

@ -558,10 +558,6 @@ Hidden content area created to increase hover target
.refined-github-diff-signs .blob-code-deletion:before {
content: '-';
}
.refined-github-diff-signs .blob-code-addition .blob-code-inner,
.refined-github-diff-signs .blob-code-deletion .blob-code-inner {
padding-left: 1ch;
}
/* Prevent copy of ghost whitespace where supported (#317) */
.refined-github-diff-signs .add-line-comment {
@ -569,6 +565,12 @@ Hidden content area created to increase hover target
user-select: none;
}
/* Restore removed space with unselectable one */
.refined-github-diff-signs .blob-code-inner:before {
content: ' ' !important;
user-select: none;
}
/* Remove "pro tip!" box on profile page (appears when name isn't set) */
.new-user-avatar-cta {
display: none !important;

44
src/content.js

@ -272,16 +272,39 @@ function addPatchDiffLinks() {
);
}
function removeSelectableWhiteSpaceFromDiffs() {
for (const commentBtn of select.all('.add-line-comment')) {
for (const node of commentBtn.childNodes) {
if (node.nodeType === Node.TEXT_NODE) {
node.remove();
}
}
}
}
/* Lasciate ogne speranza, voi ch'intrate. */
function removeDiffSigns() {
$('.diff-table:not(.refined-github-diff-signs)')
.addClass('refined-github-diff-signs')
.find(`
.blob-code-addition .blob-code-inner,
.blob-code-deletion .blob-code-inner
`)
.each((index, el) => {
el.firstChild.textContent = el.firstChild.textContent.slice(1);
});
for (const line of select.all('tr:not(.refined-github-diff-signs)')) {
line.classList.add('refined-github-diff-signs');
for (const code of select.all('.blob-code-inner', line)) {
// Drop -, + or space
code.firstChild.textContent = code.firstChild.textContent.slice(1);
// If a line is empty, the next line will collapse
if (code.textContent.length === 0) {
code.prepend(new Text(' '));
}
}
}
}
function removeDiffSignsAndWatchExpansions() {
removeSelectableWhiteSpaceFromDiffs();
removeDiffSigns();
for (const file of $('.diff-table:not(.rgh-watching-lines)').has('.diff-expander')) {
file.classList.add('rgh-watching-lines');
observeEl(file.tBodies[0], removeDiffSigns);
}
}
function markMergeCommitsInList() {
@ -572,10 +595,9 @@ async function onDomReady() {
}
if (pageDetect.hasDiff()) {
removeDiffSigns();
const diffElements = select('.js-discussion, #files');
if (diffElements) {
new MutationObserver(removeDiffSigns).observe(diffElements, {childList: true, subtree: true});
observeEl(diffElements, removeDiffSignsAndWatchExpansions, {childList: true, subtree: true});
}
addDiffViewWithoutWhitespaceOption();
}

2
src/libs/utils.js

@ -22,7 +22,7 @@ export const observeEl = (el, listener, options = {childList: true}) => {
}
// Run first
listener();
listener([]);
// Run on updates
return new MutationObserver(listener).observe(el, options);

Loading…
Cancel
Save