From df566064ba2d49fb470aeaef39637eb391bb20f9 Mon Sep 17 00:00:00 2001 From: IChooseYou Date: Tue, 10 Feb 2026 08:06:43 -0700 Subject: [PATCH] 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 to NoName. Dim the opening brace on the command row to match the rest of the bar's grey text. --- src/compose.cpp | 2 +- src/controller.cpp | 48 ++++++++++++++++++++++++++++++---------------- src/editor.cpp | 8 ++++++++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/compose.cpp b/src/compose.cpp index 313d0fa..6dca593 100644 --- a/src/compose.cpp +++ b/src/compose.cpp @@ -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) - const QString cmdRowText = QStringLiteral("[\u25B8] source\u25BE \u00B7 0x0 \u00B7 struct\u25BE {"); + const QString cmdRowText = QStringLiteral("[\u25B8] source\u25BE \u00B7 0x0 \u00B7 struct\u25BE NoName {"); { LineMeta lm; lm.nodeIdx = -1; diff --git a/src/controller.cpp b/src/controller.cpp index 375ad35..bf6e02d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -510,31 +510,47 @@ void RcxController::connectEditor(RcxEditor* editor) { case EditTarget::RootClassType: { QString kw = text.toLower().trimmed(); if (kw != QStringLiteral("struct") && kw != QStringLiteral("class") && kw != QStringLiteral("enum")) break; - for (int i = 0; i < m_doc->tree.nodes.size(); i++) { - auto& n = m_doc->tree.nodes[i]; - if (n.parentId == 0 && n.kind == NodeKind::Struct) { - QString oldKw = n.resolvedClassKeyword(); + uint64_t targetId = m_viewRootId; + if (targetId == 0) { + for (const auto& n : m_doc->tree.nodes) { + if (n.parentId == 0 && n.kind == NodeKind::Struct) { + 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) { m_doc->undoStack.push(new RcxCommand(this, - cmd::ChangeClassKeyword{n.id, oldKw, kw})); + cmd::ChangeClassKeyword{targetId, oldKw, kw})); } - break; } } break; } case EditTarget::RootClassName: { - // Rename the root struct's structTypeName + // Rename the viewed root struct's structTypeName if (!text.isEmpty()) { - for (int i = 0; i < m_doc->tree.nodes.size(); i++) { - auto& n = m_doc->tree.nodes[i]; - if (n.parentId == 0 && n.kind == NodeKind::Struct) { - QString oldName = n.structTypeName; + uint64_t targetId = m_viewRootId; + if (targetId == 0) { + for (const auto& n : m_doc->tree.nodes) { + if (n.parentId == 0 && n.kind == NodeKind::Struct) { + 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) { 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 className = n.structTypeName.isEmpty() ? n.name : n.structTypeName; row2 = QStringLiteral("%1\u25BE %2 {") - .arg(keyword, className.isEmpty() ? QStringLiteral("") : className); + .arg(keyword, className.isEmpty() ? QStringLiteral("NoName") : className); } } if (row2.isEmpty()) { @@ -1465,13 +1481,13 @@ void RcxController::updateCommandRow() { QString keyword = n.resolvedClassKeyword(); QString className = n.structTypeName.isEmpty() ? n.name : n.structTypeName; row2 = QStringLiteral("%1\u25BE %2 {") - .arg(keyword, className); + .arg(keyword, className.isEmpty() ? QStringLiteral("NoName") : className); break; } } } if (row2.isEmpty()) - row2 = QStringLiteral("struct\u25BE {"); + row2 = QStringLiteral("struct\u25BE NoName {"); QString combined = QStringLiteral("[\u25B8] ") + row + QStringLiteral(" \u00B7 ") + row2; diff --git a/src/editor.cpp b/src/editor.cpp index caff396..7fd54c0 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -732,6 +732,14 @@ void RcxEditor::applyCommandRowPills() { if (rn.valid) { 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 ──