Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qtextcursor.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    9393    QTextCursorPrivate::AdjustResult result = QTextCursorPrivate::CursorMoved;
    9494    // not(!) <= , so that inserting text adjusts the cursor correctly
    95     if (position < positionOfChange ||
    96         (position == positionOfChange && op == QTextUndoCommand::KeepCursor)) {
     95    if (position < positionOfChange
     96        || (position == positionOfChange
     97            && (op == QTextUndoCommand::KeepCursor
     98                || anchor < position)
     99            )
     100         ) {
    97101        result = CursorUnchanged;
    98102    } else {
     
    126130void QTextCursorPrivate::setX()
    127131{
    128     if (priv && priv->isInEditBlock()) {
     132    if (priv->isInEditBlock()) {
    129133        x = -1; // mark dirty
    130134        return;
     
    146150    if (anchor == position)
    147151        return;
    148     priv->beginEditBlock();
    149152    currentCharFormat = -1;
    150153    int pos1 = position;
     
    160163    QTextTable *table = complexSelectionTable();
    161164    if (table) {
     165        priv->beginEditBlock();
    162166        int startRow, startCol, numRows, numCols;
    163167        selectedTableCells(&startRow, &numRows, &startCol, &numCols);
    164168        clearCells(table, startRow, startCol, numRows, numCols, op);
     169        adjusted_anchor = anchor = position;
     170        priv->endEditBlock();
    165171    } else {
    166172        priv->remove(pos1, pos2-pos1, op);
    167     }
    168 
    169     adjusted_anchor = anchor = position;
    170     priv->endEditBlock();
     173        adjusted_anchor = anchor = position;
     174        priv->finishEdit();
     175    }
     176
    171177}
    172178
     
    854860    \brief The QTextCursor class offers an API to access and modify QTextDocuments.
    855861
    856     \ingroup text
     862    \ingroup richtext-processing
    857863    \ingroup shared
    858     \mainclass
     864
    859865
    860866    Text cursors are objects that are used to access and modify the contents
     
    10751081
    10761082/*!
    1077     Makes a copy of \a cursor and assigns it to this QTextCursor.
     1083    Makes a copy of \a cursor and assigns it to this QTextCursor. Note
     1084    that QTextCursor is an \l{Implicitly Shared Classes}{implicitly
     1085    shared} class.
     1086
    10781087 */
    10791088QTextCursor &QTextCursor::operator=(const QTextCursor &cursor)
     
    12891298    format.clearProperty(QTextFormat::ObjectIndex);
    12901299
    1291     d->priv->beginEditBlock();
    1292 
    1293     d->remove();
     1300    bool hasEditBlock = false;
     1301
     1302    if (d->anchor != d->position) {
     1303        hasEditBlock = true;
     1304        d->priv->beginEditBlock();
     1305        d->remove();
     1306    }
     1307
    12941308    if (!text.isEmpty()) {
    12951309        QTextFormatCollection *formats = d->priv->formatCollection();
     
    13191333            if (ch == QLatin1Char('\n')
    13201334                || ch == QChar::ParagraphSeparator
     1335                || ch == QTextBeginningOfFrame
     1336                || ch == QTextEndOfFrame
    13211337                || ch == QLatin1Char('\r')) {
     1338
     1339                if (!hasEditBlock) {
     1340                    hasEditBlock = true;
     1341                    d->priv->beginEditBlock();
     1342                }
    13221343
    13231344                if (blockEnd > blockStart)
     
    13311352            d->priv->insert(d->position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
    13321353    }
    1333     d->priv->endEditBlock();
     1354    if (hasEditBlock)
     1355        d->priv->endEditBlock();
    13341356    d->setX();
    13351357}
     
    13461368        return;
    13471369
    1348     if (d->position == d->anchor) {
    1349         if (!d->canDelete(d->position))
    1350             return;
    1351         d->adjusted_anchor = d->anchor =
    1352                              d->priv->nextCursorPosition(d->anchor, QTextLayout::SkipCharacters);
    1353     }
     1370    if (d->position != d->anchor) {
     1371        removeSelectedText();
     1372        return;
     1373    }
     1374
     1375    if (!d->canDelete(d->position))
     1376        return;
     1377    d->adjusted_anchor = d->anchor =
     1378                         d->priv->nextCursorPosition(d->anchor, QTextLayout::SkipCharacters);
    13541379    d->remove();
    13551380    d->setX();
     
    13661391    if (!d || !d->priv)
    13671392        return;
    1368 
    1369     if (d->position == d->anchor) {
    1370         if (d->anchor < 1 || !d->canDelete(d->anchor-1))
    1371             return;
    1372         d->anchor--;
    1373 
    1374         QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor);
    1375         const QTextFragmentData * const frag = fragIt.value();
    1376         int fpos = fragIt.position();
    1377         QChar uc = d->priv->buffer().at(d->anchor - fpos + frag->stringPosition);
    1378         if (d->anchor > fpos && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
    1379             // second half of a surrogate, check if we have the first half as well,
    1380             // if yes delete both at once
    1381             uc = d->priv->buffer().at(d->anchor - 1 - fpos + frag->stringPosition);
    1382             if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
    1383                 --d->anchor;
    1384         }
    1385 
    1386         d->adjusted_anchor = d->anchor;
    1387     }
    1388 
     1393   
     1394    if (d->position != d->anchor) {
     1395        removeSelectedText();
     1396        return;
     1397    }
     1398   
     1399    if (d->anchor < 1 || !d->canDelete(d->anchor-1))
     1400        return;
     1401    d->anchor--;
     1402   
     1403    QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor);
     1404    const QTextFragmentData * const frag = fragIt.value();
     1405    int fpos = fragIt.position();
     1406    QChar uc = d->priv->buffer().at(d->anchor - fpos + frag->stringPosition);
     1407    if (d->anchor > fpos && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
     1408        // second half of a surrogate, check if we have the first half as well,
     1409        // if yes delete both at once
     1410        uc = d->priv->buffer().at(d->anchor - 1 - fpos + frag->stringPosition);
     1411        if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
     1412            --d->anchor;
     1413    }
     1414   
     1415    d->adjusted_anchor = d->anchor;
    13891416    d->remove();
    13901417    d->setX();
     
    15021529        return;
    15031530
     1531    d->priv->beginEditBlock();
    15041532    d->remove();
     1533    d->priv->endEditBlock();
    15051534    d->setX();
    15061535}
     
    18341863
    18351864/*!
     1865    \since 4.6
     1866
    18361867    Returns true if the cursor is at the end of the document;
    18371868    otherwise returns false.
Note: See TracChangeset for help on using the changeset viewer.