diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 32a51d7f2ccd2d999c4304991a9f6920788c3d38..a81d832bbc25457b35c69c4a1b535dd22d148f43 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 4219b3b302c64203e993ec8a83757caa32d0f510..1f1888724a9ffd64f84b236ca93b9d600d7df89d 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 af6bdb01706d3ef6d116d225c3e453cf87cee5a3..0d416188326c448f1d90c9e77bf8ee1368a0833f 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 423dff62ae2f30ff96fbb5e35d7ea68da8aad391..cd215f22c639fa98b00c2f840767855cef06bdc8 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 c16803a1bf8102e2cc4bfc1cf85fdf54f36a65f9..61effc09c8d875114a2cef048c82d2d7be378070 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