FakeVim: Block Suggestions

Block suggestions when FakeVim is enabled and the mode
is not "Insert" or "Replace".

Change-Id: I778eb25d9570b76e42652f9d938a8c580033c462
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-04-27 11:03:12 +02:00
parent e46a4eba8d
commit 9f0919c4a3
6 changed files with 84 additions and 26 deletions

View File

@@ -657,6 +657,7 @@ public:
uint m_optionalActionMask = TextEditorActionHandler::None;
bool m_contentsChanged = false;
bool m_lastCursorChangeWasInteresting = false;
std::shared_ptr<void> m_suggestionBlocker;
QSharedPointer<TextDocument> m_document;
QList<QMetaObject::Connection> m_documentConnections;
@@ -905,6 +906,7 @@ void TextEditorWidgetFind::cancelCurrentSelectAll()
TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
: q(parent)
, m_suggestionBlocker((void *) this, [](void *) {})
, m_overlay(new TextEditorOverlay(q))
, m_snippetOverlay(new SnippetOverlay(q))
, m_searchResultOverlay(new TextEditorOverlay(q))
@@ -1654,6 +1656,10 @@ void TextEditorWidgetPrivate::handleMoveBlockSelection(QTextCursor::MoveOperatio
void TextEditorWidgetPrivate::insertSuggestion(std::unique_ptr<TextSuggestion> &&suggestion)
{
clearCurrentSuggestion();
if (m_suggestionBlocker.use_count() > 1)
return;
auto cursor = q->textCursor();
cursor.setPosition(suggestion->position());
m_suggestionBlock = cursor.block();
@@ -6017,6 +6023,18 @@ bool TextEditorWidget::suggestionVisible() const
return currentSuggestion();
}
bool TextEditorWidget::suggestionsBlocked() const
{
return d->m_suggestionBlocker.use_count() > 1;
}
TextEditorWidget::SuggestionBlocker TextEditorWidget::blockSuggestions()
{
if (!suggestionsBlocked())
clearSuggestion();
return d->m_suggestionBlocker;
}
#ifdef WITH_TESTS
void TextEditorWidget::processTooltipRequest(const QTextCursor &c)
{