This is an automated email from the ASF dual-hosted git repository.
mattcasters pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new a4494c9361 Scroll the text diff with the mouse wheel when the file was
added, fixes #8928 (#9188)
a4494c9361 is described below
commit a4494c9361d48eca52bfc56fb910fc4da61b71e7
Author: Bart Maertens <[email protected]>
AuthorDate: Sun Nov 1 14:28:32 2026 +0100
Scroll the text diff with the mouse wheel when the file was added, fixes
#8928 (#9188)
---
.../java/org/apache/hop/git/TextDiffDialog.java | 7 +-
.../org/apache/hop/git/TextDiffDialogUiTest.java | 111 +++++++++++++++++++++
2 files changed, 116 insertions(+), 2 deletions(-)
diff --git
a/plugins/misc/git/src/main/java/org/apache/hop/git/TextDiffDialog.java
b/plugins/misc/git/src/main/java/org/apache/hop/git/TextDiffDialog.java
index 30d5deef73..1a98f0fa7a 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/TextDiffDialog.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/TextDiffDialog.java
@@ -306,9 +306,12 @@ public class TextDiffDialog extends Dialog {
}
syncingVertical = true;
try {
- int lineHeight = wLeftEditor.getLineHeight();
+ // An empty editor ignores setTopPixel() and stays at 0, so scroll from
the side with content
+ // when the file was added or deleted
+ StyledText editor = wLeftEditor.getCharCount() > 0 ? wLeftEditor :
wRightEditor;
+ int lineHeight = editor.getLineHeight();
int delta = -event.count * lineHeight;
- int newTopPixel = Math.max(0, wLeftEditor.getTopPixel() + delta);
+ int newTopPixel = Math.max(0, editor.getTopPixel() + delta);
this.leftTop = newTopPixel;
this.rightTop = newTopPixel;
diff --git
a/plugins/misc/git/src/test/java/org/apache/hop/git/TextDiffDialogUiTest.java
b/plugins/misc/git/src/test/java/org/apache/hop/git/TextDiffDialogUiTest.java
new file mode 100644
index 0000000000..f4bffc24d0
--- /dev/null
+++
b/plugins/misc/git/src/test/java/org/apache/hop/git/TextDiffDialogUiTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hop.git;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.hop.ui.testing.SwtBotTestBase;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.IntResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+/** The mouse wheel scrolls the text diff, also when one side of it is empty.
*/
+@Tag("uitest")
+class TextDiffDialogUiTest extends SwtBotTestBase {
+ private static final String TITLE = "Text diff test";
+ private static final int WHEEL_STEPS = 10;
+
+ @Test
+ @DisplayName("the wheel scrolls a file the commit added")
+ void wheelScrollsAddedFile() {
+ assertWheelScrolls(null, lines(200), 1);
+ }
+
+ @Test
+ @DisplayName("the wheel scrolls a file the commit deleted")
+ void wheelScrollsDeletedFile() {
+ assertWheelScrolls(lines(200), null, 0);
+ }
+
+ @Test
+ @DisplayName("the wheel scrolls both sides of a modified file")
+ void wheelScrollsModifiedFile() {
+ assertWheelScrolls(lines(200), lines(200) + "added\n", 0);
+ assertWheelScrolls(lines(200), lines(200) + "added\n", 1);
+ }
+
+ /**
+ * Opens the dialog, turns the wheel over one of its editors and checks the
editors with content
+ * moved down one line per step.
+ */
+ private void assertWheelScrolls(String left, String right, int editorIndex) {
+ withDialog(
+ parent -> {
+ TextDiffDialog dialog = new TextDiffDialog(parent, left, right);
+ dialog.setTitle(TITLE);
+ dialog.open();
+ },
+ swtBot -> {
+ // Close the shell rather than pressing OK, which would save the
dialog settings
+ SWTBotShell shell = swtBot.shell(TITLE);
+ SWTBot bot = shell.bot();
+ StyledText leftEditor = bot.styledText(0).widget;
+ StyledText rightEditor = bot.styledText(1).widget;
+ StyledText wheelEditor = editorIndex == 0 ? leftEditor : rightEditor;
+
+ int lineHeight = onUi(wheelEditor::getLineHeight);
+ for (int i = 0; i < WHEEL_STEPS; i++) {
+ UIThreadRunnable.syncExec(
+ () -> {
+ Event event = new Event();
+ event.count = -1;
+ wheelEditor.notifyListeners(SWT.MouseVerticalWheel, event);
+ });
+ }
+
+ int expected = WHEEL_STEPS * lineHeight;
+ if (left != null) {
+ assertEquals(expected, onUi(leftEditor::getTopPixel), "left top
pixel");
+ }
+ if (right != null) {
+ assertEquals(expected, onUi(rightEditor::getTopPixel), "right top
pixel");
+ }
+ shell.close();
+ });
+ }
+
+ private static int onUi(IntResult result) {
+ return UIThreadRunnable.syncExec(result);
+ }
+
+ private static String lines(int count) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 1; i <= count; i++) {
+ builder.append("line ").append(i).append('\n');
+ }
+ return builder.toString();
+ }
+}