diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponent.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponent.java index 0a0045a250..85b2362538 100644 --- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponent.java +++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponent.java @@ -762,7 +762,7 @@ public class ByteViewerComponent extends FieldPanel // if the selection ends on a separator line, go back to the end of the previous line if (indexMap.isBlockSeparatorIndex(lineIndex)) { lineIndex = lineIndex.subtract(BigInteger.ONE); - fieldNum = fieldFactories.length - 1; // set to end of line factory + fieldNum = fieldFactories.length; // set to end of line factory } // if the selection is before the characters in this field, the selection doesn't include diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java index e4c4e4e536..12bc914e6b 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java @@ -1836,7 +1836,6 @@ public class FieldPanel extends JPanel private int mouseDownY; private boolean didDrag; private int timerScrollAmount; - private FieldLocation timerPoint; MouseHandler() { scrollTimer = new Timer(100, this); @@ -1850,13 +1849,15 @@ public class FieldPanel extends JPanel public void actionPerformed(ActionEvent e) { try { scrollView(timerScrollAmount); - if (timerScrollAmount > 0) { - timerPoint.setIndex(layouts.get(layouts.size() - 1).getIndex()); + FieldLocation selectToLocation = new FieldLocation(); + if (timerScrollAmount >= 0) { + BigInteger lastIndex = layouts.get(layouts.size() - 1).getIndex(); + selectToLocation.setIndex(lastIndex.add(BigInteger.ONE)); } else { - timerPoint.setIndex(layouts.get(0).getIndex()); + selectToLocation.setIndex(layouts.get(0).getIndex()); } - selectionHandler.updateSelectionSequence(timerPoint); + selectionHandler.updateSelectionSequence(selectToLocation); } catch (Exception ex) { // don't care @@ -1912,15 +1913,23 @@ public class FieldPanel extends JPanel if (((Math.abs(x - mouseDownX) > 3) || (Math.abs(y - mouseDownY) > 3))) { didDrag = true; if (selectionHandler.isInProgress()) { - if (y < 0 || y > getHeight()) { + if (y < 0 || y >= getHeight()) { timerScrollAmount = y < 0 ? y : y - getHeight(); - timerPoint = new FieldLocation(cursorPosition); scrollTimer.start(); } else { scrollTimer.stop(); cursorHandler.setCursorPos(x, y, null); // null means don't notify listeners - selectionHandler.updateSelectionSequence(cursorPosition); + FieldLocation selectionEnd = cursorPosition; + // if the mouse is to the right of the last field, make the selection + // include the last field + Layout layout = getLayoutModel().getLayout(selectionEnd.getIndex()); + int width = layout.getCompressableWidth(); + if (x > width) { + selectionEnd = + new FieldLocation(selectionEnd.getIndex().add(BigInteger.ONE)); + } + selectionHandler.updateSelectionSequence(selectionEnd); repaint(); } } @@ -2199,11 +2208,7 @@ public class FieldPanel extends JPanel currentField = null; // delegate to the appropriate layout to do the work Layout layout = findLayoutAt(y); - if (layout == null) { - x = 0; - y = 0; - layout = findLayoutAt(y); - } + if (layout != null) { FieldLocation newCursorPosition = new FieldLocation(); lastX = layout.setCursor(newCursorPosition, x, y);