mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
fixed bug where listing would jump when opening/closing large structures
or arrays
This commit is contained in:
parent
df971ee613
commit
7b7e730844
12 changed files with 175 additions and 23 deletions
|
@ -961,23 +961,45 @@ public class FieldPanel extends JPanel
|
|||
|
||||
@Override
|
||||
// BigLayoutModelListener
|
||||
public void modelSizeChanged() {
|
||||
BigInteger anchorIndex = layouts.isEmpty() ? BigInteger.ZERO : layouts.get(0).getIndex();
|
||||
public void modelSizeChanged(IndexMapper indexMapper) {
|
||||
BigInteger anchorIndex =
|
||||
layouts.isEmpty() ? BigInteger.ZERO : indexMapper.map(layouts.get(0).getIndex());
|
||||
int anchorOffset = layouts.isEmpty() ? 0 : layouts.get(0).getYPos();
|
||||
Point cursorPoint = getCursorPoint();
|
||||
AnchoredLayout layout = findLayoutOnScreen(cursorPosition.getIndex());
|
||||
BigInteger cursorIndex = indexMapper.map(cursorPosition.getIndex());
|
||||
AnchoredLayout layout = findLayoutOnScreen(cursorIndex);
|
||||
if (layout != null) {
|
||||
anchorIndex = cursorPosition.getIndex();
|
||||
anchorIndex = cursorIndex;
|
||||
anchorOffset = layout.getYPos();
|
||||
}
|
||||
notifyScrollListenerModelChanged();
|
||||
layouts = layoutHandler.positionLayoutsAroundAnchor(anchorIndex, anchorOffset);
|
||||
|
||||
updateHighlight(indexMapper);
|
||||
cursorHandler.updateCursor(cursorPoint);
|
||||
notifyScrollListenerViewChangedAndRepaint();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void updateHighlight(IndexMapper mapper) {
|
||||
if (highlight.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FieldSelection oldHighlight = highlight;
|
||||
highlight = new FieldSelection();
|
||||
for (FieldRange range : oldHighlight) {
|
||||
FieldLocation start = range.getStart();
|
||||
FieldLocation end = range.getEnd();
|
||||
BigInteger startIndex = mapper.map(start.getIndex());
|
||||
BigInteger endIndex = mapper.map(end.getIndex());
|
||||
if (startIndex != null && endIndex != null) {
|
||||
start.setIndex(startIndex);
|
||||
end.setIndex(endIndex);
|
||||
highlight.addRange(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
model.flushChanges();
|
||||
|
|
|
@ -24,6 +24,7 @@ import javax.swing.JFrame;
|
|||
|
||||
import docking.widgets.fieldpanel.*;
|
||||
import docking.widgets.fieldpanel.field.*;
|
||||
import docking.widgets.fieldpanel.listener.IndexMapper;
|
||||
import docking.widgets.fieldpanel.listener.LayoutModelListener;
|
||||
import docking.widgets.fieldpanel.support.*;
|
||||
import docking.widgets.indexedscrollpane.IndexedScrollPane;
|
||||
|
@ -53,7 +54,7 @@ public class TestBigLayoutModel implements LayoutModel {
|
|||
public void setNumIndexes(BigInteger n) {
|
||||
this.numIndexes = n;
|
||||
for (LayoutModelListener listener : listeners) {
|
||||
listener.modelSizeChanged();
|
||||
listener.modelSizeChanged(IndexMapper.IDENTITY_MAPPER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package docking.widgets.fieldpanel.listener;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* IndexMapper that always maps an index back to itself.
|
||||
*/
|
||||
class IdentityMapper implements IndexMapper {
|
||||
|
||||
@Override
|
||||
public BigInteger map(BigInteger value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package docking.widgets.fieldpanel.listener;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import docking.widgets.fieldpanel.FieldPanel;
|
||||
|
||||
/**
|
||||
* Interface for mapping indexes when the LayoutModel changes. In other words, if the mapping
|
||||
* of layout indexes to some data model changes and you want the {@link FieldPanel} to continue
|
||||
* to display the same model data on the screen, the IndexMapper can be used to convert old
|
||||
* indexes to new indexes.
|
||||
*/
|
||||
public interface IndexMapper {
|
||||
public IndexMapper IDENTITY_MAPPER = new IdentityMapper();
|
||||
|
||||
public BigInteger map(BigInteger value);
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,8 +21,10 @@ public interface LayoutModelListener {
|
|||
|
||||
/**
|
||||
* Called whenever the number of indexes changed
|
||||
* @param indexMapper Maps indexes from before the model size change to indexes after
|
||||
* the model size changed.
|
||||
*/
|
||||
void modelSizeChanged();
|
||||
void modelSizeChanged(IndexMapper indexMapper);
|
||||
|
||||
/**
|
||||
* Called when the data at an index or range of indexes changes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue