public static CommandRange QuotedString(TextEditorData editor, char quotationChar)
        {
            CommandRange range         = FindQuotes(editor, quotationChar);
            var          lineOffset    = editor.GetLine(editor.Caret.Line).Offset;
            var          lineEndOffset = editor.GetLine(editor.Caret.Line).EndOffset - 1; // Line includes \n

            var endIncludingTrailingWhiteSpace   = range.End;
            var startIncludingTrailingWhiteSpace = range.Start;

            // expand to include all trailing white space
            while (endIncludingTrailingWhiteSpace < lineEndOffset && Char.IsWhiteSpace(editor.Text[endIncludingTrailingWhiteSpace + 1]))
            {
                endIncludingTrailingWhiteSpace++;
            }

            // if there's no trailing white space then include leading
            if (endIncludingTrailingWhiteSpace == range.End)
            {
                while (startIncludingTrailingWhiteSpace > lineOffset && Char.IsWhiteSpace(editor.Text[startIncludingTrailingWhiteSpace - 1]))
                {
                    startIncludingTrailingWhiteSpace--;
                }
            }

            return(new CommandRange(Math.Min(range.Start, startIncludingTrailingWhiteSpace), Math.Max(range.End, endIncludingTrailingWhiteSpace) + 1));
        }
        protected override void Run()
        {
            CommandRange range = _selector();

            ChangeRange(range);
            if (range != CommandRange.Empty)
            {
                // Move caret inside if it is on on opening character and block is empty
                if (range.Length == 0 && Editor.Caret.Offset < range.Start)
                {
                    Editor.Caret.Offset++;
                }
                else
                {
                    // if block still has two newlines inside, then drop inside block and indent
                    int del1 = NewLine.GetDelimiterLength(Editor.Text[range.Start - 1], Editor.Text[range.Start]);
                    if (del1 > 0)
                    {
                        int del2Start = range.Start - 1 + del1;
                        int del2      = NewLine.GetDelimiterLength(Editor.Text[del2Start],
                                                                   Editor.Text[del2Start + 1]);
                        if (del2 > 0)
                        {
                            IndentCaretInBlock(range.Start - 2);
                        }
                    }
                }
            }
        }
 protected void DeleteRange(CommandRange range)
 {
     if (range.Length > 0)
     {
         Editor.SetSelection(range.Start, range.End);
         ClipboardActions.Cut(Editor);
     }
 }
Пример #4
0
 protected void ChangeRange(CommandRange range)
 {
     DeleteRange(range);
     if (range != CommandRange.Empty)
     {
         RequestedMode = Mode.Insert;
     }
 }
 protected void DeleteRange(CommandRange range)
 {
     if (range.Length > 0)
     {
         Editor.SetSelection(range.Start, range.End);
         ClipboardActions.Cut(Editor);
     }
 }
 protected void ChangeRange(CommandRange range)
 {
     DeleteRange(range);
     if (range != CommandRange.Empty)
         RequestedMode = Mode.Insert;        
 }