| 1441 | } |
| 1442 | |
| 1443 | QString DiffTextWindow::getSelection() const |
| 1444 | { |
| 1445 | if(d->m_pLineData == nullptr) |
| 1446 | return QString(); |
| 1447 | |
| 1448 | QString selectionString; |
| 1449 | |
| 1450 | LineRef line = 0; |
| 1451 | LineType lineIdx = 0; |
| 1452 | |
| 1453 | qsizetype it; |
| 1454 | qsizetype vectorSize = d->m_bWordWrap ? d->m_diff3WrapLineVector.size() : d->getDiff3LineVector()->size(); |
| 1455 | for(it = 0; it < vectorSize; ++it) |
| 1456 | { |
| 1457 | const Diff3Line* d3l = d->m_bWordWrap ? d->m_diff3WrapLineVector[it].pD3L : (*d->getDiff3LineVector())[it]; |
| 1458 | |
| 1459 | assert(getWindowIndex() >= e_SrcSelector::A && getWindowIndex() <= e_SrcSelector::C); |
| 1460 | |
| 1461 | if(getWindowIndex() == e_SrcSelector::A) |
| 1462 | { |
| 1463 | lineIdx = d3l->getLineA(); |
| 1464 | } |
| 1465 | else if(getWindowIndex() == e_SrcSelector::B) |
| 1466 | { |
| 1467 | lineIdx = d3l->getLineB(); |
| 1468 | } |
| 1469 | else if(getWindowIndex() == e_SrcSelector::C) |
| 1470 | { |
| 1471 | lineIdx = d3l->getLineC(); |
| 1472 | } |
| 1473 | |
| 1474 | if(lineIdx != LineRef::invalid) |
| 1475 | { |
| 1476 | qsizetype size = (*d->m_pLineData)[lineIdx].size(); |
| 1477 | QString lineString = (*d->m_pLineData)[lineIdx].getLine(); |
| 1478 | |
| 1479 | if(d->m_bWordWrap) |
| 1480 | { |
| 1481 | size = d->m_diff3WrapLineVector[it].wrapLineLength; |
| 1482 | lineString = lineString.mid(d->m_diff3WrapLineVector[it].wrapLineOffset, size); |
| 1483 | } |
| 1484 | |
| 1485 | for(qsizetype i = 0; i < size; ++i) |
| 1486 | { |
| 1487 | if(d->m_selection.within(line, i)) |
| 1488 | { |
| 1489 | selectionString += lineString[i]; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if(d->m_selection.within(line, size) && |
| 1494 | (!d->m_bWordWrap || it + 1 >= vectorSize || d3l != d->m_diff3WrapLineVector[it + 1].pD3L)) |
| 1495 | { |
| 1496 | #if defined(Q_OS_WIN) |
| 1497 | selectionString += '\r'; |
| 1498 | #endif |
| 1499 | selectionString += '\n'; |
| 1500 | } |