From 6a46743cd389aeefc20348445fee2135a8e4c35c Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 19 Feb 2022 07:36:40 +0000 Subject: [PATCH] Fix code copying in common browsers (#36580). Patch by Vitaly vit9696. git-svn-id: http://svn.redmine.org/redmine/trunk@21415 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/common/_diff.html.erb | 20 +++++++++---------- app/views/common/_file.html.erb | 10 ++++++---- app/views/repositories/annotate.html.erb | 8 ++++++-- public/stylesheets/scm.css | 8 +++++++- .../functional/attachments_controller_test.rb | 6 +++--- .../repositories_bazaar_controller_test.rb | 11 ++++++---- .../repositories_cvs_controller_test.rb | 4 ++-- .../repositories_git_controller_test.rb | 12 ++++++----- .../repositories_mercurial_controller_test.rb | 7 ++++--- ...repositories_subversion_controller_test.rb | 4 ++-- 10 files changed, 54 insertions(+), 36 deletions(-) diff --git a/app/views/common/_diff.html.erb b/app/views/common/_diff.html.erb index 35dfdea28..f54bdfa4c 100644 --- a/app/views/common/_diff.html.erb +++ b/app/views/common/_diff.html.erb @@ -6,7 +6,7 @@ <% diff.each do |table_file| -%>
<% if diff.diff_type == 'sbs' -%> - +
- + <% end -%> - + - + <% end -%> @@ -39,7 +39,7 @@
@@ -21,17 +21,17 @@ <% table_file.each_line do |spacing, line| -%> <% if spacing -%>
......
<%= line.nb_line_left %> -
<%= line.html_line_left.html_safe %>
+
<%= line.html_line_left.html_safe %>
<%= line.nb_line_right %> -
<%= line.html_line_right.html_safe %>
+
<%= line.html_line_right.html_safe %>
<% else -%> - +
<% end -%> - - + + <% end -%> diff --git a/app/views/common/_file.html.erb b/app/views/common/_file.html.erb index 95e0fb998..b0610f6ac 100644 --- a/app/views/common/_file.html.erb +++ b/app/views/common/_file.html.erb @@ -4,11 +4,13 @@ <% line_num = 1 %> <% syntax_highlight_lines(filename, Redmine::CodesetUtil.to_utf8_by_setting(content)).each do |line| %> - + <% line_num += 1 %> diff --git a/app/views/repositories/annotate.html.erb b/app/views/repositories/annotate.html.erb index 829090af6..de30e7c00 100644 --- a/app/views/repositories/annotate.html.erb +++ b/app/views/repositories/annotate.html.erb @@ -17,7 +17,7 @@ <% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %> <% revision = @annotate.revisions[line_num - 1] %> - + - + <% if line == "\n" or line == "\r\n" %> + + <% else %> + + <% end %> <% line_num += 1; previous_revision = revision %> <% end %> diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index 4640be5f9..3bbf6010b 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -61,8 +61,14 @@ table.filecontent th.line-num a { text-decoration: none; color: inherit; } +table.filecontent th.line-num a:after { + content: attr(data-txt); +} +table.diffcontent th.line-num:after { + content: attr(data-txt); +} table.filecontent td.line-code {padding: 0 0 0 4px;} -table.filecontent td.line-code pre { +table.filecontent td.line-code pre, table.filecontent td.line-code div { margin: 0px; white-space: pre-wrap; font-family:Consolas, Menlo, "Liberation Mono", Courier, monospace; font-size:12px; diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index f89b03052..885a79dbb 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -157,7 +157,7 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_response :success assert_equal 'text/html', @response.media_type assert_select 'tr#L1' do - assert_select 'th.line-num', :text => '1' + assert_select 'th.line-num a[data-txt=?]', '1' assert_select 'td', :text => /日本語/ end end @@ -174,7 +174,7 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_response :success assert_equal 'text/html', @response.media_type assert_select 'tr#L7' do - assert_select 'th.line-num', :text => '7' + assert_select 'th.line-num a[data-txt=?]', '7' assert_select 'td', :text => /Demande cr\?\?e avec succ\?s/ end end @@ -192,7 +192,7 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_response :success assert_equal 'text/html', @response.media_type assert_select 'tr#L7' do - assert_select 'th.line-num', :text => '7' + assert_select 'th.line-num a[data-txt=?]', '7' assert_select 'td', :text => /Demande créée avec succès/ end end diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index e8559fc78..929df7b39 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -181,7 +181,7 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest ) assert_response :success # Line 11 removed - assert_select 'th.line-num:contains(11) ~ td.diff_out', :text => /Display more information/ + assert_select 'th.line-num[data-txt=11] ~ td.diff_out', :text => /Display more information/ end end @@ -196,7 +196,8 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest ) assert_response :success - assert_select "th.line-num", :text => '2' do + assert_select "th.line-num" do + assert_select 'a[data-txt=?]', '2' assert_select "+ td.revision" do assert_select "a", :text => '3' assert_select "+ td.author", :text => "jsmith@" do @@ -226,7 +227,8 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest ) assert_response :success - assert_select "th.line-num", :text => '1' do + assert_select "th.line-num" do + assert_select "a[data-txt=?]", '1' assert_select "+ td.revision" do assert_select "a", :text => '2' assert_select "+ td.author", :text => "test &" do @@ -262,7 +264,8 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest ) assert_response :success - assert_select "th.line-num", :text => '1' do + assert_select "th.line-num" do + assert_select 'a[data-txt=?]', '1' assert_select "+ td.revision" do assert_select "a", :text => '2' assert_select "+ td.author", :text => "test Ü" do diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index 09db1611a..fdd8e986d 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 diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index 120118d9c..09458f7f9 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -378,7 +378,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest ) assert_response :success # Line 22 removed - assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/ + assert_select 'th.line-num[data-txt=22] ~ td.diff_out', :text => /def remove/ assert_select 'h2', :text => /2f9c0091/ end end @@ -403,7 +403,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest ) assert_response :success # Line 22 removed - assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/ + assert_select 'th.line-num[data-txt=22] ~ td.diff_out', :text => /def remove/ assert_select 'h2', :text => /2f9c0091/ end end @@ -589,7 +589,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest # Line 23, changeset 2f9c0091 assert_select 'tr' do - assert_select 'th.line-num', :text => '23' + assert_select 'th.line-num a[data-txt=?]', '23' assert_select 'td.revision', :text => /2f9c0091/ assert_select 'td.author', :text => 'jsmith' assert_select 'td', :text => /remove_watcher/ @@ -673,7 +673,8 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest :rev => r1 } ) - assert_select "th.line-num", :text => '1' do + assert_select "th.line-num" do + assert_select "a[data-txt=?]", '1' assert_select "+ td.revision" do assert_select "a", :text => '57ca437c' assert_select "+ td.author", :text => "jsmith" do @@ -698,7 +699,8 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest :rev => r1 } ) - assert_select "th.line-num", :text => '1' do + assert_select "th.line-num" do + assert_select "a[data-txt=?]", '1' assert_select "+ td.revision" do assert_select "a", :text => '83ca5fd5' assert_select "+ td.author", :text => "Felix Schäfer" do diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index fadb9c7f2..d88a95f0a 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -396,7 +396,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest assert_response :success if @diff_c_support # Line 22 removed - assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/ + assert_select 'th.line-num[data-txt=22] ~ td.diff_out', :text => /def remove/ assert_select 'h2', :text => /4:def6d2f1254a/ end end @@ -492,7 +492,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest # Line 22, revision 4:def6d2f1254a assert_select 'tr' do - assert_select 'th.line-num', :text => '22' + assert_select 'th.line-num a[data-txt=?]', '22' assert_select 'td.revision', :text => '4:def6d2f1254a' assert_select 'td.author', :text => 'jsmith' assert_select 'td', :text => /remove_watcher/ @@ -548,7 +548,8 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest } ) assert_response :success - assert_select "th.line-num", :text => '1' do + assert_select "th.line-num" do + assert_select "a[data-txt=?]", '1' assert_select "+ td.revision" do assert_select "a", :text => '20:709858aafd1b' assert_select "+ td.author", :text => "jsmith" do diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index 4c248a790..ca2a224a8 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -557,14 +557,14 @@ class RepositoriesSubversionControllerTest < Redmine::RepositoryControllerTest assert_response :success assert_select 'tr' do - assert_select 'th.line-num', :text => '1' + assert_select 'th.line-num a[data-txt=?]', '1' assert_select 'td.revision', :text => '4' assert_select 'td.author', :text => 'jp' assert_select 'td', :text => /stdio.h/ end # Same revision assert_select 'tr' do - assert_select 'th.line-num', :text => '2' + assert_select 'th.line-num a[data-txt=?]', '2' assert_select 'td.revision', :text => '' assert_select 'td.author', :text => '' end -- 2.39.5
@@ -58,10 +58,10 @@
<%= line.nb_line_left %><%= line.nb_line_right %> -
<%= line.html_line.html_safe %>
+
<%= line.html_line.html_safe %>
- <%= line_num %> - -
<%= line.html_safe %>
+ <% if line == "\n" or line == "\r\n" %> +
+ <% else %> +
<%= line.html_safe %>
+ <% end %>
<%= line_num %> <% if revision && revision != previous_revision %> <%= revision.identifier ? @@ -31,7 +31,11 @@ <%= author.split('<').first %> <% end %>
<%= line.html_safe %>

<%= line.html_safe %>