2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-11-08 16:11:26 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
2017-07-17 12:41:37 +02:00
|
|
|
#include "tabsettings.h"
|
2010-11-08 16:11:26 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2017-07-17 12:57:23 +02:00
|
|
|
class QTextBlock;
|
2010-11-08 16:11:26 +01:00
|
|
|
class QTextCursor;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT AutoCompleter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AutoCompleter();
|
|
|
|
|
virtual ~AutoCompleter();
|
|
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
void setAutoInsertBracketsEnabled(bool b) { m_autoInsertBrackets = b; }
|
|
|
|
|
bool isAutoInsertBracketsEnabled() const { return m_autoInsertBrackets; }
|
|
|
|
|
void setSurroundWithBracketsEnabled(bool b) { m_surroundWithBrackets = b; }
|
|
|
|
|
bool isSurroundWithBracketsEnabled() const { return m_surroundWithBrackets; }
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
void setAutoInsertQuotesEnabled(bool b) { m_autoInsertQuotes = b; }
|
|
|
|
|
bool isAutoInsertQuotesEnabled() const { return m_autoInsertQuotes; }
|
|
|
|
|
void setSurroundWithQuotesEnabled(bool b) { m_surroundWithQuotes = b; }
|
|
|
|
|
bool isSurroundWithQuotesEnabled() const { return m_surroundWithQuotes; }
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2019-05-15 21:50:28 -07:00
|
|
|
void setOverwriteClosingCharsEnabled(bool b) { m_overwriteClosingChars = b; }
|
|
|
|
|
bool isOverwriteClosingCharsEnabled() const { return m_overwriteClosingChars; }
|
|
|
|
|
|
2017-07-17 12:41:37 +02:00
|
|
|
void setTabSettings(const TabSettings &tabSettings) { m_tabSettings = tabSettings; }
|
|
|
|
|
const TabSettings &tabSettings() const { return m_tabSettings; }
|
|
|
|
|
|
2010-11-30 14:14:33 +01:00
|
|
|
// Returns the text to complete at the cursor position, or an empty string
|
2016-06-10 15:13:38 +02:00
|
|
|
virtual QString autoComplete(QTextCursor &cursor, const QString &text, bool skipChars) const;
|
2010-11-30 14:14:33 +01:00
|
|
|
|
|
|
|
|
// Handles backspace. When returning true, backspace processing is stopped
|
|
|
|
|
virtual bool autoBackspace(QTextCursor &cursor);
|
|
|
|
|
|
|
|
|
|
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
|
2017-07-17 12:41:37 +02:00
|
|
|
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
virtual bool contextAllowsAutoBrackets(const QTextCursor &cursor,
|
2010-11-30 14:14:33 +01:00
|
|
|
const QString &textToInsert = QString()) const;
|
2016-04-14 09:00:05 +02:00
|
|
|
virtual bool contextAllowsAutoQuotes(const QTextCursor &cursor,
|
|
|
|
|
const QString &textToInsert = QString()) const;
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
// Returns true if the cursor is inside a comment.
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual bool isInComment(const QTextCursor &cursor) const;
|
|
|
|
|
|
2014-09-29 18:19:38 +02:00
|
|
|
// Returns true if the cursor is inside a string.
|
|
|
|
|
virtual bool isInString(const QTextCursor &cursor) const;
|
|
|
|
|
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual QString insertMatchingBrace(const QTextCursor &cursor, const
|
|
|
|
|
QString &text,
|
2016-06-10 15:13:38 +02:00
|
|
|
QChar lookAhead, bool skipChars,
|
2016-04-14 09:00:05 +02:00
|
|
|
int *skippedChars) const;
|
|
|
|
|
|
|
|
|
|
virtual QString insertMatchingQuote(const QTextCursor &cursor, const
|
|
|
|
|
QString &text,
|
2016-06-10 15:13:38 +02:00
|
|
|
QChar lookAhead, bool skipChars,
|
2010-11-30 14:14:33 +01:00
|
|
|
int *skippedChars) const;
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
// Returns the text that needs to be inserted
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
|
|
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
static bool isQuote(const QString &text);
|
2017-07-17 12:57:23 +02:00
|
|
|
bool isNextBlockIndented(const QTextBlock ¤tBlock) const;
|
2016-04-14 09:00:05 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString replaceSelection(QTextCursor &cursor, const QString &textToInsert) const;
|
|
|
|
|
|
2010-11-08 16:11:26 +01:00
|
|
|
private:
|
2017-07-17 12:41:37 +02:00
|
|
|
TabSettings m_tabSettings;
|
2010-11-30 14:14:33 +01:00
|
|
|
mutable bool m_allowSkippingOfBlockEnd;
|
2016-04-14 09:00:05 +02:00
|
|
|
bool m_autoInsertBrackets;
|
|
|
|
|
bool m_surroundWithBrackets;
|
|
|
|
|
bool m_autoInsertQuotes;
|
|
|
|
|
bool m_surroundWithQuotes;
|
2019-05-15 21:50:28 -07:00
|
|
|
bool m_overwriteClosingChars;
|
2010-11-08 16:11:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // TextEditor
|