diff options
author | Erik Verbruggen <erik.verbruggen@nokia.com> | 2010-09-24 11:34:10 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@nokia.com> | 2010-09-24 11:35:53 +0200 |
commit | f6a99f61639c8afbbbe813c2230782a8fddf5752 (patch) | |
tree | 81ddbdf885868beb311f293952fec01bed5429be | |
parent | cb7e924896f40aa046362ebe2716e3c95dc94dff (diff) | |
download | qt-creator-f6a99f61639c8afbbbe813c2230782a8fddf5752.tar.gz |
Editor: don't leave snippet mode when user pasts/completes.
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 3 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljscodecompletion.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.cpp | 15 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.h | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor_p.h | 1 |
5 files changed, 20 insertions, 3 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 32a51d7f2c..a81d832bbc 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -1822,6 +1822,9 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item, QChar t Symbol *symbol = 0; + if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget())) + edit->setNextChangeIsSnippetSafe(); + if (item.data.isValid()) { if (item.data.canConvert<QString>()) { TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget()); diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp index 4219b3b302..1f1888724a 100644 --- a/src/plugins/qmljseditor/qmljscodecompletion.cpp +++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp @@ -904,6 +904,8 @@ void CodeCompletion::complete(const TextEditor::CompletionItem &item, QChar type QString toInsert = item.text; if (QmlJSTextEditor *edit = qobject_cast<QmlJSTextEditor *>(m_editor->widget())) { + edit->setNextChangeIsSnippetSafe(); + if (item.data.isValid()) { QTextCursor tc = edit->textCursor(); tc.setPosition(m_startPosition, QTextCursor::KeepAnchor); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index af6bdb0170..0d41618832 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -260,6 +260,8 @@ BaseTextEditor::BaseTextEditor(QWidget *parent) d->m_inKeyPressEvent = false; d->m_moveLineUndoHack = false; + + d->m_nextChangeIsSnippetSafe = false; } BaseTextEditor::~BaseTextEditor() @@ -495,7 +497,8 @@ ITextMarkable *BaseTextEditor::markableInterface() const void BaseTextEditor::maybeEmitContentsChangedBecauseOfUndo() { - if (!d->m_inKeyPressEvent) { + if (!d->m_inKeyPressEvent && !d->m_nextChangeIsSnippetSafe) { + d->m_nextChangeIsSnippetSafe = false; // i.e. the document was changed outside key press event // Possible with undo, cut, paste, etc. @@ -4081,6 +4084,11 @@ QString BaseTextEditor::insertParagraphSeparator(const QTextCursor &tc) const return QString(); } +void BaseTextEditor::setNextChangeIsSnippetSafe() +{ + d->m_nextChangeIsSnippetSafe = true; +} + QString BaseTextEditor::autoComplete(QTextCursor &cursor, const QString &textToInsert) const { const bool checkBlockEnd = d->m_allowSkippingOfBlockEnd; @@ -5432,12 +5440,13 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source) return; } - - QString text = source->text(); if (text.isEmpty()) return; + if (!text.contains(QLatin1Char('\n')) && !text.contains(QLatin1Char('\t'))) + setNextChangeIsSnippetSafe(); + const TabSettings &ts = d->m_document->tabSettings(); QTextCursor cursor = textCursor(); if (!ts.m_autoIndent) { diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 423dff62ae..cd215f22c6 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -462,6 +462,8 @@ public: // Returns the text that needs to be inserted virtual QString insertParagraphSeparator(const QTextCursor &tc) const; + virtual void setNextChangeIsSnippetSafe(); + protected: static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen); diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index c16803a1bf..61effc09c8 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -273,6 +273,7 @@ public: int m_cursorBlockNumber; bool m_inKeyPressEvent; + bool m_nextChangeIsSnippetSafe; }; } // namespace Internal |