diff --git a/lib/external/pattern_language b/lib/external/pattern_language index a3f3c1f40ed48..3fd3748e87e27 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit a3f3c1f40ed4860f1c163269647c3dfd37078eb2 +Subproject commit 3fd3748e87e27a88586ff7ab396badf6458b36f1 diff --git a/lib/libimhex/include/hex/api/events/requests_interaction.hpp b/lib/libimhex/include/hex/api/events/requests_interaction.hpp index a214e4e6847f8..e895480bd2f9d 100644 --- a/lib/libimhex/include/hex/api/events/requests_interaction.hpp +++ b/lib/libimhex/include/hex/api/events/requests_interaction.hpp @@ -29,6 +29,18 @@ namespace hex { */ EVENT_DEF(RequestPatternEditorSelectionChange, u32, u32); + /** + * @brief Requests the Pattern set the selection + * + * Requests the Pattern editor select a region. + * + * @param startLine the line selection starts on + * @param startcolumn the column selection starts on + * @param endLine the line selection ends on + * @param endcolumn the column selection ends on + */ + EVENT_DEF(RequestPatternEditorSetSelection, u32, u32, u32, u32); + /** * @brief Requests a jump to a given pattern * diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 3a3c8e739be58..bfab4f8d50c82 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -838,6 +838,7 @@ "hex.builtin.view.hex_editor.menu.edit.insert": "Insert...", "hex.builtin.view.hex_editor.menu.edit.insert_mode": "Insert Mode", "hex.builtin.view.hex_editor.menu.edit.jump_to": "Follow selection", + "hex.builtin.view.hex_editor.menu.edit.goto_pattern_editor": "Goto in pattern editor", "hex.builtin.view.hex_editor.menu.edit.jump_to.curr_pattern": "Current Pattern", "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider": "Open Selection View", "hex.builtin.view.hex_editor.menu.edit.paste": "Paste", diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 333c35f7f5fb5..3ed9daa9267a4 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -1496,6 +1496,18 @@ namespace hex::plugin::builtin { }, [] { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isReadable(); }); + /* Goto in pattern editor */ + ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.hex_editor.menu.edit.goto_pattern_editor" }, ICON_VS_GO_TO_FILE, 1870, Shortcut::None, + [] { + const auto selection = ImHexApi::HexEditor::getSelection(); + auto patterns = ContentRegistry::PatternLanguage::getRuntime().getPatternsAtAddress(selection->getStartAddress()); + if (!patterns.empty()) { + const auto &pl = patterns.front()->getVariableLocation(); + RequestPatternEditorSetSelection::post(pl.line, pl.column, pl.line, pl.column+pl.length); + } + }, + [] { return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && ImHexApi::HexEditor::getSelection()->getSize() <= sizeof(u64); } ); + ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.edit" }, 1900); /* Open in new provider */ diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 5e5770fa258c6..e9d1ac997c24b 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1924,6 +1924,17 @@ namespace hex::plugin::builtin { m_textEditor.get(provider).SetCursorPosition(coords); }); + RequestPatternEditorSetSelection::subscribe(this, [this](u32 startLine, u32 startcolumn, u32 endLine, u32 endcolumn) { + auto provider = ImHexApi::Provider::get(); + if (startLine == 0 || endLine == 0) + return; + + const TextEditor::Coordinates start = { int(startLine)-1, int(startcolumn)-1 }; + const TextEditor::Coordinates end = { int(endLine)-1, int(endcolumn)-1 }; + m_textEditor.get(provider).SetSelection(start, end); + m_textEditor.get(provider).SetCursorPosition(end); + }); + RequestLoadPatternLanguageFile::subscribe(this, [this](const std::fs::path &path) { this->loadPatternFile(path, ImHexApi::Provider::get()); });