From da230412574daa9697b4cef24c7be6209b8884dc Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 26 Jun 2019 23:35:07 +0200 Subject: fix extra newlines when copying from diff in Firefox (#7288) * fix extra newlines when copying from diff See https://bugzilla.mozilla.org/show_bug.cgi?id=1273836 Basically, the
 seems to add a forced newline that is not
possible to get rid of via CSS, so I replaced it with just a .

Secondly, .lines-type-marker also forced a newline in the copied text,
but that was possible to get rid of via user-select.

Safari still has a extraneous newline in the copied text of unknown
origin, but this should not block stop this PR.

* simplify .line-type-marker

* fix selector

* remove erronous ^^^

* Fix empty split diff

* Fix arc-theme-green

* fix add comment

* ensure line-num is copied too

* Update templates/repo/diff/box.tmpl

Co-Authored-By: zeripath 

* attempt to fix safari via removing 

* remove useless whitespace at the end of 'class'

* remove inter-tag whitespace for code s

* more inter-tag removal

* final inter-tag removal

* attempt to fix empty line copy

* move and comment getLineContent

* fix golint

* make background grey for missing added code
---
 templates/repo/diff/box.tmpl             | 43 +++++++++++---------------------
 templates/repo/diff/section_unified.tmpl | 19 +++-----------
 2 files changed, 19 insertions(+), 43 deletions(-)

(limited to 'templates/repo')

diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl
index 94ac094fa4..056b8aea20 100644
--- a/templates/repo/diff/box.tmpl
+++ b/templates/repo/diff/box.tmpl
@@ -120,30 +120,12 @@
 											{{range $j, $section := $file.Sections}}
 												{{range $k, $line := $section.Lines}}
 													
-														
-															
-														
-														
-															
{{if $line.LeftIdx}}{{end}}
- - - {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}} - + - {{end}} -
{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
- - - - - -
{{if $line.RightIdx}}{{end}}
- - - {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}} - + - {{end}} -
{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}
- + + {{if $line.LeftIdx}}{{end}} + {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}+{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + + {{if $line.RightIdx}}{{end}} + {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}+{{end}}{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} {{if gt (len $line.Comments) 0}} @@ -230,17 +212,22 @@ document.addEventListener('DOMContentLoaded', function() { $('tr.add-code').each(function() { var prev = $(this).prev(); - if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') { - while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') { + if(prev.is('.del-code') && prev.children().eq(5).text().trim() === '') { + while(prev.prev().is('.del-code') && prev.prev().children().eq(5).text().trim() === '') { prev = prev.prev(); } - prev.children().eq(2).html($(this).children().eq(2).html()); + prev.children().eq(3).attr("data-line-num", $(this).children().eq(3).attr("data-line-num")); prev.children().eq(3).html($(this).children().eq(3).html()); + prev.children().eq(4).html($(this).children().eq(4).html()); + prev.children().eq(5).html($(this).children().eq(5).html()); prev.children().eq(0).addClass('del-code'); prev.children().eq(1).addClass('del-code'); - prev.children().eq(2).addClass('add-code'); + prev.children().eq(2).addClass('del-code'); prev.children().eq(3).addClass('add-code'); + prev.children().eq(4).addClass('add-code'); + prev.children().eq(5).addClass('add-code'); + $(this).remove(); } }); diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 5706e4cdee..f33381a1a2 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -8,22 +8,11 @@ {{/* {{if gt $j 0}}{{end}} */}} {{else}} - - - - - - + + {{end}} - -
- - - {{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}} - + - {{end}} -
{{$section.GetComputedInlineDiffFor $line}}
- + + {{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}+{{end}}{{$section.GetComputedInlineDiffFor $line}} {{if gt (len $line.Comments) 0}} -- cgit v1.2.3