PavelTorgashov / FastColoredTextBox

Fast Colored TextBox for Syntax Highlighting. The text editor component for .NET.
Other
1.21k stars 463 forks source link

How to perform a Visual Studio Ctrl+L? #169

Closed nongcaro closed 4 years ago

PavelTorgashov commented 4 years ago

To cut line to clipboard and remove line, you need: 1) Assign Customaction to hotkeys: Скриншот 2019-11-03 09 34 35 2) Make handler for CusomAction event: Скриншот 2019-11-03 09 53 09 3) Create following handler code:

        private void fctb_CustomAction(object sender, CustomActionEventArgs e)
        {
            switch(e.Action)
            {
                case FCTBAction.CustomAction1:
                    //get current line index
                    var iLine = fctb.Selection.FromLine;
                    var lineLength = fctb.Lines[iLine].Length;
                    //select whole line
                    fctb.Selection = new Range(fctb, iLine);
                    //scroll to it
                    fctb.DoSelectionVisible();
                    //if line is readonly - return
                    if (fctb.Selection.ReadOnly)
                        return;
                    //cut to clipboard
                    fctb.Cut();
                    //remove line
                    if (lineLength > 0)
                    {
                        fctb.Selection.GoRight(true);
                        fctb.SelectedText = "";
                    }
                    break;
            }
        }
nongcaro commented 4 years ago

Thanks for the reply, but this does not work the same when you're doing a Ctrl+V after a Ctrl+L. I've implemented my own method a while ago.