diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index bf0dab37386..6304cbb8ee0 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -558,6 +558,19 @@ void HexEditor::paint_event(GUI::PaintEvent& event) } } +void HexEditor::select_all() +{ + highlight(0, m_buffer.size()); + set_position(0); +} + +void HexEditor::highlight(int start, int end) +{ + m_selection_start = start; + m_selection_end = end; + set_position(start); +} + int HexEditor::find_and_highlight(ByteBuffer& needle, int start) { if (m_buffer.is_empty()) @@ -571,9 +584,7 @@ int HexEditor::find_and_highlight(ByteBuffer& needle, int start) dbgln("find_and_highlight: start={} raw_offset={} relative_offset={}", start, raw_offset, relative_offset); auto end_of_match = relative_offset + needle.size(); - set_position(relative_offset); - m_selection_start = relative_offset; - m_selection_end = end_of_match; + highlight(relative_offset, end_of_match); return end_of_match; } diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h index d03d45f7f6f..4406a3a849e 100644 --- a/Userland/Applications/HexEditor/HexEditor.h +++ b/Userland/Applications/HexEditor/HexEditor.h @@ -33,6 +33,7 @@ public: void fill_selection(u8 fill_byte); bool write_to_file(const String& path); + void select_all(); bool has_selection() const { return !(m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty()); } bool copy_selected_text_to_clipboard(); bool copy_selected_hex_to_clipboard(); @@ -42,6 +43,7 @@ public: void set_bytes_per_row(int); void set_position(int position); + void highlight(int start, int end); int find_and_highlight(ByteBuffer& needle, int start = 0); Function on_status_change; // position, edit mode, selection start, selection end Function on_change; diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 76a9515c7ab..ae124c6881f 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -37,7 +37,7 @@ HexEditorWidget::HexEditorWidget() m_statusbar->set_text(1, String::formatted("Edit Mode: {}", edit_mode == HexEditor::EditMode::Hex ? "Hex" : "Text")); m_statusbar->set_text(2, String::formatted("Selection Start: {}", selection_start)); m_statusbar->set_text(3, String::formatted("Selection End: {}", selection_end)); - m_statusbar->set_text(4, String::formatted("Selected Bytes: {}", abs(selection_end - selection_start) + 1)); + m_statusbar->set_text(4, String::formatted("Selected Bytes: {}", abs(selection_end - selection_start))); }; m_editor->on_change = [this] { @@ -147,6 +147,10 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) }); auto& edit_menu = menubar.add_menu("&Edit"); + edit_menu.add_action(GUI::CommonActions::make_select_all_action([this](auto&) { + m_editor->select_all(); + m_editor->update(); + })); edit_menu.add_action(GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { String value; if (GUI::InputBox::show(window(), value, "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecOK && !value.is_empty()) { @@ -184,6 +188,7 @@ void HexEditorWidget::initialize_menubar(GUI::Menubar& menubar) GUI::MessageBox::show(window(), String::formatted("Pattern \"{}\" not found in this file", m_search_text), "Not found", GUI::MessageBox::Type::Warning); return; } + m_editor->update(); m_last_found_index = result; } }));