TextEditor: Duplicate selection (Duplicate selection and comment)

New TextEditor action for duplicating current selection.
Extended version of this feature creates commented duplications.

Possible use cases:
1. No selection, cursor anywhere in text - Duplicity line
2. Simple selection - Duplicity selection
3. Block selection, without columns - Duplicity lines
4. Block selection, with columns - Duplicity selection

Cursor position and selection stays unchanged. Works well with Undo
action.

First use case with no selection looks similar as copyLineDown, but
difference is that copyLineDown moves current cursor position and select
created line. This feature don't change cursor position. Because of this
difference it is not possible to integrate this additions with
copyLineDown.

Quick intro: https://youtu.be/Fv6WdCnCLpo

Change-Id: I7c36fca6e17de030cbd22cfa103c2ed672deabbc
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Michal Steller
2016-09-26 15:55:04 +02:00
parent a693bd97ef
commit 768eb4e52e
4 changed files with 140 additions and 0 deletions

View File

@@ -142,6 +142,8 @@ public:
QAction *m_unfoldAction;
QAction *m_cutLineAction;
QAction *m_copyLineAction;
QAction *m_duplicateSelectionAction;
QAction *m_duplicateSelectionAndCommentAction;
QAction *m_deleteLineAction;
QAction *m_deleteEndOfWordAction;
QAction *m_deleteEndOfWordCamelCaseAction;
@@ -206,6 +208,8 @@ TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
m_unfoldAction(0),
m_cutLineAction(0),
m_copyLineAction(0),
m_duplicateSelectionAction(0),
m_duplicateSelectionAndCommentAction(0),
m_deleteLineAction(0),
m_deleteEndOfWordAction(0),
m_deleteEndOfWordCamelCaseAction(0),
@@ -403,6 +407,14 @@ void TextEditorActionHandlerPrivate::createActions()
[this] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
QKeySequence(tr("Ctrl+Ins")),
G_EDIT_TEXT, advancedEditMenu);
m_duplicateSelectionAction = registerAction(DUPLICATE_SELECTION,
[this] (TextEditorWidget *w) { w->duplicateSelection(); }, false, tr("&Duplicate Selection"),
QKeySequence(),
G_EDIT_TEXT, advancedEditMenu);
m_duplicateSelectionAndCommentAction = registerAction(DUPLICATE_SELECTION_AND_COMMENT,
[this] (TextEditorWidget *w) { w->duplicateSelectionAndComment(); }, false, tr("&Duplicate Selection and Comment"),
QKeySequence(),
G_EDIT_TEXT, advancedEditMenu);
m_upperCaseSelectionAction = registerAction(UPPERCASE_SELECTION,
[this] (TextEditorWidget *w) { w->uppercaseSelection(); }, true, tr("Uppercase Selection"),
QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+U") : tr("Alt+Shift+U")),