forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user