Skip to content

Commit

Permalink
Merge pull request #429 from TheJoeFin/newline-duplicate-shortcuts
Browse files Browse the repository at this point in the history
Newline duplicate shortcuts
  • Loading branch information
TheJoeFin committed Feb 26, 2024
2 parents 200d310 + c1bf2d1 commit 03bfd61
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Text-Grab/Views/EditTextWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,25 @@ private void MakeQrCodeExecuted(object sender, ExecutedRoutedEventArgs e)
window.Show();
}

private void AddedLineAboveCommand(object sender, ExecutedRoutedEventArgs e)
{
int replaceCaret = PassedTextControl.CaretIndex + Environment.NewLine.Length;
int lineIndex = PassedTextControl.GetLineIndexFromCharacterIndex(PassedTextControl.CaretIndex);
int lineStart = PassedTextControl.GetCharacterIndexFromLineIndex(lineIndex);
PassedTextControl.Text = PassedTextControl.Text.Insert(lineStart, Environment.NewLine);
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 @@ -1807,6 +1826,14 @@ private void SetupRoutedCommands()
RoutedCommand EscapeKeyed = new();
_ = EscapeKeyed.InputGestures.Add(new KeyGesture(Key.Escape));
_ = CommandBindings.Add(new CommandBinding(EscapeKeyed, KeyedEscape));

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 03bfd61

Please sign in to comment.