From 5c72f73d26eb04e5e183b59d1ad1d6d39b992e89 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@nokia.com> Date: Tue, 7 Sep 2010 14:34:40 +0200 Subject: [PATCH] TextEditor: update text markers in moveLineUpDown() When the user moves a block up or down the text markers have to be updated correctly. This is done now in moveLineUpDown(). We check if a text marker is in the block that is about to be moved and set the position of the QTextCursor to the correct value, afterwards. Reviewed-by: mae --- src/plugins/texteditor/basetexteditor.cpp | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 647f16206d7..5388c5cce7f 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1041,6 +1041,23 @@ void BaseTextEditor::moveLineUpDown(bool up) move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); } QString text = move.selectedText(); + + RefactorMarkers affectedMarkers; + RefactorMarkers nonAffectedMarkers; + QList<int> markerOffsets; + + foreach (const RefactorMarker &marker, d->m_refactorOverlay->markers()) { + //test if marker is part of the selection to be moved + if ((move.selectionStart() <= marker.cursor.position()) && (move.selectionEnd() >= marker.cursor.position())) { + affectedMarkers.append(marker); + //remember the offset of markers in text + int offset = marker.cursor.position() - move.selectionStart(); + markerOffsets.append(offset); + } else { + nonAffectedMarkers.append(marker); + } + } + move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); move.removeSelectedText(); @@ -1069,6 +1086,13 @@ void BaseTextEditor::moveLineUpDown(bool up) move.setPosition(end, QTextCursor::KeepAnchor); } + //update positions of affectedMarkers + for (int i=0;i < affectedMarkers.count(); i++) { + int newPosition = start + markerOffsets.at(i); + affectedMarkers[i].cursor.setPosition(newPosition); + } + d->m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers); + reindent(document(), move); move.endEditBlock(); -- GitLab