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>
This commit is contained in:
David Schulz
2016-06-14 08:00:32 +02:00
committed by David Schulz
parent 5988fd0f5c
commit 5a78fcb434
5 changed files with 69 additions and 6 deletions

View File

@@ -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
;
}

View File

@@ -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); }

View File

@@ -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();

View File

@@ -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>

View File

@@ -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)