~iahmad/kubuntu-packaging/qtcreator

« back to all changes in this revision

Viewing changes to src/plugins/fakevim/fakevimhandler.cpp

  • Committer: Timo Jyrinki
  • Date: 2014-01-15 07:44:24 UTC
  • mfrom: (1.1.30)
  • Revision ID: timo.jyrinki@canonical.com-20140115074424-3pnj3a1x6s25im9v
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
623
623
{
624
624
    bool substituted = false;
625
625
    int pos = 0;
 
626
    int right = -1;
626
627
    while (true) {
627
628
        pos = pattern.indexIn(*text, pos, QRegExp::CaretAtZero);
628
629
        if (pos == -1)
629
630
            break;
 
631
 
 
632
        // ensure that substitution is advancing towards end of line
 
633
        if (right == text->size() - pos) {
 
634
            ++pos;
 
635
            if (pos == text->size())
 
636
                break;
 
637
            continue;
 
638
        }
 
639
 
 
640
        right = text->size() - pos;
 
641
 
630
642
        substituted = true;
631
643
        QString matched = text->mid(pos, pattern.cap(0).size());
632
644
        QString repl;
652
664
            }
653
665
        }
654
666
        text->replace(pos, matched.size(), repl);
655
 
        pos += qMax(1, repl.size());
 
667
        pos += (repl.isEmpty() && matched.isEmpty()) ? 1 : repl.size();
656
668
 
657
669
        if (pos >= text->size() || !global)
658
670
            break;
6477
6489
    EDITOR(setTextCursor(tc2));
6478
6490
    EDITOR(ensureCursorVisible());
6479
6491
 
 
6492
    int offset = 0;
6480
6493
    const QTextBlock block = document()->findBlockByLineNumber(line);
6481
 
    const QTextLine textLine = block.isValid()
6482
 
        ? block.layout()->lineAt(line - block.firstLineNumber()) : QTextLine();
6483
 
    tc2.setPosition(block.position() + (textLine.isValid() ? textLine.textStart() : 0));
 
6494
    if (block.isValid()) {
 
6495
        const int blockLineCount = block.layout()->lineCount();
 
6496
        const int lineInBlock = line - block.firstLineNumber();
 
6497
        if (0 <= lineInBlock && lineInBlock < blockLineCount) {
 
6498
            QTextLine textLine = block.layout()->lineAt(lineInBlock);
 
6499
            offset = textLine.textStart();
 
6500
        } else {
 
6501
//            QTC_CHECK(false);
 
6502
        }
 
6503
    }
 
6504
    tc2.setPosition(block.position() + offset);
6484
6505
    EDITOR(setTextCursor(tc2));
6485
6506
    EDITOR(ensureCursorVisible());
6486
6507