Commit 0350314b authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo

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/48Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 1b374905
......@@ -698,28 +698,6 @@ IAssistProposal * CppCompletionAssistProcessor::perform(const IAssistInterface *
if (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)
m_model->m_sortable = true;
else
......
......@@ -241,14 +241,6 @@ QString BasicProposalItemListModel::proposalPrefix() const
// Compute common prefix
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();
const int length = qMin(firstKey.length(), lastKey.length());
firstKey.truncate(length);
......
......@@ -57,8 +57,53 @@
#include <QtGui/QDesktopWidget>
#include <QtGui/QLabel>
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 &current = 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
// ------------
......@@ -380,7 +425,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
if (!prefix.isEmpty())
m_d->m_model->filter(prefix);
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();
return false;
}
......
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