Browse Source

Merge pull request #429 from TheJoeFin/newline-duplicate-shortcuts

Newline duplicate shortcuts
pull/430/head
Joseph Finney 1 year ago
committed by GitHub
parent
commit
03bfd61d30
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      Text-Grab/Views/EditTextWindow.xaml.cs

27
Text-Grab/Views/EditTextWindow.xaml.cs

@ -1163,6 +1163,25 @@ public partial class EditTextWindow : Wpf.Ui.Controls.FluentWindow
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)
@ -1807,6 +1826,14 @@ public partial class EditTextWindow : Wpf.Ui.Controls.FluentWindow
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)

Loading…
Cancel
Save