forked from qt-creator/qt-creator
LUA: Lock CyclicSuggestion when writing over an aligned suggestion
Change-Id: I8081af587a77b28254fe9bb38f811caaf060e10f Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -88,6 +88,12 @@ public:
|
|||||||
m_start = toTextCursor(origin_document->document(), suggestion.position());
|
m_start = toTextCursor(origin_document->document(), suggestion.position());
|
||||||
m_start.setKeepPositionOnInsert(true);
|
m_start.setKeepPositionOnInsert(true);
|
||||||
setCurrentPosition(m_start.position());
|
setCurrentPosition(m_start.position());
|
||||||
|
|
||||||
|
connect(
|
||||||
|
origin_document,
|
||||||
|
&::TextEditor::TextDocument::contentsChangedWithPosition,
|
||||||
|
this,
|
||||||
|
&CyclicSuggestion::documentChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool apply() override
|
virtual bool apply() override
|
||||||
@@ -163,6 +169,14 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void documentChanged(int /* position */, int /* charsRemoved */, int /* charsAdded */)
|
||||||
|
{
|
||||||
|
// When the document is changed, the suggestion will be either destroyed or must be locked.
|
||||||
|
if (!m_locked)
|
||||||
|
lockCurrentSuggestion();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Be causious with this function, it should be the last called in the chain
|
// Be causious with this function, it should be the last called in the chain
|
||||||
// since it replaces this object.
|
// since it replaces this object.
|
||||||
@@ -177,8 +191,10 @@ private:
|
|||||||
void lockCurrentSuggestion()
|
void lockCurrentSuggestion()
|
||||||
{
|
{
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
if (m_suggestions.size() <= 1)
|
if (m_suggestions.size() <= 1) {
|
||||||
|
emit update();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_suggestions = QList<Suggestion>{m_suggestions.at(m_currentSuggestion)};
|
m_suggestions = QList<Suggestion>{m_suggestions.at(m_currentSuggestion)};
|
||||||
m_currentSuggestion = 0;
|
m_currentSuggestion = 0;
|
||||||
@@ -253,9 +269,13 @@ private:
|
|||||||
|
|
||||||
void updateLabels()
|
void updateLabels()
|
||||||
{
|
{
|
||||||
if (auto cs = currentSuggestion())
|
if (auto cs = currentSuggestion()) {
|
||||||
m_numberLabel->setText(
|
if (cs->isLocked())
|
||||||
Lua::Tr::tr("%1 of %2").arg(cs->currentSuggestion() + 1).arg(cs->size()));
|
m_numberLabel->setText(" ");
|
||||||
|
else
|
||||||
|
m_numberLabel->setText(
|
||||||
|
Lua::Tr::tr("%1 of %2").arg(cs->currentSuggestion() + 1).arg(cs->size()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply()
|
void apply()
|
||||||
|
Reference in New Issue
Block a user