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:
mae
2010-09-07 15:55:06 +02:00
parent 198d81735c
commit ebc305b0d8
3 changed files with 6 additions and 4 deletions

View File

@@ -166,8 +166,8 @@ bool BaseTextDocument::save(const QString &fileName)
// When saving the current editor, make sure to maintain the cursor position for undo
Core::IEditor *currentEditor = Core::EditorManager::instance()->currentEditor();
if (BaseTextEditorEditable *editable = qobject_cast<BaseTextEditorEditable*>(currentEditor)) {
if (editable->file() == this)
cursor = editable->editor()->textCursor();
if (editable->file() == this)
cursor.setPosition(editable->editor()->textCursor().position());
}
cursor.beginEditBlock();
@@ -382,6 +382,7 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
{
bool hasSelection = cursor.hasSelection();
QTextCursor copyCursor = cursor;
copyCursor.setVisualNavigation(false);
copyCursor.beginEditBlock();
cleanWhitespace(copyCursor, true, true);
if (!hasSelection)
@@ -392,6 +393,7 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
void BaseTextDocument::cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument)
{
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
Q_ASSERT(cursor.visualNavigation() == false);
QTextBlock block = m_document->findBlock(cursor.selectionStart());
QTextBlock end;