forked from qt-creator/qt-creator
CPlusPlus: Simplify MatchingText interface
Change-Id: I46878d9ca048d0c79032445f5adc27c12d27f30c Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -102,7 +102,7 @@ bool MatchingText::shouldInsertMatchingText(QChar lookAhead)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
|
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
|
||||||
QChar la, int *skippedChars) const
|
QChar la, int *skippedChars)
|
||||||
{
|
{
|
||||||
QTextCursor tc = cursor;
|
QTextCursor tc = cursor;
|
||||||
QTextDocument *doc = tc.document();
|
QTextDocument *doc = tc.document();
|
||||||
@@ -193,7 +193,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MatchingText::shouldInsertNewline(const QTextCursor &tc) const
|
static bool shouldInsertNewline(const QTextCursor &tc)
|
||||||
{
|
{
|
||||||
QTextDocument *doc = tc.document();
|
QTextDocument *doc = tc.document();
|
||||||
int pos = tc.selectionEnd();
|
int pos = tc.selectionEnd();
|
||||||
@@ -205,17 +205,14 @@ bool MatchingText::shouldInsertNewline(const QTextCursor &tc) const
|
|||||||
|
|
||||||
if (! ch.isSpace())
|
if (! ch.isSpace())
|
||||||
break;
|
break;
|
||||||
else if (ch == QChar::ParagraphSeparator)
|
if (ch == QChar::ParagraphSeparator)
|
||||||
++newlines;
|
++newlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newlines <= 1 && doc->characterAt(pos) != QLatin1Char('}'))
|
return newlines <= 1 && doc->characterAt(pos) != QLatin1Char('}');
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
|
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc)
|
||||||
{
|
{
|
||||||
BackwardsScanner tk(tc, MAX_NUM_LINES);
|
BackwardsScanner tk(tc, MAX_NUM_LINES);
|
||||||
int index = tk.startToken();
|
int index = tk.startToken();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CPLUSPLUS_MATCHINGTEXT_H
|
#ifndef CPLUSPLUS_MATCHINGTEXT_H
|
||||||
#define CPLUSPLUS_MATCHINGTEXT_H
|
#define CPLUSPLUS_MATCHINGTEXT_H
|
||||||
|
|
||||||
@@ -42,12 +43,9 @@ public:
|
|||||||
static bool shouldInsertMatchingText(const QTextCursor &tc);
|
static bool shouldInsertMatchingText(const QTextCursor &tc);
|
||||||
static bool shouldInsertMatchingText(QChar lookAhead);
|
static bool shouldInsertMatchingText(QChar lookAhead);
|
||||||
|
|
||||||
QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
static QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
||||||
QChar la, int *skippedChars) const;
|
QChar la, int *skippedChars);
|
||||||
QString insertParagraphSeparator(const QTextCursor &tc) const;
|
static QString insertParagraphSeparator(const QTextCursor &tc);
|
||||||
|
|
||||||
private:
|
|
||||||
bool shouldInsertNewline(const QTextCursor &tc) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CPlusPlus
|
} // namespace CPlusPlus
|
||||||
|
|||||||
@@ -128,13 +128,11 @@ QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
|
|||||||
QChar la,
|
QChar la,
|
||||||
int *skippedChars) const
|
int *skippedChars) const
|
||||||
{
|
{
|
||||||
MatchingText m;
|
return MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
|
||||||
return m.insertMatchingBrace(cursor, text, la, skippedChars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
MatchingText m;
|
return MatchingText::insertParagraphSeparator(cursor);
|
||||||
return m.insertParagraphSeparator(cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,14 +124,12 @@ QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
|
|||||||
QChar la,
|
QChar la,
|
||||||
int *skippedChars) const
|
int *skippedChars) const
|
||||||
{
|
{
|
||||||
MatchingText m;
|
return MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
|
||||||
return m.insertMatchingBrace(cursor, text, la, skippedChars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
MatchingText m;
|
return MatchingText::insertParagraphSeparator(cursor);
|
||||||
return m.insertParagraphSeparator(cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user