forked from qt-creator/qt-creator
Editor: don't leave snippet mode when user pasts/completes.
This commit is contained in:
@@ -1822,6 +1822,9 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item, QChar t
|
|||||||
|
|
||||||
Symbol *symbol = 0;
|
Symbol *symbol = 0;
|
||||||
|
|
||||||
|
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget()))
|
||||||
|
edit->setNextChangeIsSnippetSafe();
|
||||||
|
|
||||||
if (item.data.isValid()) {
|
if (item.data.isValid()) {
|
||||||
if (item.data.canConvert<QString>()) {
|
if (item.data.canConvert<QString>()) {
|
||||||
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget());
|
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;
|
QString toInsert = item.text;
|
||||||
|
|
||||||
if (QmlJSTextEditor *edit = qobject_cast<QmlJSTextEditor *>(m_editor->widget())) {
|
if (QmlJSTextEditor *edit = qobject_cast<QmlJSTextEditor *>(m_editor->widget())) {
|
||||||
|
edit->setNextChangeIsSnippetSafe();
|
||||||
|
|
||||||
if (item.data.isValid()) {
|
if (item.data.isValid()) {
|
||||||
QTextCursor tc = edit->textCursor();
|
QTextCursor tc = edit->textCursor();
|
||||||
tc.setPosition(m_startPosition, QTextCursor::KeepAnchor);
|
tc.setPosition(m_startPosition, QTextCursor::KeepAnchor);
|
||||||
|
|||||||
@@ -260,6 +260,8 @@ BaseTextEditor::BaseTextEditor(QWidget *parent)
|
|||||||
|
|
||||||
d->m_inKeyPressEvent = false;
|
d->m_inKeyPressEvent = false;
|
||||||
d->m_moveLineUndoHack = false;
|
d->m_moveLineUndoHack = false;
|
||||||
|
|
||||||
|
d->m_nextChangeIsSnippetSafe = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextEditor::~BaseTextEditor()
|
BaseTextEditor::~BaseTextEditor()
|
||||||
@@ -495,7 +497,8 @@ ITextMarkable *BaseTextEditor::markableInterface() const
|
|||||||
|
|
||||||
void BaseTextEditor::maybeEmitContentsChangedBecauseOfUndo()
|
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
|
// i.e. the document was changed outside key press event
|
||||||
// Possible with undo, cut, paste, etc.
|
// Possible with undo, cut, paste, etc.
|
||||||
@@ -4081,6 +4084,11 @@ QString BaseTextEditor::insertParagraphSeparator(const QTextCursor &tc) const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::setNextChangeIsSnippetSafe()
|
||||||
|
{
|
||||||
|
d->m_nextChangeIsSnippetSafe = true;
|
||||||
|
}
|
||||||
|
|
||||||
QString BaseTextEditor::autoComplete(QTextCursor &cursor, const QString &textToInsert) const
|
QString BaseTextEditor::autoComplete(QTextCursor &cursor, const QString &textToInsert) const
|
||||||
{
|
{
|
||||||
const bool checkBlockEnd = d->m_allowSkippingOfBlockEnd;
|
const bool checkBlockEnd = d->m_allowSkippingOfBlockEnd;
|
||||||
@@ -5432,12 +5440,13 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString text = source->text();
|
QString text = source->text();
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!text.contains(QLatin1Char('\n')) && !text.contains(QLatin1Char('\t')))
|
||||||
|
setNextChangeIsSnippetSafe();
|
||||||
|
|
||||||
const TabSettings &ts = d->m_document->tabSettings();
|
const TabSettings &ts = d->m_document->tabSettings();
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
if (!ts.m_autoIndent) {
|
if (!ts.m_autoIndent) {
|
||||||
|
|||||||
@@ -462,6 +462,8 @@ public:
|
|||||||
// Returns the text that needs to be inserted
|
// Returns the text that needs to be inserted
|
||||||
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
|
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
|
||||||
|
|
||||||
|
virtual void setNextChangeIsSnippetSafe();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
|
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
|
||||||
|
|
||||||
|
|||||||
@@ -273,6 +273,7 @@ public:
|
|||||||
int m_cursorBlockNumber;
|
int m_cursorBlockNumber;
|
||||||
|
|
||||||
bool m_inKeyPressEvent;
|
bool m_inKeyPressEvent;
|
||||||
|
bool m_nextChangeIsSnippetSafe;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user