Skip to content

Commit c1bf2d1

Browse files
committed
Duplicate line with ctrl+d
closes #423
1 parent 8f762f0 commit c1bf2d1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Text-Grab/Views/EditTextWindow.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,16 @@ private void AddedLineAboveCommand(object sender, ExecutedRoutedEventArgs e)
11721172
PassedTextControl.Select(replaceCaret, 0);
11731173
}
11741174

1175+
private void DuplicateSelectedLine(object sender, ExecutedRoutedEventArgs e)
1176+
{
1177+
int replaceCaret = PassedTextControl.CaretIndex;
1178+
int selectionLength = PassedTextControl.SelectionLength;
1179+
SelectLine();
1180+
string lineText = PassedTextControl.SelectedText;
1181+
PassedTextControl.SelectedText = lineText + Environment.NewLine + lineText;
1182+
PassedTextControl.Select(replaceCaret + (Environment.NewLine.Length + lineText.Length), selectionLength);
1183+
}
1184+
11751185
private void MarginsMenuItem_Checked(object sender, RoutedEventArgs e)
11761186
{
11771187
if (sender is not MenuItem marginsMenuItem)
@@ -1820,6 +1830,10 @@ private void SetupRoutedCommands()
18201830
RoutedCommand AddedLineAbove = new();
18211831
_ = AddedLineAbove.InputGestures.Add(new KeyGesture(Key.Enter, ModifierKeys.Control));
18221832
_ = CommandBindings.Add(new CommandBinding(AddedLineAbove, AddedLineAboveCommand));
1833+
1834+
RoutedCommand duplicateLine = new();
1835+
_ = duplicateLine.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Control));
1836+
_ = CommandBindings.Add(new CommandBinding(duplicateLine, DuplicateSelectedLine));
18231837
}
18241838

18251839
private void SingleLineCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)

0 commit comments

Comments
 (0)