1
0
mirror of synced 2024-11-29 01:44:31 +01:00

fix: Hex editor selection moving with shift + arrow keys not working correctly

This commit is contained in:
WerWolv 2022-06-19 15:09:38 +02:00
parent 116aeede2d
commit c238767750
2 changed files with 26 additions and 7 deletions

View File

@ -30,7 +30,7 @@ namespace hex::plugin::builtin {
public:
void setSelection(const Region &region) { this->setSelection(region.getStartAddress(), region.getEndAddress()); }
void setSelection(i128 start, i128 end) {
void setSelection(u128 start, u128 end) {
if (!ImHexApi::Provider::isValid())
return;
if (start == InvalidSelection && end == InvalidSelection)
@ -45,8 +45,8 @@ namespace hex::plugin::builtin {
this->m_selectionChanged = this->m_selectionStart != start || this->m_selectionEnd != end;
this->m_selectionStart = std::clamp<decltype(start)>(start, 0, maxAddress);
this->m_selectionEnd = std::clamp<decltype(end)>(end, 0, maxAddress);
this->m_selectionStart = std::clamp<u128>(start, 0, maxAddress);
this->m_selectionEnd = std::clamp<u128>(end, 0, maxAddress);
if (this->m_selectionChanged) {
EventManager::post<EventRegionSelected>(this->getSelection());

View File

@ -1158,23 +1158,42 @@ namespace hex::plugin::builtin {
// Move selection around
ShortcutManager::addShortcut(this, SHIFT + Keys::Up, [this] {
this->setSelection(this->m_selectionEnd - this->m_bytesPerRow, this->m_selectionEnd);
this->m_selectionStart = std::max<u64>(this->m_selectionStart, this->m_bytesPerRow);
this->setSelection(this->m_selectionStart - this->m_bytesPerRow, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Down, [this] {
this->setSelection(this->m_selectionEnd + this->m_bytesPerRow, this->m_selectionEnd);
this->setSelection(this->m_selectionStart + this->m_bytesPerRow, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Left, [this] {
this->setSelection(this->m_selectionEnd - 1, this->m_selectionEnd);
this->m_selectionStart = std::max<u64>(this->m_selectionStart, 1);
this->setSelection(this->m_selectionStart - 1, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Right, [this] {
this->setSelection(this->m_selectionEnd + 1, this->m_selectionEnd);
this->setSelection(this->m_selectionStart + 1, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, Keys::PageUp, [this] {
u64 visibleByteCount = this->m_bytesPerRow * this->m_visibleRowCount;
if (this->m_selectionEnd >= visibleByteCount) {
auto pos = this->m_selectionEnd - visibleByteCount;
this->setSelection(pos, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
}
});
ShortcutManager::addShortcut(this, Keys::PageDown, [this] {
auto pos = this->m_selectionEnd + (this->m_bytesPerRow * this->m_visibleRowCount);
this->setSelection(pos, this->m_selectionEnd);
this->scrollToSelection();
this->jumpIfOffScreen();
});