Editor: ensure something is selected after model update

Change-Id: I3fbf14cb7aa60caef43340302e74e80ed5e3ba4c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-11-30 12:28:06 +01:00
parent 0313470db0
commit 69ce2a4047
3 changed files with 16 additions and 14 deletions

View File

@@ -285,11 +285,11 @@ public:
return static_cast<LanguageClientCompletionModel *>(model().data())->isComplete(prefix); return static_cast<LanguageClientCompletionModel *>(model().data())->isComplete(prefix);
} }
void setProposal(IAssistProposal *proposal) void setProposal(IAssistProposal *proposal, const QString &prefix)
{ {
if (!proposal) if (!proposal)
return; return;
updateModel(proposal->model()); updateModel(proposal->model(), prefix);
delete proposal; delete proposal;
} }
@@ -303,7 +303,10 @@ public:
auto processor = m_provider->createProcessor(interface.get()); auto processor = m_provider->createProcessor(interface.get());
QTC_ASSERT(processor, return); QTC_ASSERT(processor, return);
processor->setAsyncCompletionAvailableHandler([this, processor](IAssistProposal *proposal) { const QString prefix = interface->textAt(m_basePosition,
interface->position() - m_basePosition);
processor->setAsyncCompletionAvailableHandler([this, processor, prefix](IAssistProposal *proposal) {
QTC_ASSERT(processor == m_processor, return); QTC_ASSERT(processor == m_processor, return);
if (!processor->running()) { if (!processor->running()) {
// do not delete this processor directly since this function is called from within the processor // do not delete this processor directly since this function is called from within the processor
@@ -313,10 +316,10 @@ public:
Qt::QueuedConnection); Qt::QueuedConnection);
m_processor = nullptr; m_processor = nullptr;
} }
setProposal(proposal); setProposal(proposal, prefix);
}); });
setProposal(processor->start(std::move(interface))); setProposal(processor->start(std::move(interface)), prefix);
if (processor->running()) if (processor->running())
m_processor = processor; m_processor = processor;
else else

View File

@@ -392,7 +392,7 @@ void GenericProposalWidget::setIsSynchronized(bool isSync)
d->m_isSynchronized = isSync; d->m_isSynchronized = isSync;
} }
void GenericProposalWidget::updateModel(ProposalModelPtr model) void GenericProposalWidget::updateModel(ProposalModelPtr model, const QString &prefix)
{ {
QString currentText; QString currentText;
if (d->m_explicitlySelected) if (d->m_explicitlySelected)
@@ -403,16 +403,15 @@ void GenericProposalWidget::updateModel(ProposalModelPtr model)
d->m_completionListView->setModel(new ModelAdapter(d->m_model, d->m_completionListView)); d->m_completionListView->setModel(new ModelAdapter(d->m_model, d->m_completionListView));
connect(d->m_completionListView->selectionModel(), &QItemSelectionModel::currentChanged, connect(d->m_completionListView->selectionModel(), &QItemSelectionModel::currentChanged,
&d->m_infoTimer, QOverload<>::of(&QTimer::start)); &d->m_infoTimer, QOverload<>::of(&QTimer::start));
int currentRow = -1;
if (!currentText.isEmpty()) { if (!currentText.isEmpty()) {
currentRow = d->m_model->indexOf( const int currentRow = d->m_model->indexOf(
Utils::equal(&AssistProposalItemInterface::text, currentText)); Utils::equal(&AssistProposalItemInterface::text, currentText));
} if (currentRow < 0)
if (currentRow >= 0)
d->m_completionListView->selectRow(currentRow);
else
d->m_explicitlySelected = false; d->m_explicitlySelected = false;
updatePositionAndSize(); else
d->m_completionListView->selectRow(currentRow);
}
updateAndCheck(prefix);
} }
void GenericProposalWidget::showProposal(const QString &prefix) void GenericProposalWidget::showProposal(const QString &prefix)

View File

@@ -31,7 +31,7 @@ public:
void setDisplayRect(const QRect &rect) override; void setDisplayRect(const QRect &rect) override;
void setIsSynchronized(bool isSync) override; void setIsSynchronized(bool isSync) override;
void updateModel(ProposalModelPtr model); void updateModel(ProposalModelPtr model, const QString &prefix);
void showProposal(const QString &prefix) override; void showProposal(const QString &prefix) override;
void filterProposal(const QString &prefix) override; void filterProposal(const QString &prefix) override;