Commit c4532125 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added indenting of dirty areas.

parent 3efdb876
......@@ -43,6 +43,8 @@ public:
virtual void replace(int offset, int length, const QString& replacement);
virtual void move(const MoveInfo &moveInfo);
virtual void indent(int offset, int length);
virtual void startGroup();
virtual void flushGroup();
virtual void commitGroup();
......
......@@ -64,6 +64,8 @@ public:
virtual void replace(int offset, int length, const QString &replacement);
virtual void move(const MoveInfo &moveInfo);
virtual void indent(int offset, int length);
virtual void startGroup();
virtual void flushGroup();
virtual void commitGroup();
......
......@@ -68,6 +68,8 @@ public:
virtual void replace(int offset, int length, const QString& replacement) = 0;
virtual void move(const MoveInfo &moveInfo) = 0;
virtual void indent(int offset, int length) = 0;
virtual void startGroup() = 0;
virtual void flushGroup() = 0;
virtual void commitGroup() = 0;
......
......@@ -58,6 +58,11 @@ void ComponentTextModifier::move(const MoveInfo &moveInfo)
m_originalModifier->move(moveInfo);
}
void ComponentTextModifier::indent(int offset, int length)
{
m_originalModifier->indent(offset, length);
}
void ComponentTextModifier::startGroup()
{
m_originalModifier->startGroup();
......
......@@ -287,15 +287,16 @@ void ModelToTextMerger::applyChanges()
}
}
void ModelToTextMerger::reindent(const QMap<int, int> &/*dirtyAreas*/) const
void ModelToTextMerger::reindent(const QMap<int, int> &dirtyAreas) const
{
// QList<int> offsets = dirtyAreas.keys();
// qSort(offsets);
//
// foreach (const int offset, offsets) {
// const int length = dirtyAreas[offset];
// xxxx
// }
QList<int> offsets = dirtyAreas.keys();
qSort(offsets);
TextModifier *textModifier = m_rewriterView->textModifier();
foreach (const int offset, offsets) {
const int length = dirtyAreas[offset];
textModifier->indent(offset, length);
}
}
void ModelToTextMerger::schedule(RewriteAction *action)
......
......@@ -27,14 +27,15 @@
**
**************************************************************************/
#include <QtCore/QDebug>
#include "plaintexteditmodifier.h"
#include <texteditor/basetexteditor.h>
#include <utils/changeset.h>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QUndoStack>
#include <utils/changeset.h>
#include "plaintexteditmodifier.h"
#include <QtCore/QDebug>
using namespace Utils;
using namespace QmlDesigner;
......@@ -112,6 +113,27 @@ void PlainTextEditModifier::move(const MoveInfo &moveInfo)
}
}
void PlainTextEditModifier::indent(int offset, int length)
{
if (length == 0 || offset < 0 || offset + length >= text().length())
return;
// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")";
if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(m_textEdit)) {
// qDebug() << "**** Doing indentation";
// find the applicable block:
QTextDocument *doc = bte->document();
QTextCursor tc(doc);
tc.beginEditBlock();
tc.setPosition(offset);
tc.setPosition(offset + length, QTextCursor::KeepAnchor);
bte->indentInsertedText(tc);
tc.endEditBlock();
} else {
// qDebug() << "**** Skipping indentation";
}
}
void PlainTextEditModifier::startGroup()
{
if (!m_changeSet)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment