mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Bug 331629 - [disassembly] pageUp/pageDown scrolling jumps over unknown sections unexpectedly
In cooperation with Kirk Beitz
This commit is contained in:
parent
6945632db0
commit
7f65962244
2 changed files with 76 additions and 10 deletions
|
@ -658,7 +658,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
|
|||
parent.setLayout(layout);
|
||||
fVerticalRuler = createVerticalRuler();
|
||||
int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
|
||||
fViewer = new DisassemblyViewer(parent, fVerticalRuler, getOverviewRuler(), true, styles);
|
||||
fViewer = new DisassemblyViewer(this, parent, fVerticalRuler, getOverviewRuler(), true, styles);
|
||||
SourceViewerConfiguration sourceViewerConfig = new DisassemblyViewerConfiguration(this);
|
||||
fViewer.addTextPresentationListener(this);
|
||||
fViewer.configure(sourceViewerConfig);
|
||||
|
@ -1439,15 +1439,14 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
|
|||
fBackend.gotoSymbol(symbol);
|
||||
}
|
||||
|
||||
private void gotoPosition(Position pos, boolean select) {
|
||||
private void gotoPosition(Position pos, boolean onTop) {
|
||||
if (fViewer == null) {
|
||||
return;
|
||||
}
|
||||
setFocusPosition(pos);
|
||||
fViewer.setSelectedRange(pos.offset, select ? Math.max(pos.length-1, 0) : 0);
|
||||
fViewer.setSelectedRange(pos.offset, 0);
|
||||
int revealOffset = pos.offset;
|
||||
boolean onTop = false;
|
||||
if (/* !fUpdateBeforeFocus && */ pos.offset > 0) {
|
||||
if (pos.offset > 0) {
|
||||
try {
|
||||
AddressRangePosition previousPos = fDocument.getModelPosition(pos.offset - 1);
|
||||
if (previousPos instanceof LabelPosition) {
|
||||
|
@ -3086,4 +3085,54 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
|
|||
private static boolean isGuiThread() {
|
||||
return Display.getCurrent() != null;
|
||||
}
|
||||
|
||||
boolean keyScroll(int keyCode) {
|
||||
BigInteger topAddress = getTopAddress();
|
||||
BigInteger bottomAddress = getBottomAddress();
|
||||
BigInteger addressRange = bottomAddress.subtract(topAddress);
|
||||
StyledText styledText = fViewer.getTextWidget();
|
||||
Rectangle clientArea = styledText.getClientArea();
|
||||
int lineRange;
|
||||
if (SWT.PAGE_UP == keyCode || SWT.PAGE_DOWN == keyCode) {
|
||||
lineRange = clientArea.height / styledText.getLineHeight();
|
||||
} else {
|
||||
lineRange = 1;
|
||||
}
|
||||
addressRange = addressRange.min(BigInteger.valueOf(lineRange * fDocument.getMeanSizeOfInstructions()));
|
||||
BigInteger scrollToAddress;
|
||||
switch (keyCode) {
|
||||
case SWT.PAGE_UP:
|
||||
case SWT.ARROW_UP:
|
||||
scrollToAddress = topAddress.subtract(addressRange).max(fStartAddress);
|
||||
break;
|
||||
case SWT.PAGE_DOWN:
|
||||
scrollToAddress = topAddress.add(addressRange).min(bottomAddress);
|
||||
break;
|
||||
case SWT.ARROW_DOWN:
|
||||
scrollToAddress = bottomAddress.add(addressRange).min(bottomAddress);
|
||||
break;
|
||||
default:
|
||||
assert false; // invalid keycode passed
|
||||
scrollToAddress = fFocusAddress;
|
||||
}
|
||||
AddressRangePosition pos = getPositionOfAddress(scrollToAddress);
|
||||
if (pos != null && pos.fValid) {
|
||||
if (SWT.ARROW_DOWN == keyCode && pos.fAddressOffset.compareTo(bottomAddress) <= 0
|
||||
|| SWT.ARROW_UP == keyCode && pos.fAddressOffset.compareTo(topAddress) >= 0) {
|
||||
return false;
|
||||
}
|
||||
gotoPosition(pos, SWT.ARROW_DOWN != keyCode);
|
||||
} else {
|
||||
gotoAddress(scrollToAddress);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private BigInteger getBottomAddress() {
|
||||
BigInteger bottomAddress = getAddressOfLine(fViewer.getBottomIndex());
|
||||
if (bottomAddress == null || bottomAddress.equals(PC_UNKNOWN)) {
|
||||
bottomAddress = fEndAddress.subtract(BigInteger.ONE);
|
||||
}
|
||||
return bottomAddress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Wind River Systems and others.
|
||||
* Copyright (c) 2007, 2011 Wind River Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -24,12 +24,15 @@ import org.eclipse.jface.text.source.IOverviewRuler;
|
|||
import org.eclipse.jface.text.source.IVerticalRuler;
|
||||
import org.eclipse.jface.text.source.IVerticalRulerColumn;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.custom.VerifyKeyListener;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
import org.eclipse.swt.dnd.TextTransfer;
|
||||
import org.eclipse.swt.dnd.Transfer;
|
||||
import org.eclipse.swt.events.ControlEvent;
|
||||
import org.eclipse.swt.events.ControlListener;
|
||||
import org.eclipse.swt.events.VerifyEvent;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
@ -52,13 +55,14 @@ public class DisassemblyViewer extends SourceViewer {
|
|||
public void controlMoved(ControlEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean fUserTriggeredScrolling;
|
||||
private int fCachedLastTopPixel;
|
||||
|
||||
// extra resize listener to workaround bug 171018
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171018
|
||||
private ResizeListener fResizeListener;
|
||||
private DisassemblyPart fPart;
|
||||
|
||||
/**
|
||||
* Create a new DisassemblyViewer.
|
||||
|
@ -68,8 +72,9 @@ public class DisassemblyViewer extends SourceViewer {
|
|||
* @param showsAnnotationOverview
|
||||
* @param styles
|
||||
*/
|
||||
public DisassemblyViewer(Composite parent, IVerticalRuler ruler, IOverviewRuler overviewRuler, boolean showsAnnotationOverview, int styles) {
|
||||
public DisassemblyViewer(DisassemblyPart part, Composite parent, IVerticalRuler ruler, IOverviewRuler overviewRuler, boolean showsAnnotationOverview, int styles) {
|
||||
super(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
|
||||
fPart = part;
|
||||
// always readonly
|
||||
setEditable(false);
|
||||
}
|
||||
|
@ -80,8 +85,20 @@ public class DisassemblyViewer extends SourceViewer {
|
|||
@Override
|
||||
protected void createControl(Composite parent, int styles) {
|
||||
super.createControl(parent, styles);
|
||||
StyledText textWidget = getTextWidget();
|
||||
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=171018
|
||||
getTextWidget().addControlListener(fResizeListener= new ResizeListener());
|
||||
textWidget.addControlListener(fResizeListener= new ResizeListener());
|
||||
textWidget.addVerifyKeyListener(new VerifyKeyListener() {
|
||||
public void verifyKey(VerifyEvent event) {
|
||||
switch (event.keyCode) {
|
||||
case SWT.PAGE_UP:
|
||||
case SWT.PAGE_DOWN:
|
||||
case SWT.ARROW_UP:
|
||||
case SWT.ARROW_DOWN:
|
||||
event.doit = !fPart.keyScroll(event.keyCode);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -231,7 +248,7 @@ public class DisassemblyViewer extends SourceViewer {
|
|||
if (!onTop && focusLine >= top && focusLine <= bottom - bottomBuffer) {
|
||||
// do not scroll at all as it is already visible
|
||||
} else {
|
||||
if (focusLine > bottom - bottomBuffer && focusLine <= bottom) {
|
||||
if (!onTop && focusLine > bottom - bottomBuffer && focusLine <= bottom) {
|
||||
// focusLine is already in bottom bufferZone
|
||||
// scroll to top of bottom bufferzone - for smooth down-scrolling
|
||||
int scrollDelta = focusLine - (bottom - bottomBuffer);
|
||||
|
|
Loading…
Add table
Reference in a new issue