mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-03 05:57:40 -05:00
impr: Don't move hex editor scroll position when jumping to address that's on-screen (#1660)
### Problem description This PR offers two improvements: 1) When selecting / jumping to an offset that falls within the current viewport of the scroll view, the scroll offset will no longer force the selected byte to the top of the view. Instead, the scroll offset will only be changed if the selected byte is outside the current view. 2) In case a wrong offset is entered into the Select or Goto dialog (e.g. and offset beyond EoF), the dialog's button will be disabled. ### Implementation description For the first change, I modified the logic that recalculates the `m_scrollPosition ` based on the current byte offset. For the second change, I added validation logic to both popups to ensure that the entered offsets are valid (using `provider->getActualSize()`). In case of the Select popup, I wrapped the button into an `ImGui::Begin/EndDisabled` to enforce the validation check.
This commit is contained in:
@@ -88,12 +88,14 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
bool isOffsetValid = m_newAddress <= ImHexApi::Provider::get()->getActualSize();
|
||||
|
||||
bool executeGoto = false;
|
||||
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
|
||||
if (isOffsetValid && ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
|
||||
executeGoto = true;
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(!m_newAddress.has_value());
|
||||
ImGui::BeginDisabled(!m_newAddress.has_value() || !isOffsetValid);
|
||||
{
|
||||
const auto label = hex::format("{} {}", "hex.builtin.view.hex_editor.menu.file.goto"_lang, m_newAddress.has_value() ? hex::format("0x{:08X}", *m_newAddress) : "???");
|
||||
const auto buttonWidth = ImGui::GetWindowWidth() - ImGui::GetStyle().WindowPadding.x * 2;
|
||||
@@ -163,10 +165,18 @@ namespace hex::plugin::builtin {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::Button("hex.builtin.view.hex_editor.select.select"_lang) || (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter)))) {
|
||||
editor->setSelection(m_region.getStartAddress(), m_region.getEndAddress());
|
||||
editor->jumpToSelection();
|
||||
const auto provider = ImHexApi::Provider::get();
|
||||
bool isOffsetValid = m_region.getStartAddress() <= m_region.getEndAddress() &&
|
||||
m_region.getEndAddress() < provider->getActualSize();
|
||||
|
||||
ImGui::BeginDisabled(!isOffsetValid);
|
||||
{
|
||||
if (ImGui::Button("hex.builtin.view.hex_editor.select.select"_lang) || (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter)))) {
|
||||
editor->setSelection(m_region.getStartAddress(), m_region.getEndAddress());
|
||||
editor->jumpToSelection();
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user