Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3308 - Structure Editor - fixed bug that caused wrong cell to be edited after using the arrow keys

dragonmacher340bea8a30d9
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
index 04f9cb7d7c..b0c71433a9 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
@@ -179,12 +179,12 @@ public abstract class CompositeEditorPanel extends JPanel
table.addPropertyChangeListener("tableCellEditor", evt -> {
TableCellEditor fieldEditor = (TableCellEditor) evt.getNewValue();
if (fieldEditor == null) {
- // Ending cell edit.
- SwingUtilities.invokeLater(() -> model.endEditingField());
+ // Ending cell edit
+ Swing.runLater(() -> model.endEditingField());
}
else {
- // Starting cell edit.
- SwingUtilities.invokeLater(() -> {
+ // Starting cell edit
+ Swing.runLater(() -> {
int editingRow = table.getEditingRow();
if (editingRow < 0) {
return;
@@ -255,11 +255,11 @@ public abstract class CompositeEditorPanel extends JPanel
public void moveCellEditor(final int direction, final String value) {
stopCellEditing();
- // Note: We perform an invokeLater here due to focus dependencies (SCR 6915). When we call
+ // Note: We run this later due to focus dependencies (SCR 6915). When we call
// stopCellEditing() this will trigger a focusLost() event, which itself happens in
- // an invokeLater(). If we do not trigger the moving of the cell editor after that focus
+ // a Swing.runLater(). If we do not trigger the moving of the cell editor after that focus
// event, then the focusLost() will trigger our new edit to be cancelled.
- SwingUtilities.invokeLater(() -> doMoveCellEditor(direction, value));
+ Swing.runLater(() -> doMoveCellEditor(direction, value));
}
private void doMoveCellEditor(int direction, String value) {
@@ -457,8 +457,10 @@ public abstract class CompositeEditorPanel extends JPanel
}
/**
- * Puts the next editable cell into edit mode.
- * @return true if there was a table cell that could be edited.
+ * Puts the next editable cell into edit mode
+ *
+ * @param currentRow the current row
+ * @return true if there was a table cell that could be edited
*/
protected boolean editNextField(int currentRow) {
if (locateNextEditField(currentRow)) {
@@ -479,9 +481,6 @@ public abstract class CompositeEditorPanel extends JPanel
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModelListener#lockStateChanged(int)
- */
public void lockStateChanged(int type) {
// no-op
}
@@ -585,7 +584,15 @@ public abstract class CompositeEditorPanel extends JPanel
if (e.getValueIsAdjusting()) {
return;
}
- model.setColumn(e.getFirstIndex());
+
+ TableColumnModel cm = table.getColumnModel();
+ int[] selected = cm.getSelectedColumns();
+ if (selected.length == 1) {
+ model.setColumn(selected[0]);
+ }
+ else {
+ model.setColumn(-1);
+ }
});
JPanel tablePanel = new JPanel(new BorderLayout());
@@ -870,23 +877,14 @@ public abstract class CompositeEditorPanel extends JPanel
return new DataTypeTransferable(dt);
}
- /**
- * Return true if it is OK to drop the transferable at the location
- * specified by the event.
- * Data Types can only be dropped on undefined bytes in locked state
- * and only if they fit there.
- *
- * @param e event that has current state of drag and drop operation
- * @param obj the DataType being dropped
- */
@Override
public boolean isDropOk(DropTargetDragEvent e) {
return true;
}
/**
- * Add the object to the droppable component. The DragSrcAdapter
- * calls this method from its drop() method.
+ * Add the object to the droppable component. The DragSrcAdapter calls this method from its
+ * drop() method
*
* @param obj Transferable object that is to be dropped.
* @param e has current state of drop operation
@@ -913,13 +911,11 @@ public abstract class CompositeEditorPanel extends JPanel
}
/**
- * Add the object to the droppable component. The DragSrcAdapter
- * calls this method from its drop() method.
+ * Add the object to the droppable component. The DragSrcAdapter calls this method from its
+ * drop() method.
*
- * @param obj Transferable object that is to be dropped.
- * @param e has current state of drop operation
- * @param f represents the opaque concept of a data format as
- * would appear on a clipboard, during drag and drop.
+ * @param p the point of insert
+ * @param dt the data type to insert
*/
public void insertAtPoint(Point p, DataType dt) {
endFieldEditing(); // Make sure a field isn't being edited.
@@ -934,13 +930,11 @@ public abstract class CompositeEditorPanel extends JPanel
}
/**
- * Add the object to the droppable component. The DragSrcAdapter
- * calls this method from its drop() method.
- *
- * @param obj Transferable object that is to be dropped.
- * @param e has current state of drop operation
- * @param f represents the opaque concept of a data format as
- * would appear on a clipboard, during drag and drop.
+ * Add the object to the droppable component. The DragSrcAdapter calls this method from its
+ * drop() method
+ *
+ * @param p the point of insert
+ * @param dt the data type to insert
*/
public void addAtPoint(Point p, DataType dt) {
endFieldEditing(); // Make sure a field isn't being edited.
@@ -1305,7 +1299,7 @@ public abstract class CompositeEditorPanel extends JPanel
}
};
- dataTypeChooserButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
+ dataTypeChooserButton.addActionListener(e -> Swing.runLater(() -> {
DataTypeManagerService service = tool.getService(DataTypeManagerService.class);
DataType dataType = service.getDataType((String) null);
if (dataType != null) {
@@ -1503,7 +1497,7 @@ public abstract class CompositeEditorPanel extends JPanel
// overridden because the editor component was not being given focus
public Component prepareEditor(TableCellEditor editor, int row, int column) {
final Component component = super.prepareEditor(editor, row, column);
- SwingUtilities.invokeLater(() -> component.requestFocus());
+ Swing.runLater(() -> component.requestFocus());
return component;
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java
index 108e66dd99..b3538adb40 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java
@@ -29,7 +29,7 @@ import ghidra.util.InvalidNameException;
import ghidra.util.Msg;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.DuplicateNameException;
-import ghidra.util.task.TaskMonitorAdapter;
+import ghidra.util.task.TaskMonitor;
class CompositeViewerModel extends AbstractTableModel implements DataTypeManagerChangeListener {
@@ -81,12 +81,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
protected CompositeEditorProvider provider;
protected boolean showHexNumbers = false;
- /**
- * Constructor for a model for handling a data structure.
- *
- * @param dataType the composite data type to be viewed.
- * @param category the category for the composite data type.
- */
CompositeViewerModel(CompositeEditorProvider provider) {
this.provider = provider;
selection = new FieldSelection();
@@ -211,8 +205,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
* and category/dataType changes no longer need to be listened for.
* It can also be called to unload the current composite before loading
* a new composite data type.
- *
- * @param dataType the new structure to be edited.
*/
void unload() {
DataTypeManager originalDTM =
@@ -239,7 +231,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
/**
* Resolves the indicated data type against the working copy in the
* viewer's data type manager.
- * @param dataType
+ * @param dataType the data type
* @return the working copy of the data type.
*/
DataType resolve(DataType dataType) {
@@ -312,21 +304,24 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns the original name of the CompositeDataType being viewed.
+ * Returns the original name of the CompositeDataType being viewed
+ * @return the name
*/
public final String getOriginalDataTypeName() {
return originalDataTypePath.getDataTypeName();
}
/**
- * Return the data type manager for the composite data type being viewed.
+ * Return the data type manager for the composite data type being viewed
+ * @return the manager
*/
protected DataTypeManager getOriginalDataTypeManager() {
return (originalComposite != null) ? originalComposite.getDataTypeManager() : null;
}
/**
- * Return the original category for the composite data type being viewed.
+ * Return the original category for the composite data type being viewed
+ * @return the category
*/
public final Category getOriginalCategory() {
DataTypeManager originalDTM = getOriginalDataTypeManager();
@@ -340,7 +335,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the path of the data category for the structure being viewed.
+ * Return the path of the data category for the structure being viewed
+ * @return the path
*/
public final CategoryPath getOriginalCategoryPath() {
if (originalDataTypePath != null) {
@@ -350,7 +346,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the description for the structure being viewed.
+ * Return the description for the structure being viewed
+ * @return the description
*/
public String getDescription() {
String desc = null;
@@ -361,7 +358,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the size of the structure being viewed in bytes.
+ * Return the size of the structure being viewed in bytes
+ * @return this size
*/
public int getLength() {
if (viewComposite != null && !viewComposite.isNotYetDefined()) {
@@ -371,8 +369,9 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the size of the structure being viewed in bytes as a hex or decimal string
- * depending on the model's current display setting for numbers.
+ * Return the size of the structure being viewed in bytes as a hex or decimal string
+ * depending on the model's current display setting for numbers
+ * @return the length
*/
public String getLengthAsString() {
int length = getLength();
@@ -380,14 +379,16 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the data type name of the structure being viewed.
+ * Return the data type name of the structure being viewed
+ * @return the name
*/
public String getCompositeName() {
return (viewComposite != null) ? viewComposite.getDisplayName() : "";
}
/**
- * Return the size of the left margin for the component viewing area.
+ * Return the size of the left margin for the component viewing area
+ * @return the margin
*/
public int getLeftMargin() {
return leftMargin;
@@ -405,10 +406,11 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return a header name for the indicated field (column).
+ * Return a header name for the indicated field (column)
*
* @param columnIndex the index number indicating the component field (column)
- * to get the header for.
+ * to get the header for
+ * @return the name
*/
public String getFieldName(int columnIndex) {
if (columnIndex < 0 || columnIndex > getColumnCount()) {
@@ -419,21 +421,22 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * returns whether or not a particular component row and field in this
- * structure is an editable type of cell. However the cell still
- * may not be editable currently. To check if the cell can actually be
- * edited call isCellEditable().
+ * Returns whether or not a particular component row and field in this
+ * structure is an editable type of cell. However the cell still
+ * may not be editable currently. To check if the cell can actually be
+ * edited call isCellEditable().
*
- * @param rowIndex the row index of the component.
- * @param columnIndex the index for the field of the component.
+ * @param rowIndex the row index of the component
+ * @param columnIndex the index for the field of the component
+ * @return true if editable
*/
boolean isEditTypeOfCell(int rowIndex, int columnIndex) {
return false; // User can't edit the cell.
}
/**
- * Returns whether or not a particular component row and field in this
- * structure is editable
+ * Returns whether or not a particular component row and field in this
+ * structure is editable
*
* @param rowIndex index for the row (component within this structure).
* @param columnIndex index for the column (field of the component within
@@ -445,7 +448,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Gets the display offset of the component field at the specified column index.
+ * Gets the display offset of the component field at the specified column index
*
* @param columnIndex the field index within the component.
* @return the offset in pixels of the component field.
@@ -456,14 +459,15 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Gets the component display field widths.
+ * Gets the component display field widths
+ * @return the offsets
*/
int[] getFieldOffsets() {
return columnOffsets;
}
/**
- * Adjusts the offsets of all component fields.
+ * Adjusts the offsets of all component fields
*/
protected void adjustOffsets() {
int offset = leftMargin;
@@ -508,10 +512,11 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Sets the component display width for the field.
+ * Sets the component display width for the field
*
- * @param width the width of the component field.
- * @param columnIndex the field index within the component.
+ * @param width the width of the component field
+ * @param columnIndex the field index within the component
+ * @return true if the width changed
*/
boolean setFieldWidth(int width, int columnIndex) {
if (columnIndex >= 0 && columnIndex < getColumnCount()) {
@@ -535,9 +540,10 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Sets the component display field widths.
+ * Sets the component display field widths
*
- * @param widths an array indicating each component field's width.
+ * @param widths an array indicating each component field's width
+ * @return true
*/
boolean setFieldWidths(int[] widths) {
int numCols = getColumnCount();
@@ -578,13 +584,13 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Return the nth component for the structure being viewed. Since the number of rows
- * can exceed the number of components defined within the composite
- * ({@link Composite#getNumComponents()}) this method will return null for a blank
- * row or a flexible array component which may appear as an additional rows for
- * structures.
- * @param rowIndex the index of the component to return.
- * First component is index of 0.
+ * Return the nth component for the structure being viewed. Since the number of rows
+ * can exceed the number of components defined within the composite
+ * ({@link Composite#getNumComponents()}) this method will return null for a blank
+ * row or a flexible array component which may appear as an additional rows for
+ * structures.
+ * @param rowIndex the index of the component to return. First component is index of 0.
+ * @return the component
*/
public DataTypeComponent getComponent(int rowIndex) {
if (rowIndex >= 0 && rowIndex < getNumComponents()) {
@@ -613,14 +619,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
return getColumnCount();
}
- /**
- * Returns an attribute value for the cell at <I>columnIndex</I>
- * and <I>rowIndex</I>.
- *
- * @param rowIndex the row whose value is to be looked up
- * @param columnIndex the column whose value is to be looked up
- * @return the value Object at the specified cell
- */
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
@@ -671,14 +669,16 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns the current dataType name (Structure or Union) as a string.
+ * Returns the current dataType name (Structure or Union) as a string
+ * @return the name
*/
protected String getTypeName() {
return "Composite Data Type";
}
/**
- * Returns the current status string.
+ * Returns the current status string
+ * @return the status
*/
public String getStatus() {
return status;
@@ -741,28 +741,32 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Adds a CompositeViewerModelListener to be notified when model changes occur.
+ * Adds a CompositeViewerModelListener to be notified when model changes occur
+ * @param listener the listener
*/
public void addCompositeViewerModelListener(CompositeViewerModelListener listener) {
modelListeners.add(listener);
}
/**
- * Removes a CompositeViewerModelListener that was being notified when model changes occur.
+ * Removes a CompositeViewerModelListener that was being notified when model changes occur
+ * @param listener the listener
*/
public void removeCompositeViewerModelListener(CompositeViewerModelListener listener) {
modelListeners.remove(listener);
}
/**
- * Adds an OriginalCompositeListener to be notified when changes occur.
+ * Adds an OriginalCompositeListener to be notified when changes occur
+ * @param listener the listener
*/
public void addOriginalCompositeListener(OriginalCompositeListener listener) {
originalListeners.add(listener);
}
/**
- * Removes an OriginalCompositeListener that was being notified when changes occur.
+ * Removes an OriginalCompositeListener that was being notified when changes occur
+ * @param listener the listener
*/
public void removeOriginalCompositeListener(OriginalCompositeListener listener) {
originalListeners.remove(listener);
@@ -904,7 +908,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
viewDTM.createCategory(parent);
Category newCat = viewDTM.getCategory(parent);
try {
- newCat.moveCategory(oldCat, TaskMonitorAdapter.DUMMY_MONITOR);
+ newCat.moveCategory(oldCat, TaskMonitor.DUMMY);
}
catch (DuplicateNameException e) {
Msg.error(this, "Unexpected Exception: " + e.getMessage(), e);
@@ -938,7 +942,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
originalDataTypePath.getDataTypeName() + "\".";
setStatus(msg, true);
}
- viewDTM.remove(dt, TaskMonitorAdapter.DUMMY_MONITOR);
+ viewDTM.remove(dt, TaskMonitor.DUMMY);
// If a datatype we are using is removed, change it to undefined data types.
fireTableDataChanged();
componentDataChanged();
@@ -1161,25 +1165,25 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
return false;
}
- // **********************************************************************
- // * METHODS FOR THE SELECTION
- // **********************************************************************
/**
- * Returns a copy of the model's current field selection.
+ * Returns a copy of the model's current field selection
+ * @return the selection
*/
public FieldSelection getSelection() {
return new FieldSelection(this.selection);
}
/**
- * Returns true if the GUI has a table row selected.
+ * Returns true if the GUI has a table row selected
+ * @return true if there is a selection
*/
public boolean hasSelection() {
return (selection.getNumRanges() > 0);
}
/**
- * Returns true if the GUI has a component row selected.
+ * Returns true if the GUI has a component row selected
+ * @return true if there is a selection
*/
public boolean hasComponentSelection() {
return ((selection.getNumRanges() > 0) &&
@@ -1187,8 +1191,10 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns the number of rows currently selected.
- * <br> Note: In unlocked mode this can include the additional blank line.
+ * Returns the number of rows currently selected.
+ *
+ * <p>Note: In unlocked mode this can include the additional blank line.
+ * @return the selected row count
*/
public int getNumSelectedRows() {
int numRanges = this.selection.getNumRanges();
@@ -1202,8 +1208,10 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns the number of component rows currently selected.
- * <br> Note: This only includes rows that are actually components.
+ * Returns the number of component rows currently selected.
+ *
+ * <p>Note: This only includes rows that are actually components.
+ * @return the selected row count
*/
public int getNumSelectedComponentRows() {
FieldSelection tmpSelection = new FieldSelection();
@@ -1220,15 +1228,16 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns true if the component list selection is contiguous.
+ * Returns true if the component list selection is contiguous
+ * @return true if contiguous
*/
public boolean isContiguousSelection() {
return (selection.getNumRanges() == 1);
}
/**
- * Returns true if the current single row selection corresponds to
- * a flexible array component.
+ * Returns true if the current single row selection corresponds to a flexible array component
+ * @return true if the current single row selection corresponds to a flexible array component
*/
public boolean isFlexibleArraySelection() {
if (!isSingleRowSelection()) {
@@ -1241,7 +1250,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns true if the component list selection is a single component.
+ * Returns true if the component list selection is a single component
+ * @return true if the component list selection is a single component
*/
public boolean isSingleComponentRowSelection() {
if (!isSingleRowSelection()) {
@@ -1253,7 +1263,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns true if the selection is a single row.
+ * Returns true if the selection is a single row
+ * @return true if the selection is a single row
*/
public boolean isSingleRowSelection() {
if (selection.getNumRanges() != 1) {
@@ -1264,8 +1275,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns true if the list selection is contiguous and only contains
- * component rows.
+ * Returns true if the list selection is contiguous and only contains component rows
+ * @return true if the list selection is contiguous and only contains component rows
*/
public boolean isContiguousComponentSelection() {
return ((selection.getNumRanges() == 1) &&
@@ -1273,7 +1284,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Get an array of the indices for all the selected rows.
+ * Get an array of the indices for all the selected rows
+ * @return the selected rows
*/
public int[] getSelectedRows() {
int[] selectedRows = new int[getNumSelectedRows()];
@@ -1290,7 +1302,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Get an array of the row indices for all the selected components.
+ * Get an array of the row indices for all the selected components
+ * @return the selected rows
*/
public int[] getSelectedComponentRows() {
int[] selectedRows = new int[getNumSelectedComponentRows()];
@@ -1312,7 +1325,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
* Returns the selection range containing the specified row index
* if there is one that contains it. Otherwise, returns null.
*
- * @index the row index
+ * @param rowIndex the row index
* @return the range or null
*/
public FieldRange getSelectedRangeContaining(int rowIndex) {
@@ -1333,8 +1346,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- *
- * Gets the minimum row index that is selected or -1 if no index is selected.
+ * Gets the minimum row index that is selected or -1 if no index is selected
+ * @return the index
*/
public int getMinIndexSelected() {
if (!selection.isEmpty()) {
@@ -1345,7 +1358,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Saves the current selection in the structure components viewing area.
+ * Saves the current selection in the structure components viewing area
*
* @param rows the indices for the selected rows.
*/
@@ -1440,7 +1453,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager
}
/**
- * Returns whether or not the editor is displaying numbers in hex.
+ * Returns whether or not the editor is displaying numbers in hex
+ * @return true if hex
*/
public boolean isShowingNumbersInHex() {
return showHexNumbers;
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
index 8be3d39ca7..a5c7460c24 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
@@ -467,24 +467,13 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
// no-op?
}
- protected void backspace(int repeat) {
- for (int i = 0; i < repeat; i++) {
- triggerActionKey(getTable(), 0, KeyEvent.VK_BACK_SPACE);
- }
- waitForSwing();
- }
-
- protected void leftArrowKey(int repeat) {
- for (int i = 0; i < repeat; i++) {
- triggerActionKey(getTable(), 0, KeyEvent.VK_LEFT);
- }
+ protected void leftArrow() {
+ triggerActionKey(getTable(), 0, KeyEvent.VK_LEFT);
waitForSwing();
}
- protected void rightArrowKey(int repeat) {
- for (int i = 0; i < repeat; i++) {
- triggerActionKey(getTable(), 0, KeyEvent.VK_RIGHT);
- }
+ protected void rightArrow() {
+ triggerActionKey(getTable(), 0, KeyEvent.VK_RIGHT);
waitForSwing();
}
@@ -771,14 +760,22 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
assertEquals(status, getStatus());
}
- private int getRow() {
+ protected int getRow() {
return runSwing(() -> model.getRow());
}
- private int getColumn() {
+ protected void assertRow(int row) {
+ assertEquals(row, getRow());
+ }
+
+ protected int getColumn() {
return runSwing(() -> model.getColumn());
}
+ protected void assertColumn(int column) {
+ assertEquals(column, getColumn());
+ }
+
private String getStatus() {
return runSwing(() -> model.getStatus());
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java
index 741028b91a..39ded8cf6e 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java
@@ -633,6 +633,33 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {
assertIsEditingField(row, column);
}
+ @Test
+ public void testEditAfterUsingArrowKeys() throws Exception {
+
+ //
+ // This is a regression test. Using F2 to start an edit would edit the wrong cell after
+ // the user had navigated the table using the left/right arrow keys.
+ //
+
+ init(simpleStructure, pgmBbCat, false);
+
+ int row = 3;
+ int column = model.getNameColumn();
+ assertNull(getComment(3));
+ clickTableCell(getTable(), row, column, 1);
+ assertColumn(column);
+
+ leftArrow();
+ assertColumn(column - 1);
+
+ rightArrow();
+ assertColumn(column);
+
+ performAction(editFieldAction, provider, true);
+ assertIsEditingField(row, column);
+ escape();
+ }
+
@Test
public void testChangeHexNumbersOption() throws Exception {
final Options options = tool.getOptions("Editors");
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
index 09a7ea0d3f..8d0abe4b6a 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java
@@ -17,8 +17,6 @@ package ghidra.app.plugin.core.stackeditor;
import static org.junit.Assert.*;
-import java.awt.event.KeyEvent;
-
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -310,15 +308,6 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
}
}
- @Override
- protected void backspace(final int repeat) {
- runSwing(() -> {
- for (int i = 0; i < repeat; i++) {
- triggerActionInCellEditor(KeyEvent.VK_BACK_SPACE);
- }
- });
- }
-
int getOrdinalAtOffset(int offset) {
DataTypeComponent dtc = stackModel.getEditorStack().getComponentAt(offset);
if (dtc != null) {