mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
HexEditor: Fix copy {text/hex} to clipboard
Now the copy action takes exactly the selected chars and not one more.
This commit is contained in:
parent
932ce93fd7
commit
334ed9225a
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/guerinoni Commit: https://github.com/SerenityOS/serenity/commit/334ed9225a Pull-request: https://github.com/SerenityOS/serenity/pull/11942 Issue: https://github.com/SerenityOS/serenity/issues/11925 Reviewed-by: https://github.com/metmo ✅
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "HexEditor.h"
|
||||
#include "AK/Format.h"
|
||||
#include "SearchResultsModel.h"
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
@ -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(", ");
|
||||
|
Loading…
Reference in New Issue
Block a user