From 334ed9225aae43e84660106e8d81488ca19c0869 Mon Sep 17 00:00:00 2001 From: Federico Guerinoni Date: Sun, 16 Jan 2022 18:08:00 +0100 Subject: [PATCH] HexEditor: Fix copy {text/hex} to clipboard Now the copy action takes exactly the selected chars and not one more. --- Userland/Applications/HexEditor/HexEditor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index 26bf9b2327..86b41e9448 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -6,6 +6,7 @@ */ #include "HexEditor.h" +#include "AK/Format.h" #include "SearchResultsModel.h" #include #include @@ -157,7 +158,7 @@ bool HexEditor::copy_selected_hex_to_clipboard() return false; StringBuilder output_string_builder; - for (size_t i = m_selection_start; i <= m_selection_end; i++) + for (size_t i = m_selection_start; i < m_selection_end; i++) output_string_builder.appendff("{:02X} ", m_document->get(i).value); GUI::Clipboard::the().set_plain_text(output_string_builder.to_string()); @@ -170,7 +171,7 @@ bool HexEditor::copy_selected_text_to_clipboard() return false; StringBuilder output_string_builder; - for (size_t i = m_selection_start; i <= m_selection_end; i++) + for (size_t i = m_selection_start; i < m_selection_end; i++) output_string_builder.append(isprint(m_document->get(i).value) ? m_document->get(i).value : '.'); GUI::Clipboard::the().set_plain_text(output_string_builder.to_string()); @@ -183,9 +184,9 @@ bool HexEditor::copy_selected_hex_to_clipboard_as_c_code() return false; StringBuilder output_string_builder; - output_string_builder.appendff("unsigned char raw_data[{}] = {{\n", (m_selection_end - m_selection_start) + 1); + output_string_builder.appendff("unsigned char raw_data[{}] = {{\n", m_selection_end - m_selection_start); output_string_builder.append(" "); - for (size_t i = m_selection_start, j = 1; i <= m_selection_end; i++, j++) { + for (size_t i = m_selection_start, j = 1; i < m_selection_end; i++, j++) { output_string_builder.appendff("{:#02X}", m_document->get(i).value); if (i != m_selection_end) output_string_builder.append(", ");