Skip to content

Commit 2208649

Browse files
committed
Fix jumpy newline above behavior
1 parent 54202e6 commit 2208649

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Text-Grab/Views/EditTextWindow.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,12 @@ private void MakeQrCodeExecuted(object sender, ExecutedRoutedEventArgs e)
11661166
private void AddedLineAboveCommand(object sender, ExecutedRoutedEventArgs e)
11671167
{
11681168
int replaceCaret = PassedTextControl.CaretIndex + Environment.NewLine.Length;
1169-
int lineIndex = PassedTextControl.GetLineIndexFromCharacterIndex(PassedTextControl.CaretIndex);
1170-
int lineStart = PassedTextControl.GetCharacterIndexFromLineIndex(lineIndex);
1171-
PassedTextControl.Text = PassedTextControl.Text.Insert(lineStart, Environment.NewLine);
1172-
PassedTextControl.Select(replaceCaret, 0);
1169+
int selectionLength = PassedTextControl.SelectionLength;
1170+
1171+
SelectLine();
1172+
string lineText = PassedTextControl.SelectedText;
1173+
PassedTextControl.SelectedText = $"{Environment.NewLine}{lineText}";
1174+
PassedTextControl.Select(replaceCaret, selectionLength);
11731175
}
11741176

11751177
private void DuplicateSelectedLine(object sender, ExecutedRoutedEventArgs e)

0 commit comments

Comments
 (0)