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 moveLineUpDown(bool up);
|
||||||
void copyLineUpDown(bool up);
|
void copyLineUpDown(bool up);
|
||||||
void addSelectionNextFindMatch();
|
void addSelectionNextFindMatch();
|
||||||
|
void addCursorsToLineEnds();
|
||||||
void saveCurrentCursorPositionForNavigation();
|
void saveCurrentCursorPositionForNavigation();
|
||||||
void updateHighlights();
|
void updateHighlights();
|
||||||
void updateCurrentLineInScrollbar();
|
void updateCurrentLineInScrollbar();
|
||||||
@@ -6822,6 +6823,42 @@ void TextEditorWidget::copyLine()
|
|||||||
copy();
|
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()
|
void TextEditorWidgetPrivate::addSelectionNextFindMatch()
|
||||||
{
|
{
|
||||||
MultiTextCursor cursor = q->multiTextCursor();
|
MultiTextCursor cursor = q->multiTextCursor();
|
||||||
@@ -6902,6 +6939,11 @@ void TextEditorWidget::duplicateSelection()
|
|||||||
d->duplicateSelection(false);
|
d->duplicateSelection(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::addCursorsToLineEnds()
|
||||||
|
{
|
||||||
|
d->addCursorsToLineEnds();
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::addSelectionNextFindMatch()
|
void TextEditorWidget::addSelectionNextFindMatch()
|
||||||
{
|
{
|
||||||
d->addSelectionNextFindMatch();
|
d->addSelectionNextFindMatch();
|
||||||
|
@@ -384,6 +384,7 @@ public:
|
|||||||
void selectLineEnding(int index);
|
void selectLineEnding(int index);
|
||||||
void updateTextLineEndingLabel();
|
void updateTextLineEndingLabel();
|
||||||
void addSelectionNextFindMatch();
|
void addSelectionNextFindMatch();
|
||||||
|
void addCursorsToLineEnds();
|
||||||
|
|
||||||
void gotoBlockStart();
|
void gotoBlockStart();
|
||||||
void gotoBlockEnd();
|
void gotoBlockEnd();
|
||||||
|
@@ -329,6 +329,10 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
[] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
|
[] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
|
||||||
QKeySequence(tr("Ctrl+Ins")),
|
QKeySequence(tr("Ctrl+Ins")),
|
||||||
G_EDIT_TEXT, advancedEditMenu);
|
G_EDIT_TEXT, advancedEditMenu);
|
||||||
|
registerAction(ADD_CURSORS_TO_LINE_ENDS,
|
||||||
|
[] (TextEditorWidget *w) { w->addCursorsToLineEnds(); }, false, tr("Create Cursors at Selected Line Ends"),
|
||||||
|
QKeySequence(tr("Alt+Shift+I")),
|
||||||
|
G_EDIT_TEXT, advancedEditMenu);
|
||||||
registerAction(ADD_SELECT_NEXT_FIND_MATCH,
|
registerAction(ADD_SELECT_NEXT_FIND_MATCH,
|
||||||
[] (TextEditorWidget *w) { w->addSelectionNextFindMatch(); }, false, tr("Add Next Occurrence to Selection"),
|
[] (TextEditorWidget *w) { w->addSelectionNextFindMatch(); }, false, tr("Add Next Occurrence to Selection"),
|
||||||
QKeySequence(tr("Ctrl+D")),
|
QKeySequence(tr("Ctrl+D")),
|
||||||
|
@@ -181,6 +181,7 @@ const char SORT_SELECTED_LINES[] = "TextEditor.SortSelectedLines";
|
|||||||
const char CUT_LINE[] = "TextEditor.CutLine";
|
const char CUT_LINE[] = "TextEditor.CutLine";
|
||||||
const char COPY_LINE[] = "TextEditor.CopyLine";
|
const char COPY_LINE[] = "TextEditor.CopyLine";
|
||||||
const char ADD_SELECT_NEXT_FIND_MATCH[] = "TextEditor.AddSelectionNextFindMatch";
|
const char ADD_SELECT_NEXT_FIND_MATCH[] = "TextEditor.AddSelectionNextFindMatch";
|
||||||
|
const char ADD_CURSORS_TO_LINE_ENDS[] = "TextEditor.AddCursorsAtLineEnd";
|
||||||
const char DUPLICATE_SELECTION[] = "TextEditor.DuplicateSelection";
|
const char DUPLICATE_SELECTION[] = "TextEditor.DuplicateSelection";
|
||||||
const char DUPLICATE_SELECTION_AND_COMMENT[] = "TextEditor.DuplicateSelectionAndComment";
|
const char DUPLICATE_SELECTION_AND_COMMENT[] = "TextEditor.DuplicateSelectionAndComment";
|
||||||
const char DELETE_LINE[] = "TextEditor.DeleteLine";
|
const char DELETE_LINE[] = "TextEditor.DeleteLine";
|
||||||
|
Reference in New Issue
Block a user