diff options
| author | Joel Smith <joel.m.smith@gmail.com> | 2019-05-15 21:50:28 -0700 |
|---|---|---|
| committer | Joel Smith <joel.m.smith@gmail.com> | 2019-05-27 14:09:12 +0000 |
| commit | e846b8717aad09e71650c6ca95b05d320f1eb3f1 (patch) | |
| tree | 818bc7e5fb6cfa9ff754b75eb7057d7e36e8b00d /src | |
| parent | 0980484be856a71d704bad7623d0b6c5abff143e (diff) | |
| download | qt-creator-e846b8717aad09e71650c6ca95b05d320f1eb3f1.tar.gz | |
TextEditor: Type over punctuation that can be auto completed
This restores a feature of older Qt Creator versions: typing "over"
closing punctuation. For instance, if my cursor is at | and I have
something like this:
if (statement|)
... and I type the ) character, older versions of Qt Creator would not
end up with )). With newer versions of Qt Creator, this behavior is
limited to the case where an autocompletion has just happened (i.e. if I
typed the opening ( character, the closing ) is auto inserted and
highlighted - and if I type it myself, it won't add a second one).
Task-number: QTCREATORBUG-16946
Change-Id: I45af3ac139d5e7c76e5f0a8a9d66762f9209a525
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/texteditor/autocompleter.cpp | 6 | ||||
| -rw-r--r-- | src/plugins/texteditor/autocompleter.h | 4 | ||||
| -rw-r--r-- | src/plugins/texteditor/completionsettings.cpp | 5 | ||||
| -rw-r--r-- | src/plugins/texteditor/completionsettings.h | 1 | ||||
| -rw-r--r-- | src/plugins/texteditor/completionsettingspage.cpp | 2 | ||||
| -rw-r--r-- | src/plugins/texteditor/completionsettingspage.ui | 12 | ||||
| -rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 1 |
7 files changed, 29 insertions, 2 deletions
diff --git a/src/plugins/texteditor/autocompleter.cpp b/src/plugins/texteditor/autocompleter.cpp index 8517c5c03d..ea50725639 100644 --- a/src/plugins/texteditor/autocompleter.cpp +++ b/src/plugins/texteditor/autocompleter.cpp @@ -37,7 +37,8 @@ AutoCompleter::AutoCompleter() : m_autoInsertBrackets(true), m_surroundWithBrackets(true), m_autoInsertQuotes(true), - m_surroundWithQuotes(true) + m_surroundWithQuotes(true), + m_overwriteClosingChars(false) {} AutoCompleter::~AutoCompleter() = default; @@ -191,6 +192,9 @@ QString AutoCompleter::autoComplete(QTextCursor &cursor, const QString &textToIn QTextDocument *doc = cursor.document(); const QChar lookAhead = doc->characterAt(cursor.selectionEnd()); + if (m_overwriteClosingChars && (textToInsert == lookAhead)) + skipChars = true; + int skippedChars = 0; if (isQuote(textToInsert) && m_autoInsertQuotes diff --git a/src/plugins/texteditor/autocompleter.h b/src/plugins/texteditor/autocompleter.h index 4847f50476..128d875e0f 100644 --- a/src/plugins/texteditor/autocompleter.h +++ b/src/plugins/texteditor/autocompleter.h @@ -53,6 +53,9 @@ public: void setSurroundWithQuotesEnabled(bool b) { m_surroundWithQuotes = b; } bool isSurroundWithQuotesEnabled() const { return m_surroundWithQuotes; } + void setOverwriteClosingCharsEnabled(bool b) { m_overwriteClosingChars = b; } + bool isOverwriteClosingCharsEnabled() const { return m_overwriteClosingChars; } + void setTabSettings(const TabSettings &tabSettings) { m_tabSettings = tabSettings; } const TabSettings &tabSettings() const { return m_tabSettings; } @@ -103,6 +106,7 @@ private: bool m_surroundWithBrackets; bool m_autoInsertQuotes; bool m_surroundWithQuotes; + bool m_overwriteClosingChars; }; } // TextEditor diff --git a/src/plugins/texteditor/completionsettings.cpp b/src/plugins/texteditor/completionsettings.cpp index 61c9f203a8..aca84ef104 100644 --- a/src/plugins/texteditor/completionsettings.cpp +++ b/src/plugins/texteditor/completionsettings.cpp @@ -42,6 +42,7 @@ static const char animateAutoCompleteKey[] = "AnimateAutoComplete"; static const char highlightAutoCompleteKey[] = "HighlightAutoComplete"; static const char skipAutoCompleteKey[] = "SkipAutoComplete"; static const char autoRemoveKey[] = "AutoRemove"; +static const char overwriteClosingCharsKey[] = "OverwriteClosingChars"; using namespace TextEditor; @@ -62,6 +63,7 @@ void CompletionSettings::toSettings(QSettings *s) const s->setValue(highlightAutoCompleteKey, m_highlightAutoComplete); s->setValue(skipAutoCompleteKey, m_skipAutoCompletedText); s->setValue(autoRemoveKey, m_autoRemove); + s->setValue(overwriteClosingCharsKey, m_overwriteClosingChars); s->endGroup(); } @@ -98,6 +100,8 @@ void CompletionSettings::fromSettings(QSettings *s) s->value(skipAutoCompleteKey, m_skipAutoCompletedText).toBool(); m_autoRemove = s->value(autoRemoveKey, m_autoRemove).toBool(); + m_overwriteClosingChars = + s->value(overwriteClosingCharsKey, m_overwriteClosingChars).toBool(); s->endGroup(); } @@ -117,5 +121,6 @@ bool CompletionSettings::equals(const CompletionSettings &cs) const && m_highlightAutoComplete == cs.m_highlightAutoComplete && m_skipAutoCompletedText == cs.m_skipAutoCompletedText && m_autoRemove == cs.m_autoRemove + && m_overwriteClosingChars == cs.m_overwriteClosingChars ; } diff --git a/src/plugins/texteditor/completionsettings.h b/src/plugins/texteditor/completionsettings.h index 9fa75e6152..c670c05443 100644 --- a/src/plugins/texteditor/completionsettings.h +++ b/src/plugins/texteditor/completionsettings.h @@ -70,6 +70,7 @@ public: bool m_highlightAutoComplete = true; bool m_skipAutoCompletedText = true; bool m_autoRemove = true; + bool m_overwriteClosingChars = false; }; 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 8a9a82740c..b9cff7f661 100644 --- a/src/plugins/texteditor/completionsettingspage.cpp +++ b/src/plugins/texteditor/completionsettingspage.cpp @@ -102,6 +102,7 @@ QWidget *CompletionSettingsPage::widget() m_page->spaceAfterFunctionName->setChecked(m_completionSettings.m_spaceAfterFunctionName); m_page->autoSplitStrings->setChecked(m_completionSettings.m_autoSplitStrings); m_page->animateAutoComplete->setChecked(m_completionSettings.m_animateAutoComplete); + m_page->overwriteClosingChars->setChecked(m_completionSettings.m_overwriteClosingChars); m_page->highlightAutoComplete->setChecked(m_completionSettings.m_highlightAutoComplete); m_page->skipAutoComplete->setChecked(m_completionSettings.m_skipAutoCompletedText); m_page->removeAutoComplete->setChecked(m_completionSettings.m_autoRemove); @@ -181,6 +182,7 @@ void CompletionSettingsPage::settingsFromUi(CompletionSettings &completion, Comm completion.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked(); completion.m_autoSplitStrings = m_page->autoSplitStrings->isChecked(); completion.m_animateAutoComplete = m_page->animateAutoComplete->isChecked(); + completion.m_overwriteClosingChars = m_page->overwriteClosingChars->isChecked(); completion.m_highlightAutoComplete = m_page->highlightAutoComplete->isChecked(); completion.m_skipAutoCompletedText = m_page->skipAutoComplete->isChecked(); completion.m_autoRemove = m_page->removeAutoComplete->isChecked(); diff --git a/src/plugins/texteditor/completionsettingspage.ui b/src/plugins/texteditor/completionsettingspage.ui index ce3ba046be..59e60cb70e 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>493</height> + <height>507</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> @@ -303,6 +303,16 @@ In addition, Shift+Enter inserts an escape character at the cursor position and </item> </layout> </item> + <item row="3" column="1"> + <widget class="QCheckBox" name="overwriteClosingChars"> + <property name="toolTip"> + <string>Automatically overwrite closing parentheses and quotes.</string> + </property> + <property name="text"> + <string>Overwrite closing punctuation</string> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 97970dbd6e..197eb5ddcf 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7521,6 +7521,7 @@ void TextEditorWidget::setCompletionSettings(const CompletionSettings &completio d->m_autoCompleter->setSurroundWithBracketsEnabled(completionSettings.m_surroundingAutoBrackets); d->m_autoCompleter->setAutoInsertQuotesEnabled(completionSettings.m_autoInsertQuotes); d->m_autoCompleter->setSurroundWithQuotesEnabled(completionSettings.m_surroundingAutoQuotes); + d->m_autoCompleter->setOverwriteClosingCharsEnabled(completionSettings.m_overwriteClosingChars); d->m_animateAutoComplete = completionSettings.m_animateAutoComplete; d->m_highlightAutoComplete = completionSettings.m_highlightAutoComplete; d->m_skipAutoCompletedText = completionSettings.m_skipAutoCompletedText; |
