forked from qt-creator/qt-creator
texteditor: Add Cursors to Line Ends command
Adds a new function that creates new cursors at the end of each line that was previously selected. Change-Id: I6510002eae17af9cf00a2eedc5e56ef6fdcc8ef3 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -530,6 +530,7 @@ public:
|
||||
void moveLineUpDown(bool up);
|
||||
void copyLineUpDown(bool up);
|
||||
void addSelectionNextFindMatch();
|
||||
void addCursorsToLineEnds();
|
||||
void saveCurrentCursorPositionForNavigation();
|
||||
void updateHighlights();
|
||||
void updateCurrentLineInScrollbar();
|
||||
@@ -6822,6 +6823,42 @@ void TextEditorWidget::copyLine()
|
||||
copy();
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::addCursorsToLineEnds()
|
||||
{
|
||||
MultiTextCursor multiCursor = q->multiTextCursor();
|
||||
MultiTextCursor newMultiCursor;
|
||||
const QList<QTextCursor> cursors = multiCursor.cursors();
|
||||
|
||||
if (multiCursor.cursorCount() == 0)
|
||||
return;
|
||||
|
||||
QTextDocument *document = q->document();
|
||||
|
||||
for (const QTextCursor &cursor : cursors) {
|
||||
if (!cursor.hasSelection())
|
||||
continue;
|
||||
|
||||
QTextBlock block = document->findBlock(cursor.selectionStart());
|
||||
|
||||
while (block.isValid()) {
|
||||
int blockEnd = block.position() + block.length() - 1;
|
||||
if (blockEnd >= cursor.selectionEnd()) {
|
||||
break;
|
||||
}
|
||||
|
||||
QTextCursor newCursor(document);
|
||||
newCursor.setPosition(blockEnd);
|
||||
newMultiCursor.addCursor(newCursor);
|
||||
|
||||
block = block.next();
|
||||
}
|
||||
}
|
||||
|
||||
if (!newMultiCursor.isNull()) {
|
||||
q->setMultiTextCursor(newMultiCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::addSelectionNextFindMatch()
|
||||
{
|
||||
MultiTextCursor cursor = q->multiTextCursor();
|
||||
@@ -6902,6 +6939,11 @@ void TextEditorWidget::duplicateSelection()
|
||||
d->duplicateSelection(false);
|
||||
}
|
||||
|
||||
void TextEditorWidget::addCursorsToLineEnds()
|
||||
{
|
||||
d->addCursorsToLineEnds();
|
||||
}
|
||||
|
||||
void TextEditorWidget::addSelectionNextFindMatch()
|
||||
{
|
||||
d->addSelectionNextFindMatch();
|
||||
|
||||
Reference in New Issue
Block a user