fix: Crash when trying to place pattern language variable through the Edit menu
Fixes #1013
This commit is contained in:
parent
a5568d09d8
commit
24e584c77b
@ -85,6 +85,10 @@ namespace hex::plugin::builtin {
|
||||
void registerEvents();
|
||||
void registerMenuItems();
|
||||
void registerHandlers();
|
||||
|
||||
void appendEditorText(const std::string &text);
|
||||
void appendVariable(const std::string &type);
|
||||
void appendArray(const std::string &type, size_t size);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -863,6 +863,24 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
void ViewPatternEditor::appendEditorText(const std::string &text) {
|
||||
this->m_textEditor.SetCursorPosition(TextEditor::Coordinates { this->m_textEditor.GetTotalLines(), 0 });
|
||||
this->m_textEditor.InsertText(hex::format("\n{0}", text));
|
||||
this->m_hasUnevaluatedChanges = true;
|
||||
}
|
||||
|
||||
void ViewPatternEditor::appendVariable(const std::string &type) {
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
|
||||
appendEditorText(hex::format("{0} {0}_at_0x{1:02X} @ 0x{1:02X};", type, selection->getStartAddress()));
|
||||
}
|
||||
|
||||
void ViewPatternEditor::appendArray(const std::string &type, size_t size) {
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
|
||||
appendEditorText(hex::format("{0} {0}_array_at_0x{1:02X}[0x{2:02X}] @ 0x{1:02X};", type, selection->getStartAddress(), (selection->getSize() + (size - 1)) / size));
|
||||
}
|
||||
|
||||
void ViewPatternEditor::registerMenuItems() {
|
||||
/* Import Pattern */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.pattern" }, 4050, Shortcut::None,
|
||||
@ -898,24 +916,6 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
}, ImHexApi::Provider::isValid);
|
||||
|
||||
const auto appendEditorText = [this](const std::string &text){
|
||||
this->m_textEditor.SetCursorPosition(TextEditor::Coordinates { this->m_textEditor.GetTotalLines(), 0 });
|
||||
this->m_textEditor.InsertText(hex::format("\n{0}", text));
|
||||
this->m_hasUnevaluatedChanges = true;
|
||||
};
|
||||
|
||||
const auto appendVariable = [&](const std::string &type) {
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
|
||||
appendEditorText(hex::format("{0} {0}_at_0x{1:02X} @ 0x{1:02X};", type, selection->getStartAddress()));
|
||||
};
|
||||
|
||||
const auto appendArray = [&](const std::string &type, size_t size) {
|
||||
auto selection = ImHexApi::HexEditor::getSelection();
|
||||
|
||||
appendEditorText(hex::format("{0} {0}_array_at_0x{1:02X}[0x{2:02X}] @ 0x{1:02X};", type, selection->getStartAddress(), (selection->getSize() + (size - 1)) / size));
|
||||
};
|
||||
|
||||
constexpr static std::array<std::pair<const char *, size_t>, 21> Types = {{
|
||||
{ "u8", 1 }, { "u16", 2 }, { "u24", 3 }, { "u32", 4 }, { "u48", 6 }, { "u64", 8 }, { "u96", 12 }, { "u128", 16 },
|
||||
{ "s8", 1 }, { "s16", 2 }, { "s24", 3 }, { "s32", 4 }, { "s48", 6 }, { "s64", 8 }, { "s96", 12 }, { "s128", 16 },
|
||||
|
Loading…
Reference in New Issue
Block a user