#include <texteditor/texteditorconstants.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorsettings.h>
+#include <texteditor/indenter.h>
#include <find/findplugin.h>
#include <find/textfindconstants.h>
if (!handler)
return;
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget()))
- *result = bt->isElectricCharacter(c);
+ *result = bt->indenter()->isElectricCharacter(c);
}
void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
while (!cursor.atBlockEnd())
cursor.deleteChar();
} else {
- bt->indentBlock(doc, block, typedChar);
+ bt->indenter()->indentBlock(doc, block, typedChar, bt);
}
block = block.next();
}
QChar electricChar;
if (d->m_document->tabSettings().m_autoIndent) {
foreach (QChar c, text) {
- if (isElectricCharacter(c)) {
+ if (d->m_indenter->isElectricCharacter(c)) {
electricChar = c;
break;
}
d->m_indenter.reset(indenter);
}
+Indenter *BaseTextEditor::indenter() const
+{
+ return d->m_indenter.data();
+}
+
void BaseTextEditor::setAutoCompleter(AutoCompleter *autoCompleter)
{
d->m_autoCompleter.reset(autoCompleter);
m_requestAutoCompletionPosition(0),
m_requestAutoCompletionTimer(0),
m_cursorBlockNumber(-1),
- m_autoCompleter(new AutoCompleter)
+ m_autoCompleter(new AutoCompleter),
+ m_indenter(new Indenter)
{
}
emit requestZoomReset();
}
-bool BaseTextEditor::isElectricCharacter(QChar ch) const
-{
- if (!d->m_indenter.isNull())
- return d->m_indenter->isElectricCharacter(ch);
- return false;
-}
-
void BaseTextEditor::indentInsertedText(const QTextCursor &tc)
{
indent(tc.document(), tc, QChar::Null);
return 1;
}
-void BaseTextEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar ch)
-{
- if (!d->m_indenter.isNull())
- d->m_indenter->indentBlock(doc, block, ch, this);
-}
-
void BaseTextEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
{
maybeClearSomeExtraSelections(cursor);
- if (!d->m_indenter.isNull())
- d->m_indenter->indent(doc, cursor, typedChar, this);
+ d->m_indenter->indent(doc, cursor, typedChar, this);
}
void BaseTextEditor::reindent(QTextDocument *doc, const QTextCursor &cursor)
{
maybeClearSomeExtraSelections(cursor);
- if (!d->m_indenter.isNull())
- d->m_indenter->reindent(doc, cursor, this);
+ d->m_indenter->reindent(doc, cursor, this);
}
BaseTextEditor::Link BaseTextEditor::findLinkAt(const QTextCursor &, bool)
QRegion translatedLineRegion(int lineStart, int lineEnd) const;
void setIndenter(Indenter *indenter);
+ Indenter *indenter() const;
void setAutoCompleter(AutoCompleter *autoCompleter);
AutoCompleter *autoCompleter() const;
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
void indentInsertedText(const QTextCursor &tc);
- // Returns true if key triggers an indent.
- virtual bool isElectricCharacter(QChar ch) const;
- // Indent a text block based on previous line. Default does nothing
- virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
- // Indent at cursor. Calls indentBlock for selection or current line.
- virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
- // Reindent at cursor. Selection will be adjusted according to the indentation change of the first block
- virtual void reindent(QTextDocument *doc, const QTextCursor &cursor);
+ void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
+ void reindent(QTextDocument *doc, const QTextCursor &cursor);
protected:
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
return false;
}
+void Indenter::doIndentBlock(QTextDocument *doc,
+ const QTextBlock &block,
+ const QChar &typedChar,
+ BaseTextEditor *editor)
+{
+ Q_UNUSED(doc);
+ Q_UNUSED(block);
+ Q_UNUSED(typedChar);
+ Q_UNUSED(editor);
+}
+
void Indenter::doIndent(QTextDocument *doc, const QTextCursor &cursor, const QChar &typedChar, BaseTextEditor *editor)
{
if (cursor.hasSelection()) {
Indenter();
virtual ~Indenter();
+ // Returns true if key triggers an indent.
bool isElectricCharacter(const QChar &ch) const;
+ // Indent a text block based on previous line. Default does nothing
void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
BaseTextEditor *editor);
+ // Indent at cursor. Calls indentBlock for selection or current line.
void indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
BaseTextEditor *editor);
+ // Reindent at cursor. Selection will be adjusted according to the indentation
+ // change of the first block.
void reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextEditor *editor);
private:
virtual void doIndentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- BaseTextEditor *editor) = 0;
+ BaseTextEditor *editor);
virtual void doIndent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,