forked from qt-creator/qt-creator
Fix: Folded code is deleted on save
Also fixes a crash when folding code at the very end of the document Task-number: QTCREATORBUG-2159
This commit is contained in:
@@ -165,8 +165,8 @@ bool BaseTextDocument::save(const QString &fileName)
|
|||||||
// When saving the current editor, make sure to maintain the cursor position for undo
|
// When saving the current editor, make sure to maintain the cursor position for undo
|
||||||
Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor();
|
Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor();
|
||||||
if (BaseTextEditorEditable *editable = qobject_cast<BaseTextEditorEditable*>(currentEditor)) {
|
if (BaseTextEditorEditable *editable = qobject_cast<BaseTextEditorEditable*>(currentEditor)) {
|
||||||
if (editable->file() == this)
|
if (editable->file() == this)
|
||||||
cursor = editable->editor()->textCursor();
|
cursor.setPosition(editable->editor()->textCursor().position());
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
@@ -373,6 +373,7 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
|
|||||||
{
|
{
|
||||||
bool hasSelection = cursor.hasSelection();
|
bool hasSelection = cursor.hasSelection();
|
||||||
QTextCursor copyCursor = cursor;
|
QTextCursor copyCursor = cursor;
|
||||||
|
copyCursor.setVisualNavigation(false);
|
||||||
copyCursor.beginEditBlock();
|
copyCursor.beginEditBlock();
|
||||||
cleanWhitespace(copyCursor, true, true);
|
cleanWhitespace(copyCursor, true, true);
|
||||||
if (!hasSelection)
|
if (!hasSelection)
|
||||||
@@ -383,6 +384,7 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
|
|||||||
void BaseTextDocument::cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument)
|
void BaseTextDocument::cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument)
|
||||||
{
|
{
|
||||||
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
|
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
|
||||||
|
Q_ASSERT(cursor.visualNavigation() == false);
|
||||||
|
|
||||||
QTextBlock block = m_document->findBlock(cursor.selectionStart());
|
QTextBlock block = m_document->findBlock(cursor.selectionStart());
|
||||||
QTextBlock end;
|
QTextBlock end;
|
||||||
|
@@ -175,6 +175,9 @@ void TextBlockUserData::doCollapse(const QTextBlock& block, bool visible)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!visible && !cursor.block().next().isValid())
|
||||||
|
return; // WORKAROUND for a QPlainTextEdit bug, we cannot collapse at the very end, would crash
|
||||||
|
|
||||||
QTextBlock b = block.next();
|
QTextBlock b = block.next();
|
||||||
while (b < cursor.block()) {
|
while (b < cursor.block()) {
|
||||||
b.setVisible(visible);
|
b.setVisible(visible);
|
||||||
|
@@ -1451,6 +1451,8 @@ void BaseTextEditor::setTextCursor(const QTextCursor &cursor)
|
|||||||
QTextCursor c = cursor;
|
QTextCursor c = cursor;
|
||||||
c.setVisualNavigation(true);
|
c.setVisualNavigation(true);
|
||||||
QPlainTextEdit::setTextCursor(c);
|
QPlainTextEdit::setTextCursor(c);
|
||||||
|
if (!c.block().isVisible())
|
||||||
|
expand();
|
||||||
if (selectionChange)
|
if (selectionChange)
|
||||||
slotSelectionChanged();
|
slotSelectionChanged();
|
||||||
}
|
}
|
||||||
@@ -3238,7 +3240,7 @@ void BaseTextEditor::updateCurrentLineHighlight()
|
|||||||
if (block.isValid())
|
if (block.isValid())
|
||||||
d->m_extraArea->update(blockBoundingGeometry(block).translated(offset).toAlignedRect());
|
d->m_extraArea->update(blockBoundingGeometry(block).translated(offset).toAlignedRect());
|
||||||
block = document()->findBlockByNumber(cursorBlockNumber);
|
block = document()->findBlockByNumber(cursorBlockNumber);
|
||||||
if (block.isValid())
|
if (block.isValid() && block.isVisible())
|
||||||
d->m_extraArea->update(blockBoundingGeometry(block).translated(offset).toAlignedRect());
|
d->m_extraArea->update(blockBoundingGeometry(block).translated(offset).toAlignedRect());
|
||||||
d->m_cursorBlockNumber = cursorBlockNumber;
|
d->m_cursorBlockNumber = cursorBlockNumber;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user