1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

HexEditor: Fix half byte offset bug

If you had made a change to the first 4 bits of a byte and then changed
your offset via keyboard or menu option it would change the last 4 bits
of the new offset the next time you made a change and would not show that
the byte had been changed at the new offset.
This commit is contained in:
Brandon Scott 2019-10-21 00:54:34 -05:00 committed by Andreas Kling
parent a76b02f741
commit 465a33443c

View file

@ -50,6 +50,7 @@ void HexEditor::set_position(int position)
return;
m_position = position;
m_byte_position = 0;
scroll_position_into_view(position);
update_status();
}
@ -288,6 +289,7 @@ void HexEditor::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Up) {
if (m_position - bytes_per_row() >= 0) {
m_position -= bytes_per_row();
m_byte_position = 0;
scroll_position_into_view(m_position);
update();
update_status();
@ -298,6 +300,7 @@ void HexEditor::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Down) {
if (m_position + bytes_per_row() < m_buffer.size()) {
m_position += bytes_per_row();
m_byte_position = 0;
scroll_position_into_view(m_position);
update();
update_status();
@ -308,6 +311,7 @@ void HexEditor::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Left) {
if (m_position - 1 >= 0) {
m_position--;
m_byte_position = 0;
scroll_position_into_view(m_position);
update();
update_status();
@ -318,6 +322,7 @@ void HexEditor::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Right) {
if (m_position + 1 < m_buffer.size()) {
m_position++;
m_byte_position = 0;
scroll_position_into_view(m_position);
update();
update_status();
@ -328,6 +333,7 @@ void HexEditor::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Backspace) {
if (m_position > 0) {
m_position--;
m_byte_position = 0;
scroll_position_into_view(m_position);
update();
update_status();
@ -374,6 +380,7 @@ void HexEditor::text_mode_keydown_event(GKeyEvent& event)
m_tracked_changes.set(m_position, m_buffer.data()[m_position]);
m_buffer.data()[m_position] = (u8)event.text().characters()[0]; // save the first 4 bits, OR the new value in the last 4
m_position++;
m_byte_position = 0;
update();
update_status();
did_change();