From 604557c71bbac947a7be0ad3d5c3b11b134313bd Mon Sep 17 00:00:00 2001 From: Timothy Slater Date: Thu, 3 Mar 2022 08:21:10 -0600 Subject: [PATCH] HexEditor: Add get_byte() method to HexEditor class --- Userland/Applications/HexEditor/HexEditor.cpp | 8 ++++++++ Userland/Applications/HexEditor/HexEditor.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index e7c3b00f04..ad16ffdf15 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -229,6 +229,14 @@ void HexEditor::set_content_length(size_t length) set_content_size({ static_cast(newWidth), static_cast(newHeight) }); } +Optional HexEditor::get_byte(size_t position) +{ + if (position < m_document->size()) + return m_document->get(position).value; + + return {}; +} + void HexEditor::mousedown_event(GUI::MouseEvent& event) { if (event.button() != GUI::MouseButton::Primary) { diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h index 4ec6556437..6444c4cab8 100644 --- a/Userland/Applications/HexEditor/HexEditor.h +++ b/Userland/Applications/HexEditor/HexEditor.h @@ -39,6 +39,7 @@ public: bool open_new_file(size_t size); void open_file(NonnullRefPtr file); void fill_selection(u8 fill_byte); + Optional get_byte(size_t position); bool save_as(NonnullRefPtr); bool save();