Project

General

Profile

Actions

Defect #36580

closed

Fix code copying in common browsers

Added by Vitaly vit9696 over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

This patch resolves https://www.redmine.org/issues/3382 for:

  • Chrome-based browsers (empty lines do not get copied).
  • Safari (line numbers are inserted to the copied code, empty lines do not get copied, extra spaces are inserted before each line).
  • Firefox (empty lines are inserted to the copied code).

As for Chrome and Safari the only way to make them properly copy empty newlines is to insert a "br" element instead of "pre".

As for Safari, data marked as user-select none will still be copied, thus the content trick used in other SCM apps. It is additionally important to put "a" element right after "th", because otherwise there will be spaces in front of the line.

As for Firefox, there are multiple related issues in their bugtracker:

Files

redmine-4.2.3-codelines-2022-02-06-20-12.diff (4.81 KB) redmine-4.2.3-codelines-2022-02-06-20-12.diff Vitaly vit9696, 2022-02-06 18:16
safari-without-patch.png (23.6 KB) safari-without-patch.png Go MAEDA, 2022-02-07 08:27
safari-with-patch.png (25.1 KB) safari-with-patch.png Go MAEDA, 2022-02-07 08:27
Screenshot 2022-02-08 at 14.01.31.png (231 KB) Screenshot 2022-02-08 at 14.01.31.png Vitaly vit9696, 2022-02-08 12:01
Screenshot 2022-02-08 at 14.04.50.jpg (573 KB) Screenshot 2022-02-08 at 14.04.50.jpg Vitaly vit9696, 2022-02-08 12:05
36580-v2.patch (13 KB) 36580-v2.patch Go MAEDA, 2022-02-15 07:12
36580-v3.patch (13.9 KB) 36580-v3.patch Yuichi HARADA, 2022-02-17 07:03

Related issues

Related to Redmine - Feature #3382: Ability to select only source code without line numbersClosed2009-05-18

Actions
Actions #1

Updated by Go MAEDA over 2 years ago

Thank you for posting the patch that fixes the issue that has not been fixed for years.

However, I found an issue with Safari that all preceding white spaces of a line are stripped.

before:

after:

Actions #2

Updated by Vitaly vit9696 over 2 years ago

Thanks for testing, but I am afraid I need more details about the issue, because it works fine on macOS 12.2 with the latest Safari for me.

  • What Safari version do you have?
  • Could you post the source of the file?
  • Could you post HTML source of page? Could do both the whole part of just the important part. E.g. I have
    <div>    <span class="k">union</span> <span class="n">ldshape</span> <span class="n">u</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">};</span>
    </div>
    
  • Could you also post computed CSS for the div element? I attached mine on the screenshot to get an idea what I need
Actions #3

Updated by Holger Just over 2 years ago

  • Assignee set to Go MAEDA

Maeda-san, could you clarify this?

Actions #4

Updated by Go MAEDA over 2 years ago

  • Assignee deleted (Go MAEDA)
  • Target version set to 5.0.0

I found that the "issue" I reported in #36580#note-1 was due to browser cache. Super reload resolved the issue. I am very sorry for bothering you.

Setting the target version to 5.0.0.

Actions #5

Updated by Go MAEDA over 2 years ago

Updated the patch to include fixes for existing tests.

Actions #6

Updated by Yuichi HARADA over 2 years ago

Go MAEDA wrote:

Updated the patch to include fixes for existing tests.

The test in test/functional/repositories_cvs_controller_test.rb failed, so I fixed the test and added it to 36580-v2.patch.

Failure:
RepositoriesCvsControllerTest#test_annotate [test/functional/repositories_cvs_controller_test.rb:285]:
<21> expected but was
<>..
Expected 0 to be >= 1.

rails test test/functional/repositories_cvs_controller_test.rb:268
diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb
index 09db1611a8..fdd8e986d1 100644
--- a/test/functional/repositories_cvs_controller_test.rb
+++ b/test/functional/repositories_cvs_controller_test.rb
@@ -283,13 +283,13 @@ class RepositoriesCvsControllerTest < Redmine::RepositoryControllerTest

       # 1.1 line
       assert_select 'tr' do
-        assert_select 'th.line-num', :text => '21'
+        assert_select 'th.line-num a[data-txt=?]', '21'
         assert_select 'td.revision', :text => /1.1/
         assert_select 'td.author', :text => /LANG/
       end
       # 1.2 line
       assert_select 'tr' do
-        assert_select 'th.line-num', :text => '32'
+        assert_select 'th.line-num a[data-txt=?]', '32'
         assert_select 'td.revision', :text => /1.2/
         assert_select 'td.author', :text => /LANG/
       end
Actions #7

Updated by Go MAEDA about 2 years ago

  • Related to Feature #3382: Ability to select only source code without line numbers added
Actions #8

Updated by Go MAEDA about 2 years ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch. Thank you.

Actions #9

Updated by Go MAEDA about 2 years ago

  • Tracker changed from Patch to Defect
Actions

Also available in: Atom PDF