Defect #36580

Fix code copying in common browsers

Added by Vitaly vit9696 5 months ago. Updated 3 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Text formatting
Target version:5.0.0
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:

redmine-4.2.3-codelines-2022-02-06-20-12.diff Magnifier (4.81 KB) Vitaly vit9696, 2022-02-06 18:16

safari-without-patch.png (23.6 KB) Go MAEDA, 2022-02-07 08:27

safari-with-patch.png (25.1 KB) Go MAEDA, 2022-02-07 08:27

Screenshot 2022-02-08 at 14.01.31.png (231 KB) Vitaly vit9696, 2022-02-08 12:01

Screenshot 2022-02-08 at 14.04.50.jpg (573 KB) Vitaly vit9696, 2022-02-08 12:05

36580-v2.patch Magnifier (13 KB) Go MAEDA, 2022-02-15 07:12

36580-v3.patch Magnifier (13.9 KB) Yuichi HARADA, 2022-02-17 07:03


Related issues

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

Associated revisions

Revision 21415
Added by Go MAEDA 5 months ago

Fix code copying in common browsers (#36580).

Patch by Vitaly vit9696.

History

#1 Updated by Go MAEDA 5 months 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:

#2 Updated by Vitaly vit9696 5 months 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

#3 Updated by Holger Just 5 months ago

  • Assignee set to Go MAEDA

Maeda-san, could you clarify this?

#4 Updated by Go MAEDA 5 months 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.

#5 Updated by Go MAEDA 5 months ago

Updated the patch to include fixes for existing tests.

#6 Updated by Yuichi HARADA 5 months 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

#7 Updated by Go MAEDA 5 months ago

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

#8 Updated by Go MAEDA 5 months ago

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

Committed the patch. Thank you.

#9 Updated by Go MAEDA 3 months ago

  • Tracker changed from Patch to Defect

Also available in: Atom PDF