forked from qt-creator/qt-creator
Editor: merge SnippetOverlay::mangle, ::clear and ::hide
... into SnippetOverlay::accept. We currently have no need for just applying the mangling without closing the overlay. Change-Id: I98b2f023253f3676d1aed21438251998be1e509c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -77,8 +77,9 @@ void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetOverlay::mangle()
|
void SnippetOverlay::accept()
|
||||||
{
|
{
|
||||||
|
hide();
|
||||||
for (int i = 0; i < m_selections.size(); ++i) {
|
for (int i = 0; i < m_selections.size(); ++i) {
|
||||||
if (NameMangler *mangler = m_selections[i].mangler) {
|
if (NameMangler *mangler = m_selections[i].mangler) {
|
||||||
QTextCursor cursor = cursorForIndex(i);
|
QTextCursor cursor = cursorForIndex(i);
|
||||||
@@ -91,6 +92,7 @@ void SnippetOverlay::mangle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnippetOverlay::hasCursorInSelection(const QTextCursor &cursor) const
|
bool SnippetOverlay::hasCursorInSelection(const QTextCursor &cursor) const
|
||||||
|
@@ -49,7 +49,7 @@ public:
|
|||||||
void setFinalSelection(const QTextCursor &cursor, const QColor &color);
|
void setFinalSelection(const QTextCursor &cursor, const QColor &color);
|
||||||
|
|
||||||
void updateEquivalentSelections(const QTextCursor &cursor);
|
void updateEquivalentSelections(const QTextCursor &cursor);
|
||||||
void mangle();
|
void accept();
|
||||||
|
|
||||||
bool hasCursorInSelection(const QTextCursor &cursor) const;
|
bool hasCursorInSelection(const QTextCursor &cursor) const;
|
||||||
|
|
||||||
|
@@ -2276,9 +2276,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
if (e->key() == Qt::Key_Escape
|
if (e->key() == Qt::Key_Escape
|
||||||
&& d->m_snippetOverlay->isVisible()) {
|
&& d->m_snippetOverlay->isVisible()) {
|
||||||
e->accept();
|
e->accept();
|
||||||
d->m_snippetOverlay->hide();
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->mangle();
|
|
||||||
d->m_snippetOverlay->clear();
|
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
@@ -2321,9 +2319,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
}
|
}
|
||||||
if (d->m_snippetOverlay->isVisible()) {
|
if (d->m_snippetOverlay->isVisible()) {
|
||||||
e->accept();
|
e->accept();
|
||||||
d->m_snippetOverlay->hide();
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->mangle();
|
|
||||||
d->m_snippetOverlay->clear();
|
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
cursor.movePosition(QTextCursor::EndOfBlock);
|
cursor.movePosition(QTextCursor::EndOfBlock);
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
@@ -2738,8 +2734,7 @@ void TextEditorWidget::insertCodeSnippet(const QTextCursor &cursor_arg,
|
|||||||
cursor.removeSelectedText();
|
cursor.removeSelectedText();
|
||||||
const int startCursorPosition = cursor.position();
|
const int startCursorPosition = cursor.position();
|
||||||
|
|
||||||
d->m_snippetOverlay->mangle();
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->clear();
|
|
||||||
|
|
||||||
QList<PositionedPart> positionedParts;
|
QList<PositionedPart> positionedParts;
|
||||||
for (const ParsedSnippet::Part &part : qAsConst(data.parts)) {
|
for (const ParsedSnippet::Part &part : qAsConst(data.parts)) {
|
||||||
@@ -2783,13 +2778,10 @@ void TextEditorWidget::insertCodeSnippet(const QTextCursor &cursor_arg,
|
|||||||
cursor = d->m_snippetOverlay->firstSelectionCursor();
|
cursor = d->m_snippetOverlay->firstSelectionCursor();
|
||||||
if (!cursor.isNull()) {
|
if (!cursor.isNull()) {
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
if (d->m_snippetOverlay->isFinalSelection(cursor)) {
|
if (d->m_snippetOverlay->isFinalSelection(cursor))
|
||||||
d->m_snippetOverlay->mangle();
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->clear();
|
else
|
||||||
d->m_snippetOverlay->setVisible(false);
|
|
||||||
} else {
|
|
||||||
d->m_snippetOverlay->setVisible(true);
|
d->m_snippetOverlay->setVisible(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3485,9 +3477,7 @@ bool TextEditorWidgetPrivate::snippetCheckCursor(const QTextCursor &cursor)
|
|||||||
if (!m_snippetOverlay->hasCursorInSelection(start)
|
if (!m_snippetOverlay->hasCursorInSelection(start)
|
||||||
|| !m_snippetOverlay->hasCursorInSelection(end)
|
|| !m_snippetOverlay->hasCursorInSelection(end)
|
||||||
|| m_snippetOverlay->hasFirstSelectionBeginMoved()) {
|
|| m_snippetOverlay->hasFirstSelectionBeginMoved()) {
|
||||||
m_snippetOverlay->setVisible(false);
|
m_snippetOverlay->accept();
|
||||||
m_snippetOverlay->mangle();
|
|
||||||
m_snippetOverlay->clear();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -3500,11 +3490,8 @@ void TextEditorWidgetPrivate::snippetTabOrBacktab(bool forward)
|
|||||||
QTextCursor cursor = forward ? m_snippetOverlay->nextSelectionCursor(q->textCursor())
|
QTextCursor cursor = forward ? m_snippetOverlay->nextSelectionCursor(q->textCursor())
|
||||||
: m_snippetOverlay->previousSelectionCursor(q->textCursor());
|
: m_snippetOverlay->previousSelectionCursor(q->textCursor());
|
||||||
q->setTextCursor(cursor);
|
q->setTextCursor(cursor);
|
||||||
if (m_snippetOverlay->isFinalSelection(cursor)) {
|
if (m_snippetOverlay->isFinalSelection(cursor))
|
||||||
m_snippetOverlay->setVisible(false);
|
m_snippetOverlay->accept();
|
||||||
m_snippetOverlay->mangle();
|
|
||||||
m_snippetOverlay->clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate global position for a tooltip considering the left extra area.
|
// Calculate global position for a tooltip considering the left extra area.
|
||||||
@@ -6143,11 +6130,9 @@ void TextEditorWidgetPrivate::handleBackspaceKey()
|
|||||||
cursor.deletePreviousChar();
|
cursor.deletePreviousChar();
|
||||||
handled = true;
|
handled = true;
|
||||||
} else {
|
} else {
|
||||||
if (cursorWithinSnippet) {
|
if (cursorWithinSnippet)
|
||||||
m_snippetOverlay->mangle();
|
m_snippetOverlay->accept();
|
||||||
m_snippetOverlay->clear();
|
cursorWithinSnippet = false;
|
||||||
cursorWithinSnippet = false;
|
|
||||||
}
|
|
||||||
int previousIndent = 0;
|
int previousIndent = 0;
|
||||||
const int indent = tabSettings.columnAt(blockText, positionInBlock);
|
const int indent = tabSettings.columnAt(blockText, positionInBlock);
|
||||||
for (QTextBlock previousNonEmptyBlock = currentBlock.previous();
|
for (QTextBlock previousNonEmptyBlock = currentBlock.previous();
|
||||||
@@ -6176,11 +6161,9 @@ void TextEditorWidgetPrivate::handleBackspaceKey()
|
|||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
cursor.deletePreviousChar();
|
cursor.deletePreviousChar();
|
||||||
} else {
|
} else {
|
||||||
if (cursorWithinSnippet) {
|
if (cursorWithinSnippet)
|
||||||
m_snippetOverlay->mangle();
|
m_snippetOverlay->accept();
|
||||||
m_snippetOverlay->clear();
|
cursorWithinSnippet = false;
|
||||||
cursorWithinSnippet = false;
|
|
||||||
}
|
|
||||||
q->unindent();
|
q->unindent();
|
||||||
}
|
}
|
||||||
handled = true;
|
handled = true;
|
||||||
@@ -7753,12 +7736,8 @@ void TextEditorWidget::insertFromMimeData(const QMimeData *source)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->m_snippetOverlay->isVisible() && (text.contains(QLatin1Char('\n'))
|
if (d->m_snippetOverlay->isVisible() && (text.contains('\n') || text.contains('\t')))
|
||||||
|| text.contains(QLatin1Char('\t')))) {
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->hide();
|
|
||||||
d->m_snippetOverlay->mangle();
|
|
||||||
d->m_snippetOverlay->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
const TypingSettings &tps = d->m_document->typingSettings();
|
const TypingSettings &tps = d->m_document->typingSettings();
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
@@ -8517,11 +8496,8 @@ QTextBlock TextEditorWidget::blockForVerticalOffset(int offset) const
|
|||||||
|
|
||||||
void TextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
|
void TextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
|
||||||
{
|
{
|
||||||
if (kind == QuickFix && d->m_snippetOverlay->isVisible()) {
|
if (kind == QuickFix && d->m_snippetOverlay->isVisible())
|
||||||
d->m_snippetOverlay->setVisible(false);
|
d->m_snippetOverlay->accept();
|
||||||
d->m_snippetOverlay->mangle();
|
|
||||||
d->m_snippetOverlay->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool previousMode = overwriteMode();
|
bool previousMode = overwriteMode();
|
||||||
setOverwriteMode(false);
|
setOverwriteMode(false);
|
||||||
|
Reference in New Issue
Block a user