From b3ecd136397a1ddb6e4ceb12ae4a26e69eebe151 Mon Sep 17 00:00:00 2001
From: Marc Bernard <59966492+mbtools@users.noreply.github.com>
Date: Mon, 17 Apr 2023 00:06:30 +0200
Subject: [PATCH] Improve copy&paste on diff page (#6218)
---
.../pages/zcl_abapgit_gui_page_diff.clas.abap | 18 ++++++++++-------
src/ui/zabapgit_js_common.w3mi.data.js | 20 ++++++++++---------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/ui/pages/zcl_abapgit_gui_page_diff.clas.abap b/src/ui/pages/zcl_abapgit_gui_page_diff.clas.abap
index d34be0bed..63428bf79 100644
--- a/src/ui/pages/zcl_abapgit_gui_page_diff.clas.abap
+++ b/src/ui/pages/zcl_abapgit_gui_page_diff.clas.abap
@@ -270,7 +270,7 @@ ENDCLASS.
-CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
+CLASS zcl_abapgit_gui_page_diff IMPLEMENTATION.
METHOD add_filter_sub_menu.
@@ -1094,6 +1094,8 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
+ " Note: CSS classes "new" and "old" are used to enable column-based copy to clipboard
+
" New line
lv_mark = ` `.
IF is_diff_line-result IS NOT INITIAL.
@@ -1107,7 +1109,7 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
ENDIF.
lv_new = |
| |
&& |{ lv_mark } | |
- && |{ is_diff_line-new } | |.
+ && |{ is_diff_line-new } | |.
" Old line
CLEAR lv_bg.
@@ -1123,7 +1125,7 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
ENDIF.
lv_old = | | |
&& |{ lv_mark } | |
- && |{ is_diff_line-old } | |.
+ && |{ is_diff_line-old } | |.
" render line, inverse sides if remote is newer
ri_html->add( '' ).
@@ -1161,6 +1163,8 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
+ " Note: CSS classes "new" and "old" are used to enable column-based copy to clipboard
+
" Release delayed subsequent update lines
IF is_diff_line-result <> zif_abapgit_definitions=>c_diff-update.
LOOP AT mt_delayed_lines ASSIGNING .
@@ -1168,7 +1172,7 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
ri_html->add( | | |
&& | | |
&& |- | |
- && |{ -old } | | ).
+ && |{ -old } | | ).
ri_html->add( '
' ).
ENDLOOP.
LOOP AT mt_delayed_lines ASSIGNING .
@@ -1176,7 +1180,7 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
ri_html->add( | | |
&& | | |
&& |+ | |
- && |{ -new } | | ).
+ && |{ -new } | | ).
ri_html->add( '' ).
ENDLOOP.
CLEAR mt_delayed_lines.
@@ -1190,12 +1194,12 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_DIFF IMPLEMENTATION.
ri_html->add( | | |
&& | | |
&& |+ | |
- && |{ is_diff_line-new } | | ).
+ && |{ is_diff_line-new } | | ).
WHEN zif_abapgit_definitions=>c_diff-delete.
ri_html->add( | | |
&& | | |
&& |- | |
- && |{ is_diff_line-old } | | ).
+ && |{ is_diff_line-old } | | ).
WHEN OTHERS. "none
ri_html->add( | | |
&& | | |
diff --git a/src/ui/zabapgit_js_common.w3mi.data.js b/src/ui/zabapgit_js_common.w3mi.data.js
index ad15d10e2..399ff334f 100644
--- a/src/ui/zabapgit_js_common.w3mi.data.js
+++ b/src/ui/zabapgit_js_common.w3mi.data.js
@@ -1200,20 +1200,22 @@ DiffColumnSelection.prototype.getSelectedText = function() {
} else {
var newline = "";
var realThis = this;
+ var copySide = "";
[].forEach.call(nodes, function(tr, i) {
var cellIdx = (i == 0 ? 0 : realThis.selectedColumnIdx);
if (tr.cells.length > cellIdx) {
var tdSelected = tr.cells[cellIdx];
- var tdLineNum = tr.cells[realThis.lineNumColumnIdx];
- // copy is interesting for remote code, don't copy lines which exist only locally
- if (i == 0 || tdLineNum.getAttribute("line-num") != "") {
+ // decide which side to copy based on first line of selection
+ if (i == 0) {
+ copySide = (tdSelected.classList.contains("new") ? "new" : "old" );
+ }
+ // copy is interesting only for one side of code, do not copy lines which exist on other side
+ if (i == 0 || copySide == "new" && !tdSelected.classList.contains("old") || copySide == "old" && !tdSelected.classList.contains("new")) {
text += newline + tdSelected.textContent;
// special processing for TD tag which sometimes contains newline
- // (expl: /src/ui/zabapgit_js_common.w3mi.data.js) so don't add newline again in that case.
+ // (expl: /src/ui/zabapgit_js_common.w3mi.data.js) so do not add newline again in that case.
var lastChar = tdSelected.textContent[tdSelected.textContent.length - 1];
-
if (lastChar == "\n") newline = "";
-
else newline = "\n";
}
}
@@ -1474,7 +1476,7 @@ LinkHints.prototype.handleKey = function(event) {
var hint = this.hintsMap[this.pendingPath];
- if (hint) { // we are there, we have a fully specified tooltip. Let's activate or yank it
+ if (hint) { // we are there, we have a fully specified tooltip. Let us activate or yank it
this.displayHints(false);
event.preventDefault();
if (this.yankModeActive) {
@@ -1484,7 +1486,7 @@ LinkHints.prototype.handleKey = function(event) {
this.hintActivate(hint);
}
} else {
- // we are not there yet, but let's filter the link so that only
+ // we are not there yet, but let us filter the link so that only
// the partially matched are shown
var visibleHints = this.filterHints();
if (!visibleHints) {
@@ -2480,4 +2482,4 @@ function toggleSticky() {
} else {
header.classList.remove(stickyClass);
}
-}
+}
\ No newline at end of file