aboutsummaryrefslogtreecommitdiffstats
path: root/modules/highlight
diff options
context:
space:
mode:
authormrsdizzie <info@mrsdizzie.com>2020-07-08 17:02:38 -0400
committerGitHub <noreply@github.com>2020-07-08 22:02:38 +0100
commita6168fa25d0a7dfee689e1bce940557fff70d392 (patch)
tree6571fae3f1d73ffc9d3ace5ff3c3bcbf7c34909c /modules/highlight
parentcedbd3684fe76875c9ce3b2c12471db63a11f421 (diff)
downloadgitea-a6168fa25d0a7dfee689e1bce940557fff70d392.tar.gz
gitea-a6168fa25d0a7dfee689e1bce940557fff70d392.zip
Make copy/paste work for source code (#12191)
* Make copy/paste work for source code Fix regression casued by #12047 so copy/paste works properly in all browsers. Fixes #12184 Also while looking at this I saw a small display issue for blame view. I think #12023 was merged into original PR through an update branch before #12047 was merged and made one of the css ruules not apply anymore. * use pseudo-element to prevent copying of comment + symbol even when not visually selected * remove added newline here should not be necessary anymore * make sure empty line is newline so there is something to select and copy
Diffstat (limited to 'modules/highlight')
-rw-r--r--modules/highlight/highlight.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go
index 5d66e4c32d..31448ccd63 100644
--- a/modules/highlight/highlight.go
+++ b/modules/highlight/highlight.go
@@ -44,6 +44,9 @@ func NewContext() {
func Code(fileName, code string) string {
NewContext()
+ if code == "" {
+ return "\n"
+ }
if len(code) > sizeLimit {
return code
}
@@ -133,7 +136,12 @@ func File(numLines int, fileName string, code []byte) map[int]string {
m := make(map[int]string, numLines)
for k, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) {
line := k + 1
- m[line] = string(v)
+ content := string(v)
+ //need to keep lines that are only \n so copy/paste works properly in browser
+ if content == "" {
+ content = "\n"
+ }
+ m[line] = content
}
return m
}
@@ -143,7 +151,12 @@ func plainText(code string, numLines int) map[int]string {
m := make(map[int]string, numLines)
for k, v := range strings.SplitN(string(code), "\n", numLines) {
line := k + 1
- m[line] = string(v)
+ content := string(v)
+ //need to keep lines that are only \n so copy/paste works properly in browser
+ if content == "" {
+ content = "\n"
+ }
+ m[line] = content
}
return m
}