Commit f6a99f61 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Editor: don't leave snippet mode when user pasts/completes.

parent cb7e9248
......@@ -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());
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
......
......@@ -273,6 +273,7 @@ public:
int m_cursorBlockNumber;
bool m_inKeyPressEvent;
bool m_nextChangeIsSnippetSafe;
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment