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.setKeepPositionOnInsert(true);
|
||||
setCurrentPosition(m_start.position());
|
||||
|
||||
connect(
|
||||
origin_document,
|
||||
&::TextEditor::TextDocument::contentsChangedWithPosition,
|
||||
this,
|
||||
&CyclicSuggestion::documentChanged);
|
||||
}
|
||||
|
||||
virtual bool apply() override
|
||||
@@ -163,6 +169,14 @@ public:
|
||||
signals:
|
||||
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:
|
||||
// Be causious with this function, it should be the last called in the chain
|
||||
// since it replaces this object.
|
||||
@@ -177,8 +191,10 @@ private:
|
||||
void lockCurrentSuggestion()
|
||||
{
|
||||
m_locked = true;
|
||||
if (m_suggestions.size() <= 1)
|
||||
if (m_suggestions.size() <= 1) {
|
||||
emit update();
|
||||
return;
|
||||
}
|
||||
|
||||
m_suggestions = QList<Suggestion>{m_suggestions.at(m_currentSuggestion)};
|
||||
m_currentSuggestion = 0;
|
||||
@@ -253,10 +269,14 @@ private:
|
||||
|
||||
void updateLabels()
|
||||
{
|
||||
if (auto cs = currentSuggestion())
|
||||
if (auto cs = currentSuggestion()) {
|
||||
if (cs->isLocked())
|
||||
m_numberLabel->setText(" ");
|
||||
else
|
||||
m_numberLabel->setText(
|
||||
Lua::Tr::tr("%1 of %2").arg(cs->currentSuggestion() + 1).arg(cs->size()));
|
||||
}
|
||||
}
|
||||
|
||||
void apply()
|
||||
{
|
||||
|
Reference in New Issue
Block a user