forked from qt-creator/qt-creator
Make sure bookmarks survive a document reload
While reloading a text document, the bookmarks got lost since their associated QTextBlocks were deleted. This patch makes sure that before reloading, the bookmarks are removed non-persistently in the same way as when closing a document, and that they are restored after the document was reloaded. Currently, no effort is made to update the location of the bookmarks based on the way the file changed. Task-number: QTCREATORBUG-1281 Reviewed-by: dt
This commit is contained in:
@@ -132,7 +132,7 @@ BaseTextDocument::BaseTextDocument()
|
||||
m_fileIsReadOnly = false;
|
||||
m_isBinaryData = false;
|
||||
m_codec = QTextCodec::codecForLocale();
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
QSettings *settings = Core::ICore::instance()->settings();
|
||||
if (QTextCodec *candidate = QTextCodec::codecForName(
|
||||
settings->value(QLatin1String("General/DefaultFileEncoding")).toByteArray()))
|
||||
m_codec = candidate;
|
||||
@@ -142,12 +142,8 @@ BaseTextDocument::BaseTextDocument()
|
||||
|
||||
BaseTextDocument::~BaseTextDocument()
|
||||
{
|
||||
QTextBlock block = m_document->begin();
|
||||
while (block.isValid()) {
|
||||
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData()))
|
||||
data->documentClosing();
|
||||
block = block.next();
|
||||
}
|
||||
documentClosing();
|
||||
|
||||
delete m_document;
|
||||
m_document = 0;
|
||||
}
|
||||
@@ -324,6 +320,8 @@ void BaseTextDocument::reload(QTextCodec *codec)
|
||||
void BaseTextDocument::reload()
|
||||
{
|
||||
emit aboutToReload();
|
||||
documentClosing(); // removes text marks non-permanently
|
||||
|
||||
if (open(m_fileName))
|
||||
emit reloaded();
|
||||
}
|
||||
@@ -373,9 +371,8 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
|
||||
copyCursor.endEditBlock();
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
QTextBlock block = m_document->findBlock(cursor.selectionStart());
|
||||
@@ -423,3 +420,13 @@ void BaseTextDocument::ensureFinalNewLine(QTextCursor& cursor)
|
||||
cursor.insertText(QLatin1String("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTextDocument::documentClosing()
|
||||
{
|
||||
QTextBlock block = m_document->begin();
|
||||
while (block.isValid()) {
|
||||
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData()))
|
||||
data->documentClosing();
|
||||
block = block.next();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user