summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx/qfxtextedit.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-09 03:01:21 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-09 03:01:21 (GMT)
commit25b603c4dcbe5452f37fec17afe26e8689bc618c (patch)
tree59c948216366e8bd54a5cececb52d56bad834b4f /src/declarative/fx/qfxtextedit.cpp
parentabc26ed574f53d19165810d64d998f2a6fa8f20b (diff)
downloadQt-25b603c4dcbe5452f37fec17afe26e8689bc618c.zip
Qt-25b603c4dcbe5452f37fec17afe26e8689bc618c.tar.gz
Qt-25b603c4dcbe5452f37fec17afe26e8689bc618c.tar.bz2
selectionStart/End now work properly
Autotests still in progress
Diffstat (limited to 'src/declarative/fx/qfxtextedit.cpp')
-rw-r--r--src/declarative/fx/qfxtextedit.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp
index d3b6fab..caa48cf 100644
--- a/src/declarative/fx/qfxtextedit.cpp
+++ b/src/declarative/fx/qfxtextedit.cpp
@@ -551,7 +551,8 @@ void QFxTextEdit::loadCursorDelegate()
text edit.
Note that if selectionStart == selectionEnd then there is no current
- selection.
+ selection. If you attempt to set selectionStart to a value outside of
+ the current text, selectionStart will not be changed.
\sa selectionEnd, cursorPosition, selectedText
*/
@@ -564,7 +565,7 @@ int QFxTextEdit::selectionStart() const
void QFxTextEdit::setSelectionStart(int s)
{
Q_D(QFxTextEdit);
- if(d->lastSelectionStart == s)
+ if(d->lastSelectionStart == s || s < 0 || s > text().length())
return;
d->lastSelectionStart = s;
d->updateSelection();// Will emit the relevant signals
@@ -578,7 +579,8 @@ void QFxTextEdit::setSelectionStart(int s)
text edit.
Note that if selectionStart == selectionEnd then there is no current
- selection.
+ selection. If you attempt to set selectionEnd to a value outside of
+ the current text, selectionEnd will not be changed.
\sa selectionStart, cursorPosition, selectedText
*/
@@ -591,7 +593,7 @@ int QFxTextEdit::selectionEnd() const
void QFxTextEdit::setSelectionEnd(int s)
{
Q_D(QFxTextEdit);
- if(d->lastSelectionEnd == s)
+ if(d->lastSelectionEnd == s || s < 0 || s > text().length())
return;
d->lastSelectionEnd = s;
d->updateSelection();// Will emit the relevant signals
@@ -1075,21 +1077,13 @@ void QFxTextEdit::moveCursorDelegate()
void QFxTextEditPrivate::updateSelection()
{
Q_Q(QFxTextEdit);
- bool startChange = (lastSelectionStart != control->textCursor().selectionStart());
- bool endChange = (lastSelectionEnd != control->textCursor().selectionEnd());
- if(startChange){
- //### Does this generate spurious intermediate signals?
- control->textCursor().setPosition(lastSelectionStart, QTextCursor::MoveAnchor);
- control->textCursor().setPosition(lastSelectionEnd, QTextCursor::KeepAnchor);
- }else if(endChange){
- int n = lastSelectionEnd - control->textCursor().selectionEnd();
- if(n > 0)
- control->textCursor().movePosition(QTextCursor::NextCharacter,
- QTextCursor::KeepAnchor, n);
- else
- control->textCursor().movePosition(QTextCursor::PreviousCharacter,
- QTextCursor::KeepAnchor, -n);
- }
+ QTextCursor cursor = control->textCursor();
+ bool startChange = (lastSelectionStart != cursor.selectionStart());
+ bool endChange = (lastSelectionEnd != cursor.selectionEnd());
+ //### Is it worth calculating a more minimal set of movements?
+ cursor.setPosition(lastSelectionStart, QTextCursor::MoveAnchor);
+ cursor.setPosition(lastSelectionEnd, QTextCursor::KeepAnchor);
+ control->setTextCursor(cursor);
if(startChange)
q->selectionStartChanged();
if(endChange)