Commit b976a34e authored by hjk's avatar hjk
Browse files

bineditor: allow copying also if selection is "backwards"

parent ad0eff18
...@@ -1290,30 +1290,31 @@ void BinEditor::zoomOut(int range) ...@@ -1290,30 +1290,31 @@ void BinEditor::zoomOut(int range)
void BinEditor::copy(bool raw) void BinEditor::copy(bool raw)
{ {
const int selStart = selectionStart(); int selStart = selectionStart();
const int selEnd = selectionEnd(); int selEnd = selectionEnd();
if (selStart < selEnd) { if (selStart >= selEnd)
const int selectionLength = selEnd - selStart; qSwap(selStart, selEnd);
if (selectionLength >> 22) {
QMessageBox::warning(this, tr("Copying Failed"), const int selectionLength = selEnd - selStart;
tr("You cannot copy more than 4 MB of binary data.")); if (selectionLength >> 22) {
return; QMessageBox::warning(this, tr("Copying Failed"),
} tr("You cannot copy more than 4 MB of binary data."));
const QByteArray &data = dataMid(selStart, selectionLength); return;
if (raw) { }
QApplication::clipboard()->setText(data); const QByteArray &data = dataMid(selStart, selectionLength);
return; if (raw) {
} QApplication::clipboard()->setText(data);
QString hexString; return;
const char * const hex = "0123456789abcdef"; }
hexString.reserve(3 * data.size()); QString hexString;
for (int i = 0; i < data.size(); ++i) { const char * const hex = "0123456789abcdef";
const uchar val = static_cast<uchar>(data[i]); hexString.reserve(3 * data.size());
hexString.append(hex[val >> 4]).append(hex[val & 0xf]).append(' '); for (int i = 0; i < data.size(); ++i) {
} const uchar val = static_cast<uchar>(data[i]);
hexString.chop(1); hexString.append(hex[val >> 4]).append(hex[val & 0xf]).append(' ');
QApplication::clipboard()->setText(hexString);
} }
hexString.chop(1);
QApplication::clipboard()->setText(hexString);
} }
void BinEditor::highlightSearchResults(const QByteArray &pattern, QTextDocument::FindFlags findFlags) void BinEditor::highlightSearchResults(const QByteArray &pattern, QTextDocument::FindFlags findFlags)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment