GP-6263 - Listing - Fixed bug when copying text fro memory block fields

This commit is contained in:
dragonmacher
2025-12-19 19:00:10 -05:00
parent 2558cf5e0f
commit 5866dfc22f
2 changed files with 23 additions and 15 deletions

View File

@@ -62,9 +62,6 @@ public class MemoryBlockStartFieldFactory extends FieldFactory {
super(FIELD_NAME, model, hlProvider, displayOptions, fieldOptions);
}
/**
* @see ghidra.app.util.viewer.field.FieldFactory#getField(ProxyObj, int)
*/
@Override
public ListingField getField(ProxyObj<?> proxy, int varWidth) {
@@ -206,13 +203,13 @@ public class MemoryBlockStartFieldFactory extends FieldFactory {
String type = "";
if (blockType != MemoryBlockType.DEFAULT) {
if (block.isMapped()) {
type = "(" + block.getSourceInfos().get(0).getDescription() + ")";
type = " (" + block.getSourceInfos().get(0).getDescription() + ")";
}
else {
type = "(" + blockType + ")";
type = " (" + blockType + ")";
}
}
String line1 = block.getName() + " " + type;
String line1 = block.getName() + type;
String line2 = block.getComment();
String line3 = block.getStart().toString(true) + "-" + block.getEnd().toString(true);
Color color = ListingColors.BLOCK_START;

View File

@@ -4,9 +4,9 @@
* 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.
@@ -513,12 +513,18 @@ public class VerticalLayoutTextField implements TextField {
return getText().length();
}
int extraSpace = rowSeparator.length();
int len = 0;
int offset = 0;
for (int i = 0; i < row; i++) {
len += lines.get(i).length() + extraSpace;
String line = lines.get(i);
int len = line.length();
if (!line.endsWith(rowSeparator)) {
len += extraSpace; // getText() performs this same check; be consistent
}
offset += len;
}
len += Math.min(col, lines.get(row).length());
return len;
offset += Math.min(col, lines.get(row).length());
return offset;
}
@Override
@@ -527,11 +533,15 @@ public class VerticalLayoutTextField implements TextField {
int extraSpace = rowSeparator.length();
int n = subFields.size();
for (int i = 0; i < n; i++) {
int len = lines.get(i).length();
if (absoluteOffset < len + extraSpace) {
String line = lines.get(i);
int len = line.length();
if (!line.endsWith(rowSeparator)) {
len += extraSpace; // getText() performs this same check; be consistent
}
if (absoluteOffset < len) {
return new RowColLocation(i, absoluteOffset);
}
absoluteOffset -= len + extraSpace;
absoluteOffset -= len;
}
int lastRow = n - 1;
@@ -572,6 +582,7 @@ public class VerticalLayoutTextField implements TextField {
private class FieldRow {
private TextField field;
private int dataRow;
@SuppressWarnings("unused") // used by Json
private int screenRow;
FieldRow(TextField field, int dataRow, int screenRow) {