| 3520 | } |
| 3521 | |
| 3522 | TextDocument::SearchResult TextDocument::findLast( const String& text, TextPosition from, |
| 3523 | bool caseSensitive, bool wholeWord, |
| 3524 | FindReplaceType type, TextRange restrictRange ) { |
| 3525 | std::vector<String> textLines = text.split( '\n', true, true ); |
| 3526 | |
| 3527 | if ( textLines.empty() || textLines.size() > linesCount() ) |
| 3528 | return {}; |
| 3529 | |
| 3530 | from = sanitizePosition( from ); |
| 3531 | |
| 3532 | TextPosition to = startOfDoc(); |
| 3533 | if ( restrictRange.isValid() ) { |
| 3534 | restrictRange = sanitizeRange( restrictRange.normalized() ); |
| 3535 | to = restrictRange.start(); |
| 3536 | if ( from < restrictRange.start() || from > restrictRange.end() ) |
| 3537 | return {}; |
| 3538 | } |
| 3539 | |
| 3540 | if ( from == to ) |
| 3541 | return {}; |
| 3542 | |
| 3543 | if ( textLines.size() == 1 ) |
| 3544 | return findTextLast( text, from, caseSensitive, wholeWord, type, restrictRange ); |
| 3545 | |
| 3546 | auto range = findTextLast( textLines[0], from, caseSensitive, false, type, restrictRange ); |
| 3547 | |
| 3548 | if ( !range.isValid() ) |
| 3549 | return {}; |
| 3550 | |
| 3551 | TextPosition initPos( range.result.end().line(), 0 ); |
| 3552 | |
| 3553 | for ( size_t i = 1; i < textLines.size() - 1; i++ ) { |
| 3554 | if ( initPos < from || initPos > to ) |
| 3555 | return findLast( text, range.result.end(), caseSensitive, wholeWord, type, |
| 3556 | restrictRange ); |
| 3557 | |
| 3558 | String currentLine( mLines[initPos.line()].getText() ); |
| 3559 | |
| 3560 | if ( TextPosition( initPos.line(), (Int64)currentLine.size() - 1 ) > to ) |
| 3561 | return findLast( text, range.result.end(), caseSensitive, wholeWord, type, |
| 3562 | restrictRange ); |
| 3563 | |
| 3564 | if ( !caseSensitive ) { |
| 3565 | currentLine.toLower(); |
| 3566 | textLines[i].toLower(); |
| 3567 | } |
| 3568 | |
| 3569 | if ( currentLine == textLines[i] ) { |
| 3570 | initPos = TextPosition( i + 1, 0 ); |
| 3571 | } else { |
| 3572 | return findLast( text, range.result.end(), caseSensitive, wholeWord, type, |
| 3573 | restrictRange ); |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | if ( initPos < from || initPos > to ) |
| 3578 | return findLast( text, range.result.end(), caseSensitive, wholeWord, type, restrictRange ); |
| 3579 |
no test coverage detected