Remove characters in active selection
| 1534 | |
| 1535 | // Remove characters in active selection |
| 1536 | void TextareaData::DeleteSelection() |
| 1537 | { |
| 1538 | // Selection must be active |
| 1539 | if(!selectionOn) |
| 1540 | return; |
| 1541 | |
| 1542 | // Sort selection points |
| 1543 | unsigned int startX, startY, endX, endY; |
| 1544 | SortSelPoints(startX, endX, startY, endY); |
| 1545 | |
| 1546 | // If both points are outside the text, exit |
| 1547 | if(startY > lineCount && endY > lineCount) |
| 1548 | { |
| 1549 | selectionOn = false; |
| 1550 | return; |
| 1551 | } |
| 1552 | // Clamp selection points in Y axis |
| 1553 | startY = startY > lineCount ? lineCount - 1 : startY; |
| 1554 | endY = endY > lineCount ? lineCount-1 : endY; |
| 1555 | |
| 1556 | // Find first selection line |
| 1557 | AreaLine *first = firstLine; |
| 1558 | for(unsigned int i = 0; i < startY; i++) |
| 1559 | first = first->next; |
| 1560 | |
| 1561 | history->TakeSnapshot(first, HistoryManager::LINES_DELETED, (endY - startY)+1); |
| 1562 | |
| 1563 | // For single-line selection |
| 1564 | if(startY == endY) |
| 1565 | { |
| 1566 | // Clamp selection points in Z axis |
| 1567 | endX = endX > first->length ? first->length : endX; |
| 1568 | startX = startX > first->length ? first->length : startX; |
| 1569 | // Move text after selection to the start of selection |
| 1570 | memmove(&first->data[startX], &first->data[endX], (first->length - endX) * sizeof(AreaChar)); |
| 1571 | // Shrink length |
| 1572 | first->length -= endX - startX; |
| 1573 | // Move cursor and disable selection mode |
| 1574 | cursorCharX = startX; |
| 1575 | selectionOn = false; |
| 1576 | }else{ // For multi-line selection |
| 1577 | // Find last selection line |
| 1578 | AreaLine *last = first; |
| 1579 | for(unsigned int i = startY; i < endY; i++) |
| 1580 | last = last->next; |
| 1581 | |
| 1582 | // Shrink first line |
| 1583 | first->length = startX > first->length ? first->length : startX; |
| 1584 | |
| 1585 | // Move cursor to starting position |
| 1586 | cursorCharX = first->length; |
| 1587 | cursorCharY = startY; |
| 1588 | |
| 1589 | // Clamp ending X position |
| 1590 | endX = endX > last->length ? last->length : endX; |
| 1591 | |
| 1592 | // Move unselected part of last line to the beginning if the line |
| 1593 | memmove(&last->data[0], &last->data[endX], (last->length - endX) * sizeof(AreaChar)); |
nothing calls this directly
no test coverage detected