Commit 5c72f73d authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

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
parent f379d378
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment