AvaloniaEdit
AvaloniaEdit copied to clipboard
How to duplicate a line with a hotkey
I searched for this command in the file AvaloniaEditCommands.cs
, but didn't find anything. Can it be added?
Ctrl+C,Ctrl+V
Ctrl+C,Ctrl+V
Absolutly not. With this you need select, copy, move cursor, deselect, paste instead of a simple single hot key. In VS this combination exists and is very usefull.
you can override OnKeyDown method or add appropriate event handler Ctrl + Shift + D is hotkey in this sample
protected override async void OnKeyDown(KeyEventArgs e)
{
//...
if (e.HasModifiers(ModifierKeys.Control))
{
switch (e.Key)
{
case Key.D:
if (e.HasModifiers(ModifierKeys.Shift))
{
EditorHelpers.DoubleSelectedLine(this);
}
break;
}
}
//...
}
public static void DoubleSelectedLine(TextEditor editor)
{
editor.BeginChange();
var line = editor.Document.Lines[editor.TextArea.Caret.Line - 1];
string txt = editor.Document.GetText(line.Offset, line.Length);
editor.Document.Insert(line.EndOffset,"\n"+txt);
editor.EndChange();
}