From ec9461741ceb93e78a017ef2abee3bdde0e71a35 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 30 Jul 2025 20:21:26 +0200 Subject: [PATCH] feat: Added goto command palette command --- plugins/builtin/romfs/lang/en_US.json | 2 ++ .../content/command_palette_commands.cpp | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 3c119a734..84878d193 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -73,6 +73,8 @@ "hex.builtin.command.convert.as": "as", "hex.builtin.command.cmd.desc": "Command", "hex.builtin.command.cmd.result": "Run command '{0}'", + "hex.builtin.command.goto.desc": "Goto specific address", + "hex.builtin.command.goto.result": "Goto address 0x{0:08X}", "hex.builtin.command.web.desc": "Website lookup", "hex.builtin.command.web.result": "Navigate to '{0}'", "hex.builtin.drag_drop.text": "Drop files here to open them...", diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 674c0be57..e08cea03e 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -278,6 +278,34 @@ namespace hex::plugin::builtin { } }); + ContentRegistry::CommandPaletteCommands::add( + ContentRegistry::CommandPaletteCommands::Type::SymbolCommand, + "@", + "hex.builtin.command.goto.desc", + [](auto input) { + wolv::math_eval::MathEvaluator evaluator; + evaluator.registerStandardVariables(); + evaluator.registerStandardFunctions(); + + std::optional result = evaluator.evaluate(input); + if (result.has_value()) + return hex::format("hex.builtin.command.goto.result"_lang, result.value()); + else if (evaluator.hasError()) + return hex::format("Error: {}", *evaluator.getLastError()); + else + return std::string("???"); + }, [](auto input) -> std::optional { + wolv::math_eval::MathEvaluator evaluator; + evaluator.registerStandardVariables(); + evaluator.registerStandardFunctions(); + + std::optional result = evaluator.evaluate(input); + if (result.has_value()) { + ImHexApi::HexEditor::setSelection(result.value(), 1); + } + return std::nullopt; + }); + ContentRegistry::CommandPaletteCommands::add( ContentRegistry::CommandPaletteCommands::Type::KeywordCommand, "/web",