From 1b70c5f60514f0fde0964ff9a1f16c7c1a504f87 Mon Sep 17 00:00:00 2001 From: Timothy Slater Date: Thu, 3 Mar 2022 08:20:47 -0600 Subject: [PATCH] HexEditor: Add ability to set a selection range --- Userland/Applications/HexEditor/HexEditor.cpp | 13 +++++++++++++ Userland/Applications/HexEditor/HexEditor.h | 2 ++ 2 files changed, 15 insertions(+) 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 * Copyright (c) 2021, Mustafa Quraish * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, Timothy Slater * * 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 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 * Copyright (c) 2021, Mustafa Quraish * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, Timothy Slater * * 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 find(ByteBuffer& needle, size_t start = 0); Optional find_and_highlight(ByteBuffer& needle, size_t start = 0);