summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qtextdocument_p.cpp')
-rw-r--r--src/gui/text/qtextdocument_p.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index a31e9d3..39d0e6c 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -209,6 +209,7 @@ QTextDocumentPrivate::QTextDocumentPrivate()
defaultTextOption.setTabStop(80); // same as in qtextengine.cpp
defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ defaultCursorMoveStyle = Qt::LogicalMoveStyle;
indentWidth = 40;
documentMargin = 4;
@@ -1383,6 +1384,20 @@ int QTextDocumentPrivate::previousCursorPosition(int position, QTextLayout::Curs
return it.layout()->previousCursorPosition(position-start, mode) + start;
}
+int QTextDocumentPrivate::leftCursorPosition(int position) const
+{
+ QTextBlock it = blocksFind(position);
+ int start = it.position();
+ return it.layout()->leftCursorPosition(position-start) + start;
+}
+
+int QTextDocumentPrivate::rightCursorPosition(int position) const
+{
+ QTextBlock it = blocksFind(position);
+ int start = it.position();
+ return it.layout()->rightCursorPosition(position-start) + start;
+}
+
void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)
{
beginEditBlock();
@@ -1407,11 +1422,18 @@ void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)
static QTextFrame *findChildFrame(QTextFrame *f, int pos)
{
- // ##### use binary search
- QList<QTextFrame *> children = f->childFrames();
- for (int i = 0; i < children.size(); ++i) {
- QTextFrame *c = children.at(i);
- if (pos >= c->firstPosition() && pos <= c->lastPosition())
+ /* Binary search for frame at pos */
+ const QList<QTextFrame *> children = f->childFrames();
+ int first = 0;
+ int last = children.size() - 1;
+ while (first <= last) {
+ int mid = (first + last) / 2;
+ QTextFrame *c = children.at(mid);
+ if (pos > c->lastPosition())
+ first = mid + 1;
+ else if (pos < c->firstPosition())
+ last = mid - 1;
+ else
return c;
}
return 0;