forked from qt-creator/qt-creator
Completion: Don't propose when there's a "good" candidate
This also generalizes some code previously specific to C++. Change-Id: I5774d04a45f28a4e276a0ef282ce0aa5a2f2e552 Reviewed-on: http://codereview.qt.nokia.com/48 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
committed by
Leandro T. C. Melo
parent
1b374905f9
commit
0350314b22
@@ -698,28 +698,6 @@ IAssistProposal * CppCompletionAssistProcessor::perform(const IAssistInterface *
|
|||||||
if (m_hintProposal)
|
if (m_hintProposal)
|
||||||
return m_hintProposal;
|
return m_hintProposal;
|
||||||
|
|
||||||
if (interface->reason() == IdleEditor) {
|
|
||||||
const int pos = m_interface->position();
|
|
||||||
const QChar ch = m_interface->characterAt(pos);
|
|
||||||
if (! (ch.isLetterOrNumber() || ch == QLatin1Char('_'))) {
|
|
||||||
for (int i = pos - 1;; --i) {
|
|
||||||
const QChar ch = m_interface->characterAt(i);
|
|
||||||
if (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
|
|
||||||
const QString wordUnderCursor = m_interface->textAt(i, pos - i);
|
|
||||||
if (wordUnderCursor.at(0).isLetter() || wordUnderCursor.at(0) == QLatin1Char('_')) {
|
|
||||||
foreach (const BasicProposalItem *item, m_completions) {
|
|
||||||
if (item->text() == wordUnderCursor)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_model->m_completionOperator != T_EOF_SYMBOL)
|
if (m_model->m_completionOperator != T_EOF_SYMBOL)
|
||||||
m_model->m_sortable = true;
|
m_model->m_sortable = true;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -241,14 +241,6 @@ QString BasicProposalItemListModel::proposalPrefix() const
|
|||||||
|
|
||||||
// Compute common prefix
|
// Compute common prefix
|
||||||
QString firstKey = m_currentItems.first()->text();
|
QString firstKey = m_currentItems.first()->text();
|
||||||
int ignore = 0;
|
|
||||||
for (int i = firstKey.length() - 1; i >= 0; --i, ++ignore) {
|
|
||||||
const QChar &c = firstKey.at(i);
|
|
||||||
if (c.isLetterOrNumber() || c == QLatin1Char('_'))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ignore)
|
|
||||||
firstKey.chop(ignore);
|
|
||||||
QString lastKey = m_currentItems.last()->text();
|
QString lastKey = m_currentItems.last()->text();
|
||||||
const int length = qMin(firstKey.length(), lastKey.length());
|
const int length = qMin(firstKey.length(), lastKey.length());
|
||||||
firstKey.truncate(length);
|
firstKey.truncate(length);
|
||||||
|
|||||||
@@ -57,8 +57,53 @@
|
|||||||
#include <QtGui/QDesktopWidget>
|
#include <QtGui/QDesktopWidget>
|
||||||
#include <QtGui/QLabel>
|
#include <QtGui/QLabel>
|
||||||
|
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QString cleanText(const QString &original)
|
||||||
|
{
|
||||||
|
QString clean = original;
|
||||||
|
int ignore = 0;
|
||||||
|
for (int i = clean.length() - 1; i >= 0; --i, ++ignore) {
|
||||||
|
const QChar &c = clean.at(i);
|
||||||
|
if (c.isLetterOrNumber() || c == QLatin1Char('_'))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ignore)
|
||||||
|
clean.chop(ignore);
|
||||||
|
return clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasMatch(const QString &prefix, const IGenericProposalModel *model)
|
||||||
|
{
|
||||||
|
if (prefix.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < model->size(); ++i) {
|
||||||
|
const QString ¤t = cleanText(model->text(i));
|
||||||
|
if (!current.isEmpty()) {
|
||||||
|
TextEditor::CaseSensitivity cs =
|
||||||
|
TextEditor::TextEditorSettings::instance()->completionSettings().m_caseSensitivity;
|
||||||
|
if (cs == TextEditor::CaseSensitive) {
|
||||||
|
if (prefix == current)
|
||||||
|
return true;
|
||||||
|
} else if (cs == TextEditor::CaseInsensitive) {
|
||||||
|
if (prefix.compare(current, Qt::CaseInsensitive) == 0)
|
||||||
|
return true;
|
||||||
|
} else if (cs == TextEditor::FirstLetterCaseSensitive) {
|
||||||
|
if (prefix.at(0) == current.at(0)
|
||||||
|
&& prefix.midRef(1).compare(current.midRef(1), Qt::CaseInsensitive) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ------------
|
// ------------
|
||||||
// ModelAdapter
|
// ModelAdapter
|
||||||
// ------------
|
// ------------
|
||||||
@@ -380,7 +425,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
|
|||||||
if (!prefix.isEmpty())
|
if (!prefix.isEmpty())
|
||||||
m_d->m_model->filter(prefix);
|
m_d->m_model->filter(prefix);
|
||||||
if (m_d->m_model->size() == 0
|
if (m_d->m_model->size() == 0
|
||||||
|| (m_d->m_model->size() == 1 && prefix == m_d->m_model->proposalPrefix())) {
|
|| (m_d->m_reason == IdleEditor && hasMatch(prefix, m_d->m_model))) {
|
||||||
abort();
|
abort();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user