forked from qt-creator/qt-creator
Delay the automatic completion.
This commit is contained in:
@@ -658,7 +658,7 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
|||||||
QChar characterUnderCursor = editor->characterAt(pos);
|
QChar characterUnderCursor = editor->characterAt(pos);
|
||||||
if (!characterUnderCursor.isLetterOrNumber()) {
|
if (!characterUnderCursor.isLetterOrNumber()) {
|
||||||
const int startOfName = findStartOfName(pos);
|
const int startOfName = findStartOfName(pos);
|
||||||
if (pos - startOfName == 3) {
|
if (pos - startOfName >= 3) {
|
||||||
const QChar firstCharacter = editor->characterAt(startOfName);
|
const QChar firstCharacter = editor->characterAt(startOfName);
|
||||||
if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) {
|
if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) {
|
||||||
// Finally check that we're not inside a comment or string (code copied from startOfOperator)
|
// Finally check that we're not inside a comment or string (code copied from startOfOperator)
|
||||||
@@ -1725,6 +1725,11 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (completions->size() == 1) {
|
||||||
|
if (key == completions->first().text)
|
||||||
|
completions->clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TextEditor::CompletionItem> CppCodeCompletion::removeDuplicates(const QList<TextEditor::CompletionItem> &items)
|
QList<TextEditor::CompletionItem> CppCodeCompletion::removeDuplicates(const QList<TextEditor::CompletionItem> &items)
|
||||||
|
@@ -61,6 +61,7 @@
|
|||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QTimeLine>
|
#include <QtCore/QTimeLine>
|
||||||
|
#include <QtCore/QTime>
|
||||||
#include <QtGui/QAbstractTextDocumentLayout>
|
#include <QtGui/QAbstractTextDocumentLayout>
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QKeyEvent>
|
#include <QtGui/QKeyEvent>
|
||||||
@@ -240,6 +241,11 @@ BaseTextEditor::BaseTextEditor(QWidget *parent)
|
|||||||
d->m_highlightBlocksTimer->setSingleShot(true);
|
d->m_highlightBlocksTimer->setSingleShot(true);
|
||||||
connect(d->m_highlightBlocksTimer, SIGNAL(timeout()), this, SLOT(_q_highlightBlocks()));
|
connect(d->m_highlightBlocksTimer, SIGNAL(timeout()), this, SLOT(_q_highlightBlocks()));
|
||||||
|
|
||||||
|
d->m_requestAutoCompletionTimer = new QTimer(this);
|
||||||
|
d->m_requestAutoCompletionTimer->setSingleShot(true);
|
||||||
|
d->m_requestAutoCompletionTimer->setInterval(500);
|
||||||
|
connect(d->m_requestAutoCompletionTimer, SIGNAL(timeout()), this, SLOT(_q_requestAutoCompletion()));
|
||||||
|
|
||||||
d->m_animator = 0;
|
d->m_animator = 0;
|
||||||
|
|
||||||
d->m_searchResultFormat.setBackground(QColor(0xffef0b));
|
d->m_searchResultFormat.setBackground(QColor(0xffef0b));
|
||||||
@@ -1380,18 +1386,38 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
|||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_event:
|
skip_event:
|
||||||
if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)
|
if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)
|
||||||
d->m_parenthesesMatchingTimer->start(50);
|
d->m_parenthesesMatchingTimer->start(50);
|
||||||
|
|
||||||
|
|
||||||
if (!ro && d->m_contentsChanged && !e->text().isEmpty() && e->text().at(0).isPrint())
|
if (!ro && d->m_contentsChanged && !e->text().isEmpty() && e->text().at(0).isPrint()) {
|
||||||
emit requestAutoCompletion(editableInterface(), false);
|
maybeRequestAutoCompletion(e->text().at(0));
|
||||||
|
}
|
||||||
|
|
||||||
if (e != original_e)
|
if (e != original_e)
|
||||||
delete e;
|
delete e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::maybeRequestAutoCompletion(const QChar &ch)
|
||||||
|
{
|
||||||
|
if (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
|
||||||
|
d->m_requestAutoCompletionRevision = document()->revision();
|
||||||
|
d->m_requestAutoCompletionTimer->start();
|
||||||
|
} else {
|
||||||
|
d->m_requestAutoCompletionTimer->stop();
|
||||||
|
emit requestAutoCompletion(editableInterface(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::_q_requestAutoCompletion()
|
||||||
|
{
|
||||||
|
d->m_requestAutoCompletionTimer->stop();
|
||||||
|
|
||||||
|
if (d->m_requestAutoCompletionRevision == document()->revision())
|
||||||
|
emit requestAutoCompletion(editableInterface(), false);
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditor::insertCodeSnippet(const QTextCursor &cursor_arg, const QString &snippet)
|
void BaseTextEditor::insertCodeSnippet(const QTextCursor &cursor_arg, const QString &snippet)
|
||||||
{
|
{
|
||||||
if ((snippet.count('$') % 2) != 0) {
|
if ((snippet.count('$') % 2) != 0) {
|
||||||
@@ -1908,6 +1934,8 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
|
|||||||
m_moveLineUndoHack(false),
|
m_moveLineUndoHack(false),
|
||||||
m_findScopeVerticalBlockSelection(0),
|
m_findScopeVerticalBlockSelection(0),
|
||||||
m_highlightBlocksTimer(0),
|
m_highlightBlocksTimer(0),
|
||||||
|
m_requestAutoCompletionRevision(0),
|
||||||
|
m_requestAutoCompletionTimer(0),
|
||||||
m_cursorBlockNumber(-1),
|
m_cursorBlockNumber(-1),
|
||||||
m_inKeyPressEvent(false)
|
m_inKeyPressEvent(false)
|
||||||
{
|
{
|
||||||
|
@@ -496,6 +496,7 @@ signals:
|
|||||||
void requestQuickFix(TextEditor::ITextEditable *editor);
|
void requestQuickFix(TextEditor::ITextEditable *editor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void maybeRequestAutoCompletion(const QChar &ch);
|
||||||
void indentOrUnindent(bool doIndent);
|
void indentOrUnindent(bool doIndent);
|
||||||
void handleHomeKey(bool anchor);
|
void handleHomeKey(bool anchor);
|
||||||
void handleBackspaceKey();
|
void handleBackspaceKey();
|
||||||
@@ -527,13 +528,17 @@ private:
|
|||||||
|
|
||||||
void universalHelper(); // test function for development
|
void universalHelper(); // test function for development
|
||||||
|
|
||||||
// parentheses matcher
|
|
||||||
private slots:
|
private slots:
|
||||||
|
// auto completion
|
||||||
|
void _q_requestAutoCompletion();
|
||||||
|
|
||||||
|
// parentheses matcher
|
||||||
void _q_matchParentheses();
|
void _q_matchParentheses();
|
||||||
void _q_highlightBlocks();
|
void _q_highlightBlocks();
|
||||||
void slotSelectionChanged();
|
void slotSelectionChanged();
|
||||||
void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
|
void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
|
||||||
void doFoo();
|
void doFoo();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -263,6 +263,9 @@ public:
|
|||||||
BaseTextEditorPrivateHighlightBlocks m_highlightBlocksInfo;
|
BaseTextEditorPrivateHighlightBlocks m_highlightBlocksInfo;
|
||||||
QTimer *m_highlightBlocksTimer;
|
QTimer *m_highlightBlocksTimer;
|
||||||
|
|
||||||
|
int m_requestAutoCompletionRevision;
|
||||||
|
QTimer *m_requestAutoCompletionTimer;
|
||||||
|
|
||||||
QPointer<BaseTextEditorAnimator> m_animator;
|
QPointer<BaseTextEditorAnimator> m_animator;
|
||||||
int m_cursorBlockNumber;
|
int m_cursorBlockNumber;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user