mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-22 04:05:39 +00:00
GT-2862 - Fixed Listing cursor jumping to the wrong spot when editing
bytes
This commit is contained in:
parent
2108a5ed4c
commit
0a6bc9aa6e
@ -53,16 +53,13 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
|
||||
removeUnviewableAddressRanges();
|
||||
model.addListener(this);
|
||||
|
||||
updateMgr = new SwingUpdateManager(500, 5000, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!model.isClosed()) {
|
||||
resetIndexMap();
|
||||
for (LayoutModelListener listener : listeners) {
|
||||
listener.dataChanged(BigInteger.ZERO, addressToIndexMap.getIndexCount());
|
||||
}
|
||||
preferredViewSize = null;
|
||||
updateMgr = new SwingUpdateManager(500, 5000, () -> {
|
||||
if (!model.isClosed()) {
|
||||
resetIndexMap();
|
||||
for (LayoutModelListener listener : listeners) {
|
||||
listener.dataChanged(BigInteger.ZERO, addressToIndexMap.getIndexCount());
|
||||
}
|
||||
preferredViewSize = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -217,7 +214,6 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
|
||||
if (floc != null) {
|
||||
return floc;
|
||||
}
|
||||
|
||||
return getFieldLocation(location.getAddress(), location, true);
|
||||
}
|
||||
|
||||
@ -237,7 +233,7 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
|
||||
BigInteger index = addressToIndexMap.getIndex(address);
|
||||
Layout layout = getLayout(index);
|
||||
if (layout == null) {
|
||||
index = getLayoutForArrayElement(address);
|
||||
index = getLayoutWithinCodeUnit(address);
|
||||
layout = getLayout(index);
|
||||
}
|
||||
|
||||
@ -272,11 +268,12 @@ public class ListingModelAdapter implements LayoutModel, ListingModelListener {
|
||||
return null;
|
||||
}
|
||||
|
||||
private BigInteger getLayoutForArrayElement(Address address) {
|
||||
private BigInteger getLayoutWithinCodeUnit(Address address) {
|
||||
CodeUnit cu = model.getProgram().getListing().getCodeUnitContaining(address);
|
||||
if (cu == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Address min = cu.getMinAddress();
|
||||
while (address.compareTo(min) > 0) {
|
||||
address = address.subtract(1);
|
||||
|
@ -53,7 +53,7 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
|
||||
private List<ListingModelListener> listeners = new ArrayList<>();
|
||||
|
||||
// Use a cache so that simple arrowing to-and-fro with the keyboard will respond quickly
|
||||
private LRUMap<Address, Layout> layoutCache = new LRUMap<>(10);
|
||||
private LayoutCache layoutCache = new LayoutCache();
|
||||
|
||||
public ProgramBigListingModel(Program program, FormatManager formatMgr) {
|
||||
this.program = program;
|
||||
@ -124,15 +124,15 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
|
||||
@Override
|
||||
public Layout getLayout(Address addr, boolean isGapAddress) {
|
||||
|
||||
Layout layout = layoutCache.get(addr);
|
||||
Layout layout = layoutCache.get(addr, isGapAddress);
|
||||
if (layout == null) {
|
||||
layout = doGetLayout(addr, isGapAddress);
|
||||
layoutCache.put(addr, layout);
|
||||
layoutCache.put(addr, layout, isGapAddress);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
public Layout doGetLayout(Address addr, boolean isGapAddress) {
|
||||
private Layout doGetLayout(Address addr, boolean isGapAddress) {
|
||||
List<RowLayout> list = new ArrayList<>();
|
||||
FieldFormatModel format;
|
||||
CodeUnit cu = listing.getCodeUnitAt(addr);
|
||||
@ -581,4 +581,31 @@ public class ProgramBigListingModel implements ListingModel, FormatModelListener
|
||||
}
|
||||
return addressSet;
|
||||
}
|
||||
|
||||
private class LayoutCache {
|
||||
|
||||
private LRUMap<Address, Layout> cache = new LRUMap<>(10);
|
||||
private LRUMap<Address, Layout> gapCache = new LRUMap<>(10);
|
||||
|
||||
void clear() {
|
||||
cache.clear();
|
||||
gapCache.clear();
|
||||
}
|
||||
|
||||
Layout get(Address addr, boolean isGapAddress) {
|
||||
if (isGapAddress) {
|
||||
return gapCache.get(addr);
|
||||
}
|
||||
return cache.get(addr);
|
||||
}
|
||||
|
||||
void put(Address addr, Layout layout, boolean isGapAddress) {
|
||||
if (isGapAddress) {
|
||||
gapCache.put(addr, layout);
|
||||
}
|
||||
else {
|
||||
cache.put(addr, layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user