diff options
author | Timothy Slater <tslater2006@gmail.com> | 2022-03-03 08:20:47 -0600 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-07 16:55:20 +0430 |
commit | 1b70c5f60514f0fde0964ff9a1f16c7c1a504f87 (patch) | |
tree | 008bb2c055bd0988307ce1e5160ebe98372cd567 /Userland/Applications/HexEditor | |
parent | 151eb8606d38d4003ff43a6b829184ef9224fc67 (diff) | |
download | serenity-1b70c5f60514f0fde0964ff9a1f16c7c1a504f87.zip |
HexEditor: Add ability to set a selection range
Diffstat (limited to 'Userland/Applications/HexEditor')
-rw-r--r-- | Userland/Applications/HexEditor/HexEditor.cpp | 13 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/HexEditor.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index bb2b2faaee..e7c3b00f04 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org> * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -111,7 +112,19 @@ void HexEditor::set_position(size_t position) scroll_position_into_view(position); update_status(); } +void HexEditor::set_selection(size_t position, size_t length) +{ + if (position > m_document->size() || position + length > m_document->size()) + return; + m_position = position; + m_cursor_at_low_nibble = false; + m_selection_start = position; + m_selection_end = position + length; + reset_cursor_blink_state(); + scroll_position_into_view(position); + update_status(); +} bool HexEditor::save_as(NonnullRefPtr<Core::File> new_file) { if (m_document->type() == HexDocument::Type::File) { diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h index 84989e0a95..4ec6556437 100644 --- a/Userland/Applications/HexEditor/HexEditor.h +++ b/Userland/Applications/HexEditor/HexEditor.h @@ -2,6 +2,7 @@ * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org> * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -53,6 +54,7 @@ public: void set_bytes_per_row(size_t); void set_position(size_t position); + void set_selection(size_t position, size_t length); void highlight(size_t start, size_t end); Optional<size_t> find(ByteBuffer& needle, size_t start = 0); Optional<size_t> find_and_highlight(ByteBuffer& needle, size_t start = 0); |