C++: Fine-tune auto insertion of '}'

Do not insert for these cases:
 * <Cursor>{
 * namespace X <Cursor>
 * if the next block is indented, like e.g.:
     if (e) <Cursor>
        g();
 * on empty line if text before looks like a finished statement or
   scope opening/end

Change-Id: Id9decc1e964a775724a929c2a3e79b5283105560
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-07-17 12:57:23 +02:00
parent 2c9feb1f4b
commit a6aa287720
6 changed files with 343 additions and 59 deletions

View File

@@ -30,7 +30,10 @@
#include <cplusplus/Token.h>
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <functional>
QT_FORWARD_DECLARE_CLASS(QTextCursor)
QT_FORWARD_DECLARE_CLASS(QTextBlock)
QT_FORWARD_DECLARE_CLASS(QChar)
namespace CPlusPlus {
@@ -38,8 +41,11 @@ namespace CPlusPlus {
class CPLUSPLUS_EXPORT MatchingText
{
public:
using IsNextBlockDeeperIndented = std::function<bool(const QTextBlock &textBlock)>;
static bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert);
const QString &textToInsert,
IsNextBlockDeeperIndented isNextIndented
= IsNextBlockDeeperIndented());
static bool contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert);
static bool contextAllowsElectricCharacters(const QTextCursor &cursor);