diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index bf76217af71ed270f38ad1289f1c59138e6c621d..f9aa582444321bce75ed28c4892bd96fc2fa2e1a 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -670,10 +670,7 @@ void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int ch
     if (d->m_snippetOverlay->isVisible()) {
         QTextCursor cursor = textCursor();
         cursor.setPosition(position);
-        if (!d->m_snippetOverlay->hasCursorInSelection(cursor)) {
-            d->m_snippetOverlay->hide();
-            d->m_snippetOverlay->clear();
-        }
+        d->snippetCheckCursor(cursor);
     }
 
     if (doc->isRedoAvailable())
@@ -2455,7 +2452,8 @@ bool BaseTextEditorPrivate::snippetCheckCursor(const QTextCursor &cursor)
     QTextCursor end = cursor;
     end.setPosition(cursor.selectionEnd());
     if (!m_snippetOverlay->hasCursorInSelection(start)
-        || !m_snippetOverlay->hasCursorInSelection(end)) {
+        || !m_snippetOverlay->hasCursorInSelection(end)
+        || m_snippetOverlay->hasFirstSelectionBeginMoved()) {
         m_snippetOverlay->setVisible(false);
         m_snippetOverlay->clear();
         return false;
diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp
index 5059b20945fbc71afe355792dd8874247d952e9f..24a419f4df46db37ddad1ba91811a18769db9a03 100644
--- a/src/plugins/texteditor/texteditoroverlay.cpp
+++ b/src/plugins/texteditor/texteditoroverlay.cpp
@@ -43,6 +43,7 @@ TextEditorOverlay::TextEditorOverlay(BaseTextEditor *editor) :
     m_borderWidth(1),
     m_dropShadowWidth(2),
     m_alpha(true),
+    m_firstSelectionOriginalBegin(-1),
     m_editor(editor),
     m_viewport(editor->viewport())
 {
@@ -69,6 +70,7 @@ void TextEditorOverlay::clear()
     if (m_selections.isEmpty())
         return;
     m_selections.clear();
+    m_firstSelectionOriginalBegin = -1;
     update();
 }
 
@@ -94,13 +96,16 @@ void TextEditorOverlay::addOverlaySelection(int begin, int end,
         }
     }
 
-
     if (overlaySelectionFlags & LockSize)
         selection.m_fixedLength = (end - begin);
 
-
     selection.m_dropShadow = (overlaySelectionFlags & DropShadow);
 
+    if (m_selections.isEmpty())
+        m_firstSelectionOriginalBegin = begin;
+    else if (begin < m_firstSelectionOriginalBegin)
+        qWarning() << "overlay selections not in order";
+
     m_selections.append(selection);
     update();
 }
@@ -525,3 +530,10 @@ void TextEditorOverlay::updateEquivalentSelections(const QTextCursor &cursor)
         }
     }
 }
+
+bool TextEditorOverlay::hasFirstSelectionBeginMoved() const
+{
+    if (m_firstSelectionOriginalBegin == -1 || m_selections.isEmpty())
+        return false;
+    return m_selections.at(0).m_cursor_begin.position() != m_firstSelectionOriginalBegin;
+}
diff --git a/src/plugins/texteditor/texteditoroverlay.h b/src/plugins/texteditor/texteditoroverlay.h
index 48a61ad1c81c8c7fb44dd821fcf8fbbac4f48c07..b6e5f7e09b76777ee656e3ac4eeb69f75f07d94e 100644
--- a/src/plugins/texteditor/texteditoroverlay.h
+++ b/src/plugins/texteditor/texteditoroverlay.h
@@ -101,6 +101,8 @@ public:
     void mapEquivalentSelections();
     void updateEquivalentSelections(const QTextCursor &cursor);
 
+    bool hasFirstSelectionBeginMoved() const;
+
 private:
     QPainterPath createSelectionPath(const QTextCursor &begin, const QTextCursor &end, const QRect& clip);
     void paintSelection(QPainter *painter, const OverlaySelection &selection);
@@ -113,6 +115,7 @@ private:
     int m_borderWidth;
     int m_dropShadowWidth;
     bool m_alpha;
+    int m_firstSelectionOriginalBegin;
     BaseTextEditor *m_editor;
     QWidget *m_viewport;
     QList<OverlaySelection> m_selections;