summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2017-07-17 12:41:37 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2017-07-20 12:35:10 +0000
commitc8a543b949bd86540ccd6e05d421ee90735211fb (patch)
tree3b5bb007dc30af2a7768c7dc83f874204512fb8b
parentf77dfd64d5052d783d5a43e171eeba91998f1148 (diff)
downloadqt-creator-c8a543b949bd86540ccd6e05d421ee90735211fb.tar.gz
TextEditor: Make TabSettings accessible for AutoCompleters
Change-Id: I3591ad94ca98979c2d47585d33800a489d87eeda Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeautocompleter.cpp4
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeautocompleter.h2
-rw-r--r--src/plugins/cppeditor/cppautocompleter.cpp6
-rw-r--r--src/plugins/texteditor/autocompleter.cpp9
-rw-r--r--src/plugins/texteditor/autocompleter.h10
-rw-r--r--src/plugins/texteditor/texteditor.cpp10
6 files changed, 23 insertions, 18 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeautocompleter.cpp b/src/plugins/cmakeprojectmanager/cmakeautocompleter.cpp
index 8c2a0ba0a1..eca893b8ea 100644
--- a/src/plugins/cmakeprojectmanager/cmakeautocompleter.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeautocompleter.cpp
@@ -117,11 +117,11 @@ QString CMakeAutoCompleter::insertMatchingQuote(const QTextCursor &cursor,
return quote;
}
-int CMakeAutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
+int CMakeAutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
const QString line = cursor.block().text().trimmed();
if (line.contains(QRegExp(QStringLiteral("^(endfunction|endmacro|endif|endforeach|endwhile)\\w*\\("))))
- tabSettings.indentLine(cursor.block(), tabSettings.indentationColumn(cursor.block().text()));
+ tabSettings().indentLine(cursor.block(), tabSettings().indentationColumn(cursor.block().text()));
return 0;
}
diff --git a/src/plugins/cmakeprojectmanager/cmakeautocompleter.h b/src/plugins/cmakeprojectmanager/cmakeautocompleter.h
index ded51afc45..f61774fe23 100644
--- a/src/plugins/cmakeprojectmanager/cmakeautocompleter.h
+++ b/src/plugins/cmakeprojectmanager/cmakeautocompleter.h
@@ -43,7 +43,7 @@ public:
QChar lookAhead, bool skipChars, int *skippedChars) const override;
QString insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, bool skipChars, int *skippedChars) const override;
- int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, const TextEditor::TabSettings &tabSettings) override;
+ int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor) override;
bool contextAllowsAutoBrackets(const QTextCursor &cursor, const QString &textToInsert) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor, const QString &textToInsert) const override;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const override;
diff --git a/src/plugins/cppeditor/cppautocompleter.cpp b/src/plugins/cppeditor/cppautocompleter.cpp
index f5bb7e9e79..a1b5ca5900 100644
--- a/src/plugins/cppeditor/cppautocompleter.cpp
+++ b/src/plugins/cppeditor/cppautocompleter.cpp
@@ -431,8 +431,10 @@ void CppEditorPlugin::test_insertParagraph()
QVERIFY(!tc.isNull());
- const int blockCount = CppAutoCompleter().paragraphSeparatorAboutToBeInserted(
- tc, TextEditor::TextEditorSettings::codeStyle()->tabSettings());
+ CppAutoCompleter completer = CppAutoCompleter();
+ completer.setTabSettings(TextEditor::TextEditorSettings::codeStyle()->tabSettings());
+
+ const int blockCount = completer.paragraphSeparatorAboutToBeInserted(tc);
QCOMPARE(blockCount, expectedBlockCount);
}
diff --git a/src/plugins/texteditor/autocompleter.cpp b/src/plugins/texteditor/autocompleter.cpp
index 2e1f9d9ec7..8ac7bbb6b3 100644
--- a/src/plugins/texteditor/autocompleter.cpp
+++ b/src/plugins/texteditor/autocompleter.cpp
@@ -273,8 +273,7 @@ bool AutoCompleter::autoBackspace(QTextCursor &cursor)
return false;
}
-int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor,
- const TabSettings &tabSettings)
+int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
if (!m_autoInsertBrackets)
return 0;
@@ -302,15 +301,15 @@ int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor,
if (condition) {|
statement;
*/
- int indentation = tabSettings.indentationColumn(block.text());
+ int indentation = m_tabSettings.indentationColumn(block.text());
if (block.next().isValid()) { // not the last block
block = block.next();
//skip all empty blocks
- while (block.isValid() && tabSettings.onlySpace(block.text()))
+ while (block.isValid() && m_tabSettings.onlySpace(block.text()))
block = block.next();
if (block.isValid()
- && tabSettings.indentationColumn(block.text()) > indentation)
+ && m_tabSettings.indentationColumn(block.text()) > indentation)
return 0;
}
diff --git a/src/plugins/texteditor/autocompleter.h b/src/plugins/texteditor/autocompleter.h
index 91d5f98dc4..5d12b63b83 100644
--- a/src/plugins/texteditor/autocompleter.h
+++ b/src/plugins/texteditor/autocompleter.h
@@ -26,6 +26,7 @@
#pragma once
#include "texteditor_global.h"
+#include "tabsettings.h"
#include <QString>
@@ -35,8 +36,6 @@ QT_END_NAMESPACE
namespace TextEditor {
-class TabSettings;
-
class TEXTEDITOR_EXPORT AutoCompleter
{
public:
@@ -53,6 +52,9 @@ public:
void setSurroundWithQuotesEnabled(bool b) { m_surroundWithQuotes = b; }
bool isSurroundWithQuotesEnabled() const { return m_surroundWithQuotes; }
+ void setTabSettings(const TabSettings &tabSettings) { m_tabSettings = tabSettings; }
+ const TabSettings &tabSettings() const { return m_tabSettings; }
+
// Returns the text to complete at the cursor position, or an empty string
virtual QString autoComplete(QTextCursor &cursor, const QString &text, bool skipChars) const;
@@ -60,8 +62,7 @@ public:
virtual bool autoBackspace(QTextCursor &cursor);
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
- virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor,
- const TabSettings &tabSettings);
+ virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
virtual bool contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
@@ -94,6 +95,7 @@ private:
QString replaceSelection(QTextCursor &cursor, const QString &textToInsert) const;
private:
+ TabSettings m_tabSettings;
mutable bool m_allowSkippingOfBlockEnd;
bool m_autoInsertBrackets;
bool m_surroundWithBrackets;
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index ba1dd248bd..aa917a2222 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -2247,9 +2247,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
const TypingSettings &tps = d->m_document->typingSettings();
cursor.beginEditBlock();
- int extraBlocks =
- d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor,
- d->m_document->tabSettings());
+ int extraBlocks = d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor);
QString previousIndentationString;
if (tps.m_autoIndent) {
@@ -3160,7 +3158,10 @@ void TextEditorWidgetPrivate::setupDocumentSignals()
this, &TextEditorWidgetPrivate::documentReloadFinished);
QObject::connect(m_document.data(), &TextDocument::tabSettingsChanged,
- this, &TextEditorWidgetPrivate::updateTabStops);
+ this, [this](){
+ updateTabStops();
+ m_autoCompleter->setTabSettings(m_document->tabSettings());
+ });
QObject::connect(m_document.data(), &TextDocument::fontSettingsChanged,
this, &TextEditorWidgetPrivate::applyFontSettingsDelayed);
@@ -8242,6 +8243,7 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
widget->setAutoCompleter(m_autoCompleterCreator());
widget->setTextDocument(document);
+ widget->autoCompleter()->setTabSettings(document->tabSettings());
widget->d->m_hoverHandlers = m_hoverHandlers;
widget->d->m_codeAssistant.configure(widget);