QmlOutline: Prevent warnings about invalid offset for 'setPosition'

Check in advance whether position is still valid. This can be false if
the text has already changed, but the outline hasn't been yet updated.
This commit is contained in:
Kai Koehne
2010-09-14 11:58:06 +02:00
parent b8f6156b83
commit 9caecbaeff

View File

@@ -10,6 +10,7 @@
#include <QtCore/QSettings>
#include <QtGui/QAction>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextBlock>
using namespace QmlJS;
@@ -163,7 +164,6 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!syncCursor())
return;
if (!selection.indexes().isEmpty()) {
QModelIndex index = selection.indexes().first();
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
@@ -173,6 +173,11 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
if (!location.isValid())
return;
const QTextBlock lastBlock = m_editor->document()->lastBlock();
const uint textLength = lastBlock.position() + lastBlock.length();
if (location.offset >= textLength)
return;
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
editorManager->addCurrentPositionToNavigationHistory();