Commit 7767786c authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Disable bracket matching when automatic insertion is disabled

When automatic insertion of brackets is disabled in the completion
settings, it is reasonable to expect the automatic matching of brackets
is also disabled.

Task-number: QTCREATORBUG-454
Reviewed-by: default avatarDaniel Molkentin <daniel.molkentin@nokia.com>
parent e53b5bc9
......@@ -34,6 +34,7 @@
#include "basetexteditor_p.h"
#include "behaviorsettings.h"
#include "codecselector.h"
#include "completionsettings.h"
#include "completionsupport.h"
#include "tabsettings.h"
#include "texteditorconstants.h"
......@@ -179,7 +180,7 @@ static void convertToPlainText(QString &txt)
BaseTextEditor::BaseTextEditor(QWidget *parent)
: QPlainTextEdit(parent)
{
d = new BaseTextEditorPrivate();
d = new BaseTextEditorPrivate;
d->q = this;
d->m_extraArea = new TextEditExtraArea(this);
d->m_extraArea->setMouseTracking(true);
......@@ -195,8 +196,6 @@ BaseTextEditor::BaseTextEditor(QWidget *parent)
d->m_lastScrollPos = -1;
setCursorWidth(2);
d->m_allowSkippingOfBlockEnd = false;
// from RESEARCH
setLayoutDirection(Qt::LeftToRight);
......@@ -221,7 +220,6 @@ BaseTextEditor::BaseTextEditor(QWidget *parent)
// parentheses matcher
d->m_parenthesesMatchingEnabled = false;
d->m_formatRange = true;
d->m_matchFormat.setForeground(Qt::red);
d->m_rangeFormat.setBackground(QColor(0xb4, 0xee, 0xb4));
......@@ -1686,6 +1684,16 @@ bool BaseTextEditor::isParenthesesMatchingEnabled() const
return d->m_parenthesesMatchingEnabled;
}
void BaseTextEditor::setAutoParenthesesEnabled(bool b)
{
d->m_autoParenthesesEnabled = b;
}
bool BaseTextEditor::isAutoParenthesesEnabled() const
{
return d->m_autoParenthesesEnabled;
}
void BaseTextEditor::setHighlightCurrentLine(bool b)
{
d->m_highlightCurrentLine = b;
......@@ -1814,8 +1822,10 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
:
m_contentsChanged(false),
m_lastCursorChangeWasInteresting(false),
m_document(new BaseTextDocument()),
m_allowSkippingOfBlockEnd(false),
m_document(new BaseTextDocument),
m_parenthesesMatchingEnabled(false),
m_autoParenthesesEnabled(true),
m_extraArea(0),
m_mouseOnCollapsedMarker(false),
m_marksVisible(false),
......@@ -3866,13 +3876,16 @@ QString BaseTextEditor::autoComplete(QTextCursor &cursor, const QString &textToI
const bool checkBlockEnd = d->m_allowSkippingOfBlockEnd;
d->m_allowSkippingOfBlockEnd = false; // consume blockEnd.
if (!d->m_autoParenthesesEnabled)
return QString();
if (!contextAllowsAutoParentheses(cursor, textToInsert))
return QString();
const QString text = textToInsert;
const QChar lookAhead = characterAt(cursor.selectionEnd());
QChar character = textToInsert.at(0);
const QChar character = textToInsert.at(0);
const QString parentheses = QLatin1String("()");
const QString brackets = QLatin1String("[]");
if (parentheses.contains(character) || brackets.contains(character)) {
......@@ -3927,17 +3940,20 @@ bool BaseTextEditor::autoBackspace(QTextCursor &cursor)
{
d->m_allowSkippingOfBlockEnd = false;
if (!d->m_autoParenthesesEnabled)
return false;
int pos = cursor.position();
if (pos == 0)
return false;
QTextCursor c = cursor;
c.setPosition(pos - 1);
QChar lookAhead = characterAt(pos);
QChar lookBehind = characterAt(pos-1);
QChar lookFurtherBehind = characterAt(pos-2);
const QChar lookAhead = characterAt(pos);
const QChar lookBehind = characterAt(pos - 1);
const QChar lookFurtherBehind = characterAt(pos - 2);
QChar character = lookBehind;
const QChar character = lookBehind;
if (character == QLatin1Char('(') || character == QLatin1Char('[')) {
QTextCursor tmp = cursor;
TextEditor::TextBlockUserData::findPreviousBlockOpenParenthesis(&tmp);
......@@ -3982,7 +3998,10 @@ bool BaseTextEditor::autoBackspace(QTextCursor &cursor)
int BaseTextEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
if (characterAt(cursor.position()-1) != QLatin1Char('{'))
if (!d->m_autoParenthesesEnabled)
return 0;
if (characterAt(cursor.position() - 1) != QLatin1Char('{'))
return 0;
if (!contextAllowsAutoParentheses(cursor))
......@@ -4885,6 +4904,11 @@ void BaseTextEditor::setStorageSettings(const StorageSettings &storageSettings)
d->m_document->setStorageSettings(storageSettings);
}
void BaseTextEditor::setCompletionSettings(const TextEditor::CompletionSettings &completionSettings)
{
setAutoParenthesesEnabled(completionSettings.m_autoInsertBrackets);
}
void BaseTextEditor::collapse()
{
QTextDocument *doc = document();
......
......@@ -59,6 +59,7 @@ class BaseTextDocument;
class BaseTextEditorEditable;
class FontSettings;
struct BehaviorSettings;
struct CompletionSettings;
struct DisplaySettings;
struct StorageSettings;
struct TabSettings;
......@@ -160,13 +161,15 @@ public:
void setParenthesesMatchingEnabled(bool b);
bool isParenthesesMatchingEnabled() const;
void setAutoParenthesesEnabled(bool b);
bool isAutoParenthesesEnabled() const;
void setHighlightCurrentLine(bool b);
bool highlightCurrentLine() const;
void setLineNumbersVisible(bool b);
bool lineNumbersVisible() const;
void setMarksVisible(bool b);
bool marksVisible() const;
......@@ -363,6 +366,7 @@ public slots:
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
virtual void setStorageSettings(const TextEditor::StorageSettings &);
virtual void setCompletionSettings(const TextEditor::CompletionSettings &);
protected:
bool viewportEvent(QEvent *event);
......
......@@ -265,7 +265,6 @@ public:
int m_cursorBlockNumber;
bool m_inKeyPressEvent;
};
} // namespace Internal
......
......@@ -210,6 +210,8 @@ void TextEditorSettings::initializeEditor(BaseTextEditor *editor)
editor, SLOT(setBehaviorSettings(TextEditor::BehaviorSettings)));
connect(this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
connect(this, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
editor, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
connect(editor, SIGNAL(requestFontZoom(int)),
this, SLOT(fontZoomRequested(int)));
......@@ -222,6 +224,7 @@ void TextEditorSettings::initializeEditor(BaseTextEditor *editor)
editor->setStorageSettings(storageSettings());
editor->setBehaviorSettings(behaviorSettings());
editor->setDisplaySettings(displaySettings());
editor->setCompletionSettings(completionSettings());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment