Fix root class rename targeting wrong struct when using type selector

RootClassName and RootClassType edit handlers now use m_viewRootId
instead of blindly picking the first root struct. Default name for
unnamed structs changed from <no name> to NoName. Dim the opening
brace on the command row to match the rest of the bar's grey text.
This commit is contained in:
IChooseYou
2026-02-10 08:06:43 -07:00
committed by sysadmin
parent 24a7e68136
commit df566064ba
3 changed files with 41 additions and 17 deletions

View File

@@ -496,7 +496,7 @@ ComposeResult compose(const NodeTree& tree, const Provider& prov, uint64_t viewR
} }
// Emit CommandRow as line 0 (combined: source + address + root class type + name) // Emit CommandRow as line 0 (combined: source + address + root class type + name)
const QString cmdRowText = QStringLiteral("[\u25B8] source\u25BE \u00B7 0x0 \u00B7 struct\u25BE <no class> {"); const QString cmdRowText = QStringLiteral("[\u25B8] source\u25BE \u00B7 0x0 \u00B7 struct\u25BE NoName {");
{ {
LineMeta lm; LineMeta lm;
lm.nodeIdx = -1; lm.nodeIdx = -1;

View File

@@ -510,31 +510,47 @@ void RcxController::connectEditor(RcxEditor* editor) {
case EditTarget::RootClassType: { case EditTarget::RootClassType: {
QString kw = text.toLower().trimmed(); QString kw = text.toLower().trimmed();
if (kw != QStringLiteral("struct") && kw != QStringLiteral("class") && kw != QStringLiteral("enum")) break; if (kw != QStringLiteral("struct") && kw != QStringLiteral("class") && kw != QStringLiteral("enum")) break;
for (int i = 0; i < m_doc->tree.nodes.size(); i++) { uint64_t targetId = m_viewRootId;
auto& n = m_doc->tree.nodes[i]; if (targetId == 0) {
for (const auto& n : m_doc->tree.nodes) {
if (n.parentId == 0 && n.kind == NodeKind::Struct) { if (n.parentId == 0 && n.kind == NodeKind::Struct) {
QString oldKw = n.resolvedClassKeyword(); targetId = n.id;
break;
}
}
}
if (targetId != 0) {
int idx = m_doc->tree.indexOfId(targetId);
if (idx >= 0) {
QString oldKw = m_doc->tree.nodes[idx].resolvedClassKeyword();
if (oldKw != kw) { if (oldKw != kw) {
m_doc->undoStack.push(new RcxCommand(this, m_doc->undoStack.push(new RcxCommand(this,
cmd::ChangeClassKeyword{n.id, oldKw, kw})); cmd::ChangeClassKeyword{targetId, oldKw, kw}));
} }
break;
} }
} }
break; break;
} }
case EditTarget::RootClassName: { case EditTarget::RootClassName: {
// Rename the root struct's structTypeName // Rename the viewed root struct's structTypeName
if (!text.isEmpty()) { if (!text.isEmpty()) {
for (int i = 0; i < m_doc->tree.nodes.size(); i++) { uint64_t targetId = m_viewRootId;
auto& n = m_doc->tree.nodes[i]; if (targetId == 0) {
for (const auto& n : m_doc->tree.nodes) {
if (n.parentId == 0 && n.kind == NodeKind::Struct) { if (n.parentId == 0 && n.kind == NodeKind::Struct) {
QString oldName = n.structTypeName; targetId = n.id;
break;
}
}
}
if (targetId != 0) {
int idx = m_doc->tree.indexOfId(targetId);
if (idx >= 0) {
QString oldName = m_doc->tree.nodes[idx].structTypeName;
if (oldName != text) { if (oldName != text) {
m_doc->undoStack.push(new RcxCommand(this, m_doc->undoStack.push(new RcxCommand(this,
cmd::ChangeStructTypeName{n.id, oldName, text})); cmd::ChangeStructTypeName{targetId, oldName, text}));
} }
break;
} }
} }
} }
@@ -1454,7 +1470,7 @@ void RcxController::updateCommandRow() {
QString keyword = n.resolvedClassKeyword(); QString keyword = n.resolvedClassKeyword();
QString className = n.structTypeName.isEmpty() ? n.name : n.structTypeName; QString className = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
row2 = QStringLiteral("%1\u25BE %2 {") row2 = QStringLiteral("%1\u25BE %2 {")
.arg(keyword, className.isEmpty() ? QStringLiteral("<no name>") : className); .arg(keyword, className.isEmpty() ? QStringLiteral("NoName") : className);
} }
} }
if (row2.isEmpty()) { if (row2.isEmpty()) {
@@ -1465,13 +1481,13 @@ void RcxController::updateCommandRow() {
QString keyword = n.resolvedClassKeyword(); QString keyword = n.resolvedClassKeyword();
QString className = n.structTypeName.isEmpty() ? n.name : n.structTypeName; QString className = n.structTypeName.isEmpty() ? n.name : n.structTypeName;
row2 = QStringLiteral("%1\u25BE %2 {") row2 = QStringLiteral("%1\u25BE %2 {")
.arg(keyword, className); .arg(keyword, className.isEmpty() ? QStringLiteral("NoName") : className);
break; break;
} }
} }
} }
if (row2.isEmpty()) if (row2.isEmpty())
row2 = QStringLiteral("struct\u25BE <no class> {"); row2 = QStringLiteral("struct\u25BE NoName {");
QString combined = QStringLiteral("[\u25B8] ") + row + QStringLiteral(" \u00B7 ") + row2; QString combined = QStringLiteral("[\u25B8] ") + row + QStringLiteral(" \u00B7 ") + row2;

View File

@@ -732,6 +732,14 @@ void RcxEditor::applyCommandRowPills() {
if (rn.valid) { if (rn.valid) {
fillIndicatorCols(IND_CLASS_NAME, line, rn.start, rn.end); fillIndicatorCols(IND_CLASS_NAME, line, rn.start, rn.end);
} }
// Dim trailing opening brace to match the rest of the command row grey
for (int i = t.size() - 1; i >= 0; --i) {
if (t[i] == ' ' || t[i] == '\t') continue;
if (t[i] == '{')
fillIndicatorCols(IND_HEX_DIM, line, i, i + 1);
break;
}
} }
// ── Shared inline-edit shutdown ── // ── Shared inline-edit shutdown ──