summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2016-06-14 08:00:32 +0200
committerDavid Schulz <david.schulz@theqtcompany.com>2016-06-22 10:53:00 +0000
commit5a78fcb434619bf035eafbc2fcd6c27dc29a8dc9 (patch)
treeb58ad0479e98083110783968b1a535aa728e2964 /src/plugins
parent5988fd0f5cae56999aa389405e1fa3e0394962ed (diff)
downloadqt-creator-5a78fcb434619bf035eafbc2fcd6c27dc29a8dc9.tar.gz
Editor: Restrict deletion of automatically inserted characters.
Remove automatically inserted characters only when the cursor wasn't explicitly moved or the editor hasn't lost the focus after the completion. Change-Id: I9e995dc4ce79194b073b1bce3fa4dbc025a09a94 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/texteditor/completionsettings.cpp5
-rw-r--r--src/plugins/texteditor/completionsettings.h1
-rw-r--r--src/plugins/texteditor/completionsettingspage.cpp3
-rw-r--r--src/plugins/texteditor/completionsettingspage.ui60
-rw-r--r--src/plugins/texteditor/texteditor.cpp6
5 files changed, 69 insertions, 6 deletions
diff --git a/src/plugins/texteditor/completionsettings.cpp b/src/plugins/texteditor/completionsettings.cpp
index a012e407c2..61c9f203a8 100644
--- a/src/plugins/texteditor/completionsettings.cpp
+++ b/src/plugins/texteditor/completionsettings.cpp
@@ -41,6 +41,7 @@ static const char autoSplitStringsKey[] = "AutoSplitStrings";
static const char animateAutoCompleteKey[] = "AnimateAutoComplete";
static const char highlightAutoCompleteKey[] = "HighlightAutoComplete";
static const char skipAutoCompleteKey[] = "SkipAutoComplete";
+static const char autoRemoveKey[] = "AutoRemove";
using namespace TextEditor;
@@ -60,6 +61,7 @@ void CompletionSettings::toSettings(QSettings *s) const
s->setValue(animateAutoCompleteKey, m_animateAutoComplete);
s->setValue(highlightAutoCompleteKey, m_highlightAutoComplete);
s->setValue(skipAutoCompleteKey, m_skipAutoCompletedText);
+ s->setValue(autoRemoveKey, m_autoRemove);
s->endGroup();
}
@@ -94,6 +96,8 @@ void CompletionSettings::fromSettings(QSettings *s)
s->value(highlightAutoCompleteKey, m_highlightAutoComplete).toBool();
m_skipAutoCompletedText =
s->value(skipAutoCompleteKey, m_skipAutoCompletedText).toBool();
+ m_autoRemove =
+ s->value(autoRemoveKey, m_autoRemove).toBool();
s->endGroup();
}
@@ -112,5 +116,6 @@ bool CompletionSettings::equals(const CompletionSettings &cs) const
&& m_animateAutoComplete == cs.m_animateAutoComplete
&& m_highlightAutoComplete == cs.m_highlightAutoComplete
&& m_skipAutoCompletedText == cs.m_skipAutoCompletedText
+ && m_autoRemove == cs.m_autoRemove
;
}
diff --git a/src/plugins/texteditor/completionsettings.h b/src/plugins/texteditor/completionsettings.h
index 7ca5535b3e..9fa75e6152 100644
--- a/src/plugins/texteditor/completionsettings.h
+++ b/src/plugins/texteditor/completionsettings.h
@@ -69,6 +69,7 @@ public:
bool m_animateAutoComplete = true;
bool m_highlightAutoComplete = true;
bool m_skipAutoCompletedText = true;
+ bool m_autoRemove = true;
};
inline bool operator==(const CompletionSettings &t1, const CompletionSettings &t2) { return t1.equals(t2); }
diff --git a/src/plugins/texteditor/completionsettingspage.cpp b/src/plugins/texteditor/completionsettingspage.cpp
index 1c5d4e2dde..b824926028 100644
--- a/src/plugins/texteditor/completionsettingspage.cpp
+++ b/src/plugins/texteditor/completionsettingspage.cpp
@@ -105,6 +105,7 @@ QWidget *CompletionSettingsPage::widget()
m_page->animateAutoComplete->setChecked(m_completionSettings.m_animateAutoComplete);
m_page->highlightAutoComplete->setChecked(m_completionSettings.m_highlightAutoComplete);
m_page->skipAutoComplete->setChecked(m_completionSettings.m_skipAutoCompletedText);
+ m_page->removeAutoComplete->setChecked(m_completionSettings.m_autoRemove);
m_page->enableDoxygenCheckBox->setChecked(m_commentsSettings.m_enableDoxygen);
m_page->generateBriefCheckBox->setChecked(m_commentsSettings.m_generateBrief);
@@ -112,6 +113,7 @@ QWidget *CompletionSettingsPage::widget()
m_page->generateBriefCheckBox->setEnabled(m_page->enableDoxygenCheckBox->isChecked());
m_page->skipAutoComplete->setEnabled(m_page->highlightAutoComplete->isChecked());
+ m_page->removeAutoComplete->setEnabled(m_page->highlightAutoComplete->isChecked());
}
return m_widget;
}
@@ -182,6 +184,7 @@ void CompletionSettingsPage::settingsFromUi(CompletionSettings &completion, Comm
completion.m_animateAutoComplete = m_page->animateAutoComplete->isChecked();
completion.m_highlightAutoComplete = m_page->highlightAutoComplete->isChecked();
completion.m_skipAutoCompletedText = m_page->skipAutoComplete->isChecked();
+ completion.m_autoRemove = m_page->removeAutoComplete->isChecked();
comment.m_enableDoxygen = m_page->enableDoxygenCheckBox->isChecked();
comment.m_generateBrief = m_page->generateBriefCheckBox->isChecked();
diff --git a/src/plugins/texteditor/completionsettingspage.ui b/src/plugins/texteditor/completionsettingspage.ui
index b5bf12a0a0..7eda07d2ae 100644
--- a/src/plugins/texteditor/completionsettingspage.ui
+++ b/src/plugins/texteditor/completionsettingspage.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>551</width>
- <height>465</height>
+ <height>493</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -270,6 +270,39 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
</item>
</layout>
</item>
+ <item row="5" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <item>
+ <spacer name="horizontalSpacer_7">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>30</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="removeAutoComplete">
+ <property name="toolTip">
+ <string>Remove the automatically inserted character if the trigger is deleted by backspace after the completion.</string>
+ </property>
+ <property name="text">
+ <string>Remove automatically inserted text on backspace</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</item>
@@ -361,6 +394,7 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
<tabstop>animateAutoComplete</tabstop>
<tabstop>highlightAutoComplete</tabstop>
<tabstop>skipAutoComplete</tabstop>
+ <tabstop>removeAutoComplete</tabstop>
<tabstop>enableDoxygenCheckBox</tabstop>
<tabstop>generateBriefCheckBox</tabstop>
<tabstop>leadingAsterisksCheckBox</tabstop>
@@ -374,12 +408,12 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>195</x>
- <y>383</y>
+ <x>216</x>
+ <y>411</y>
</hint>
<hint type="destinationlabel">
- <x>320</x>
- <y>410</y>
+ <x>378</x>
+ <y>438</y>
</hint>
</hints>
</connection>
@@ -399,5 +433,21 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
</hint>
</hints>
</connection>
+ <connection>
+ <sender>highlightAutoComplete</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>removeAutoComplete</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>223</x>
+ <y>275</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>226</x>
+ <y>333</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
</ui>
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 5f0ecb647b..70e7058589 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -456,6 +456,7 @@ public:
bool m_animateAutoComplete = true;
bool m_highlightAutoComplete = true;
bool m_skipAutoCompletedText = true;
+ bool m_removeAutoCompletedText = true;
bool m_keepAutoCompletionHighlight = false;
QTextCursor m_autoCompleteHighlightPos;
@@ -5365,8 +5366,10 @@ void TextEditorWidgetPrivate::handleBackspaceKey()
const TabSettings &tabSettings = m_document->tabSettings();
const TypingSettings &typingSettings = m_document->typingSettings();
- if (typingSettings.m_autoIndent && m_autoCompleter->autoBackspace(cursor))
+ if (typingSettings.m_autoIndent && (m_autoCompleteHighlightPos == cursor)
+ && m_removeAutoCompletedText && m_autoCompleter->autoBackspace(cursor)) {
return;
+ }
bool handled = false;
if (typingSettings.m_smartBackspaceBehavior == TypingSettings::BackspaceNeverIndents) {
@@ -6571,6 +6574,7 @@ void TextEditorWidget::setCompletionSettings(const CompletionSettings &completio
d->m_animateAutoComplete = completionSettings.m_animateAutoComplete;
d->m_highlightAutoComplete = completionSettings.m_highlightAutoComplete;
d->m_skipAutoCompletedText = completionSettings.m_skipAutoCompletedText;
+ d->m_removeAutoCompletedText = completionSettings.m_autoRemove;
}
void TextEditorWidget::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings)