From 21a25f5192eff635d85f507d78d149e840ae1764 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:07:10 -0400 Subject: [PATCH] GP-4426 - Fixed exception in the Structure Editor when searching while some columns have been removed --- .../compositeeditor/CompositeEditorPanel.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 e9288a844f..58c81ee818 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 @@ -1093,7 +1093,7 @@ public abstract class CompositeEditorPanel extends JPanel private Integer findBackward(String text) { String searchText = text.toLowerCase(); - int colCount = model.getColumnCount(); + int colCount = table.getColumnCount(); int currentRow = Math.max(0, model.getRow()); // search previous lines @@ -1117,16 +1117,20 @@ public abstract class CompositeEditorPanel extends JPanel return null; } - private boolean matchesSearch(String searchText, int row, int col) { - int modelCol = table.convertColumnIndexToModel(col); - Object valueAt = model.getValueAt(row, modelCol); + private boolean matchesSearch(String searchText, int viewRow, int viewCol) { + + // Note: row is the same in view and model space; col is in view space and can differ from + // the model, since columns can be hidden in the view, but remain in the model. + int modelRow = viewRow; + int modelCol = table.convertColumnIndexToModel(viewCol); + Object valueAt = model.getValueAt(modelRow, modelCol); if (valueAt == null) { return false; } String value = getString(valueAt).toLowerCase(); - if (modelCol == model.getNameColumn()) { - return nameMatchesSearch(searchText, row, value); + if (viewCol == model.getNameColumn()) { + return nameMatchesSearch(searchText, modelRow, value); } return value.contains(searchText);