Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to duplicate a line with a hotkey #317

Open
Aegel5 opened this issue Mar 21, 2023 · 3 comments
Open

How to duplicate a line with a hotkey #317

Aegel5 opened this issue Mar 21, 2023 · 3 comments

Comments

@Aegel5
Copy link

Aegel5 commented Mar 21, 2023

I searched for this command in the file AvaloniaEditCommands.cs, but didn't find anything. Can it be added?

@ZSYMAX
Copy link

ZSYMAX commented Jun 8, 2023

Ctrl+C,Ctrl+V

@Aegel5
Copy link
Author

Aegel5 commented Jun 13, 2023

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.

@KrzysztofDusko
Copy link
Contributor

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();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants