diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 481020581ac7c33ccc38d39bd9e5915214109d23..80bbef57be40510e1e25d028b77a724d35969f19 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -58,6 +58,7 @@ #include <texteditor/texteditorconstants.h> #include <texteditor/tabsettings.h> #include <texteditor/texteditorsettings.h> +#include <texteditor/indenter.h> #include <find/findplugin.h> #include <find/textfindconstants.h> @@ -935,7 +936,7 @@ void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c) 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) @@ -1132,7 +1133,7 @@ void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine, while (!cursor.atBlockEnd()) cursor.deleteChar(); } else { - bt->indentBlock(doc, block, typedChar); + bt->indenter()->indentBlock(doc, block, typedChar, bt); } block = block.next(); } diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index f2fe088e6c5f37d5d48eef0c4464fe751049120a..d505d1ebfe23513eb97fa6ad4c3d76acae471f8c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1344,7 +1344,7 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) 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; } @@ -1890,6 +1890,11 @@ void BaseTextEditor::setIndenter(Indenter *indenter) d->m_indenter.reset(indenter); } +Indenter *BaseTextEditor::indenter() const +{ + return d->m_indenter.data(); +} + void BaseTextEditor::setAutoCompleter(AutoCompleter *autoCompleter) { d->m_autoCompleter.reset(autoCompleter); @@ -1949,7 +1954,8 @@ BaseTextEditorPrivate::BaseTextEditorPrivate() m_requestAutoCompletionPosition(0), m_requestAutoCompletionTimer(0), m_cursorBlockNumber(-1), - m_autoCompleter(new AutoCompleter) + m_autoCompleter(new AutoCompleter), + m_indenter(new Indenter) { } @@ -4019,13 +4025,6 @@ void BaseTextEditor::zoomReset() 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); @@ -4247,24 +4246,16 @@ int BaseTextEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor) 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) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index ba2c4d1d4c4740e2a457affa388844dadb11a94d..b17199d9726b2c68963e7b1debe21f4ef86568db 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -225,6 +225,7 @@ public: QRegion translatedLineRegion(int lineStart, int lineEnd) const; void setIndenter(Indenter *indenter); + Indenter *indenter() const; void setAutoCompleter(AutoCompleter *autoCompleter); AutoCompleter *autoCompleter() const; @@ -424,14 +425,8 @@ public: 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); diff --git a/src/plugins/texteditor/indenter.cpp b/src/plugins/texteditor/indenter.cpp index 8007b4209e20dd32cc0763364283c3b30901ce28..97ae9ebf17cfa0863dde99e736313018b694dd9d 100644 --- a/src/plugins/texteditor/indenter.cpp +++ b/src/plugins/texteditor/indenter.cpp @@ -70,6 +70,17 @@ bool Indenter::doIsElectricalCharacter(const QChar &) const 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()) { diff --git a/src/plugins/texteditor/indenter.h b/src/plugins/texteditor/indenter.h index 3a58f5691258f3502fb27740bb7c4f192bc18d6b..22a95b888ed3602ad058b73608060502f8d2d484 100644 --- a/src/plugins/texteditor/indenter.h +++ b/src/plugins/texteditor/indenter.h @@ -50,15 +50,20 @@ public: 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: @@ -66,7 +71,7 @@ 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,