Skip to content

Commit

Permalink
Duplicate line with ctrl+d
Browse files Browse the repository at this point in the history
closes #423
  • Loading branch information
TheJoeFin committed Feb 26, 2024
1 parent 8f762f0 commit c1bf2d1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Text-Grab/Views/EditTextWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,16 @@ private void AddedLineAboveCommand(object sender, ExecutedRoutedEventArgs e)
PassedTextControl.Select(replaceCaret, 0);
}

private void DuplicateSelectedLine(object sender, ExecutedRoutedEventArgs e)
{
int replaceCaret = PassedTextControl.CaretIndex;
int selectionLength = PassedTextControl.SelectionLength;
SelectLine();
string lineText = PassedTextControl.SelectedText;
PassedTextControl.SelectedText = lineText + Environment.NewLine + lineText;
PassedTextControl.Select(replaceCaret + (Environment.NewLine.Length + lineText.Length), selectionLength);
}

private void MarginsMenuItem_Checked(object sender, RoutedEventArgs e)
{
if (sender is not MenuItem marginsMenuItem)
Expand Down Expand Up @@ -1820,6 +1830,10 @@ private void SetupRoutedCommands()
RoutedCommand AddedLineAbove = new();
_ = AddedLineAbove.InputGestures.Add(new KeyGesture(Key.Enter, ModifierKeys.Control));
_ = CommandBindings.Add(new CommandBinding(AddedLineAbove, AddedLineAboveCommand));

RoutedCommand duplicateLine = new();
_ = duplicateLine.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Control));
_ = CommandBindings.Add(new CommandBinding(duplicateLine, DuplicateSelectedLine));
}

private void SingleLineCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
Expand Down

0 comments on commit c1bf2d1

Please sign in to comment.