GP-4891 - Fixed an exception in the Stack editor when editing and using

the down arrow
This commit is contained in:
dragonmacher 2024-09-04 16:52:40 -04:00
parent 0258fc3209
commit 28ea0c99f0
4 changed files with 45 additions and 17 deletions

View file

@ -486,8 +486,8 @@ public abstract class CompositeEditorPanel extends JPanel
if (index >= 0) {
row = index;
table.setRowSelectionInterval(row, row);
if (model.isCellEditable(index, modelColumn)) {
return beginEditField(model.getRow(), model.getColumn());
if (model.isCellEditable(row, modelColumn)) {
return beginEditField(row, modelColumn);
}
}
return false;
@ -500,6 +500,7 @@ public abstract class CompositeEditorPanel extends JPanel
protected boolean editBelowField() {
int row = model.getRow();
int modelColumn = model.getColumn();
// Get the current row (index) and column (fieldNum).
int index = row;
index++;
@ -508,8 +509,8 @@ public abstract class CompositeEditorPanel extends JPanel
if (index < numComps) {
row = index;
table.setRowSelectionInterval(row, row);
if (model.isCellEditable(index, modelColumn)) {
return beginEditField(model.getRow(), model.getColumn());
if (model.isCellEditable(row, modelColumn)) {
return beginEditField(row, modelColumn);
}
}
return false;
@ -602,7 +603,7 @@ public abstract class CompositeEditorPanel extends JPanel
model.setColumn(modelIndex);
}
else {
model.setColumn(-1);
model.setColumn(e.getFirstIndex());
}
});

View file

@ -406,22 +406,16 @@ public class StackEditorModel extends CompositeEditorModel {
if (columnIndex == LENGTH) {
return false;
}
if ((rowIndex < 0) || (rowIndex >= getRowCount())) {
if (rowIndex < 0 || rowIndex >= getRowCount()) {
return false;
}
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
return false;
}
DataTypeComponent dtc = stackDt.getComponent(rowIndex);
if (dtc == null) {
return false;
}
// if (columnIndex != NAME) {
// int offset = dtc.getOffset();
// if (!hasCustomParameterStorage && originalStack.isParameterOffset(offset)) {
// return false;
// }
// }
// if (dtc.getDataType() instanceof StackPieceDataType) {
// return false;
// }
boolean notDefined = (stackDt.getDefinedComponentAtOrdinal(rowIndex) == null);
return !(notDefined && (columnIndex == OFFSET));
}

View file

@ -474,6 +474,16 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
waitForSwing();
}
protected void downArrow() {
triggerActionKey(getTable(), 0, KeyEvent.VK_DOWN);
waitForSwing();
}
protected void downArrow(JComponent component) {
triggerActionKey(component, 0, KeyEvent.VK_DOWN);
waitForSwing();
}
protected void endKey() {
triggerActionKey(getKeyEventDestination(), 0, KeyEvent.VK_END);
waitForSwing();

View file

@ -139,6 +139,29 @@ public class StackEditorProvider1Test extends AbstractStackEditorProviderTest {
assertStackEditorHidden(function);
}
@Test
public void testEditUsingArrowKeys() throws Exception {
init(SIMPLE_STACK);
int row = 1;
int column = model.getNameColumn();
clickTableCell(getTable(), row, column, 1);
assertColumn(column);
performAction(editFieldAction, provider, true);
// change name
JTextField tf = getCellEditorTextField();
setText(tf, tf.getText() + "change");
downArrow(tf);
assertRow(row + 1);
assertColumn(column);
assertIsEditingField(row + 1, column);
escape();
}
@Test
public void testDeleteAssociatedFunction() throws Exception {
Window dialog;