Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-10-06 08:27:14 -0400
committerMichael Keppler2019-10-09 02:38:13 -0400
commitd83e193d8e917adf3c1ee2d88a26a8ef9a27f27f (patch)
tree5a9505be5cd0d6022a7437cc1ce475b584b45c28 /org.eclipse.egit.ui
parenteeee41ae45cee160b4aa5bc64c4288a1249f9bb1 (diff)
downloadegit-d83e193d8e917adf3c1ee2d88a26a8ef9a27f27f.tar.gz
egit-d83e193d8e917adf3c1ee2d88a26a8ef9a27f27f.tar.xz
egit-d83e193d8e917adf3c1ee2d88a26a8ef9a27f27f.zip
[history] Scrolling in the commit/diff viewer
Scroll the combined commit/diff viewer in the git history view when the caret position changes. Bug: 463939 Change-Id: Ie333b04ccaeb7809ceca732df9a805946ab4a130 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index da0726f62..fb649fb93 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -167,6 +167,7 @@ import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@@ -174,6 +175,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.team.ui.history.HistoryPage;
import org.eclipse.team.ui.history.IHistoryView;
@@ -1503,6 +1505,14 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
});
+ StyledText commentWidget = commentViewer.getTextWidget();
+ commentWidget.addCaretListener(event -> {
+ Point location = commentWidget
+ .getLocationAtOffset(event.caretOffset);
+ scrollCommentAndDiff(location,
+ commentWidget.getLineHeight(event.caretOffset));
+ });
+
commentAndDiffComposite.setBackground(commentViewer.getControl()
.getBackground());
@@ -1610,6 +1620,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
diffWidget.setMenu(contextMenu.createContextMenu(diffWidget));
diffWidget.addDisposeListener(e -> showWhitespaceAction.dispose());
+ diffWidget.addCaretListener(event -> {
+ Point location = diffWidget.getLocationAtOffset(event.caretOffset);
+ location.y += diffViewer.getControl().getLocation().y;
+ scrollCommentAndDiff(location,
+ diffWidget.getLineHeight(event.caretOffset));
+ });
+
setWrap(store
.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));
@@ -1678,6 +1695,45 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
GitTraceLocation.HISTORYVIEW.getLocation());
}
+ private void scrollCommentAndDiff(Point location, int lineHeight) {
+ Rectangle size = commentAndDiffScrolledComposite.getBounds();
+ ScrollBar bar = commentAndDiffScrolledComposite.getVerticalBar();
+ if (bar != null && bar.isVisible()) {
+ size.width = Math.max(0, size.width - bar.getSize().x);
+ }
+ bar = commentAndDiffScrolledComposite.getHorizontalBar();
+ if (bar != null && bar.isVisible()) {
+ size.height = Math.max(0, size.height - bar.getSize().y);
+ }
+ Point topLeft = commentAndDiffScrolledComposite.getOrigin();
+ size.x = topLeft.x;
+ size.y = topLeft.y;
+ if (location.y >= size.y) {
+ location.y += lineHeight;
+ }
+ if (!size.contains(location)) {
+ int left = size.x;
+ int top = size.y;
+ // Use the same scrolling as in StyledText: scroll horizontally at
+ // least by width / 4. Otherwise horizontal scrolling is slow.
+ int minScroll = size.width / 4;
+ if (location.x < left) {
+ left = Math.max(0,
+ left - Math.max(left - location.x, minScroll));
+ } else if (location.x > left + size.width) {
+ int maxWidth = commentAndDiffComposite.getSize().x;
+ int right = Math.max(location.x, left + size.width + minScroll);
+ left = Math.min(right, maxWidth) - size.width;
+ }
+ if (location.y < top) {
+ top = location.y;
+ } else if (location.y > top + size.height) {
+ top = location.y - size.height;
+ }
+ commentAndDiffScrolledComposite.setOrigin(left, top);
+ }
+ }
+
private void trackFocus(Control control) {
if (control != null) {
focusTracker.addToFocusTracking(control);

Back to the top