using namespace QQmlJS;
TextWriter::TextWriter()
- :string(0), cursor(0)
+ :string(0)
{
}
if (overlaps(pos, length, cmd.pos, cmd.length))
return true;
}
- return false;
}
+ return false;
}
bool TextWriter::hasMoveInto(int pos, int length)
}
}
- if (string) {
- string->replace(replace.pos, replace.length, replace.replacement);
- } else if (cursor) {
- cursor->setPosition(replace.pos);
- cursor->setPosition(replace.pos + replace.length, QTextCursor::KeepAnchor);
- cursor->insertText(replace.replacement);
- }
+ string->replace(replace.pos, replace.length, replace.replacement);
}
void TextWriter::doMove(const Move &move)
{
- QString text;
- if (string) {
- text = string->mid(move.pos, move.length);
- } else if (cursor) {
- cursor->setPosition(move.pos);
- cursor->setPosition(move.pos + move.length, QTextCursor::KeepAnchor);
- text = cursor->selectedText();
- }
+ QString text(string->mid(move.pos, move.length));
Replace cut;
cut.pos = move.pos;
string = 0;
}
-void TextWriter::write(QTextCursor *textCursor)
-{
- cursor = textCursor;
- write_helper();
- cursor = 0;
-}
-
void TextWriter::write_helper()
{
- if (cursor)
- cursor->beginEditBlock();
+ Q_ASSERT(string);
+
{
Replace cmd;
while (!replaceList.isEmpty()) {
doMove(cmd);
}
}
- if (cursor)
- cursor->endEditBlock();
}
QT_QML_END_NAMESPACE
#include <QtCore/QString>
#include <QtCore/QList>
-#include <QtGui/QTextCursor>
QT_BEGIN_HEADER
QT_QML_BEGIN_NAMESPACE
class TextWriter
{
QString *string;
- QTextCursor *cursor;
struct Replace {
int pos;
void move(int pos, int length, int to);
void write(QString *s);
- void write(QTextCursor *textCursor);
-
};
} // end of namespace QQmlJS