summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-06-01 12:38:18 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-06-01 12:38:18 +0200
commit8d6ac1a041eb26f635914b1c356f47e50cdfdc98 (patch)
treef317c39984d948391db4cfdc20bfa6fdc8f9aa0c /src/gui/text
parent8709ff7920a378c91ce754a39cae4016709e9e00 (diff)
Defines whether the cursor should keep its current position.
Defines whether the cursor should keep its position when text gets inserted at the current position of the cursor. For example, we don't want QTextCursor to extend the selection when inserting characters at the end of an extra selection representing a user-type but we do want the selection to grow when rewriting a region of code (e.g. when using our QuickFix engine). Task-number: QTBUG-11075 Reviewed-by: mae
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextcursor.cpp52
-rw-r--r--src/gui/text/qtextcursor.h3
-rw-r--r--src/gui/text/qtextcursor_p.h3
3 files changed, 51 insertions, 7 deletions
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index c91df3cadf..abc08899f6 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -64,7 +64,7 @@ enum {
QTextCursorPrivate::QTextCursorPrivate(QTextDocumentPrivate *p)
: priv(p), x(0), position(0), anchor(0), adjusted_anchor(0),
- currentCharFormat(-1), visualNavigation(false)
+ currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false)
{
priv->addCursor(this);
}
@@ -79,6 +79,7 @@ QTextCursorPrivate::QTextCursorPrivate(const QTextCursorPrivate &rhs)
x = rhs.x;
currentCharFormat = rhs.currentCharFormat;
visualNavigation = rhs.visualNavigation;
+ keepPositionOnInsert = rhs.keepPositionOnInsert;
priv->addCursor(this);
}
@@ -95,7 +96,7 @@ QTextCursorPrivate::AdjustResult QTextCursorPrivate::adjustPosition(int position
if (position < positionOfChange
|| (position == positionOfChange
&& (op == QTextUndoCommand::KeepCursor
- || anchor < position)
+ || keepPositionOnInsert)
)
) {
result = CursorUnchanged;
@@ -1277,6 +1278,45 @@ void QTextCursor::setVisualNavigation(bool b)
}
/*!
+ \since 4.7
+
+ Returns whether the cursor should keep its current position when text gets inserted at the position of the
+ cursor.
+
+ The default is false;
+
+ \sa setKeepPositionOnInsert()
+ */
+bool QTextCursor::keepPositionOnInsert() const
+{
+ return d ? d->keepPositionOnInsert : false;
+}
+
+/*!
+ \since 4.7
+
+ Defines whether the cursor should keep its current position when text gets inserted at the current position of the
+ cursor.
+
+ If \b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor.
+ If \b is false, the cursor moves along with the inserted text.
+
+ The default is false.
+
+ Note that a cursor always moves when text is inserted before the current position of the cursor, and it
+ always keeps its position when text is inserted after the current position of the cursor.
+
+ \sa keepPositionOnInsert()
+ */
+void QTextCursor::setKeepPositionOnInsert(bool b)
+{
+ if (d)
+ d->keepPositionOnInsert = b;
+}
+
+
+
+/*!
Inserts \a text at the current position, using the current
character format.
@@ -1408,16 +1448,16 @@ void QTextCursor::deletePreviousChar()
{
if (!d || !d->priv)
return;
-
+
if (d->position != d->anchor) {
removeSelectedText();
return;
}
-
+
if (d->anchor < 1 || !d->canDelete(d->anchor-1))
return;
d->anchor--;
-
+
QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor);
const QTextFragmentData * const frag = fragIt.value();
int fpos = fragIt.position();
@@ -1429,7 +1469,7 @@ void QTextCursor::deletePreviousChar()
if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
--d->anchor;
}
-
+
d->adjusted_anchor = d->anchor;
d->remove();
d->setX();
diff --git a/src/gui/text/qtextcursor.h b/src/gui/text/qtextcursor.h
index 3e968a31fd..6cb776cfe5 100644
--- a/src/gui/text/qtextcursor.h
+++ b/src/gui/text/qtextcursor.h
@@ -132,6 +132,9 @@ public:
bool visualNavigation() const;
void setVisualNavigation(bool b);
+ void setKeepPositionOnInsert(bool b);
+ bool keepPositionOnInsert() const;
+
void deleteChar();
void deletePreviousChar();
diff --git a/src/gui/text/qtextcursor_p.h b/src/gui/text/qtextcursor_p.h
index 1bdfa78553..4e36b954eb 100644
--- a/src/gui/text/qtextcursor_p.h
+++ b/src/gui/text/qtextcursor_p.h
@@ -112,7 +112,8 @@ public:
int anchor;
int adjusted_anchor;
int currentCharFormat;
- bool visualNavigation;
+ uint visualNavigation : 1;
+ uint keepPositionOnInsert : 1;
};
QT_END_NAMESPACE