示例#1
0
 //实现插入{},但是{与插入行同行
 private void addBrace4JSStandard()
 {
     m_edit.MoveToEndOfLine(false);
     m_edit.InsertText("{");
     m_edit.OpenLineBelow();
     m_edit.InsertText("}");
     m_edit.DecreaseLineIndent();
     m_edit.MoveLineUp(false);
     m_edit.MoveToEndOfLine(false);
     m_edit.OpenLineBelow();
 }
        int?ISmartIndent.GetDesiredIndentation(ITextSnapshotLine line)
        {
            var snap = _textView.TextSnapshot;
            // get all of the previous lines
            var lines = snap.Lines.Reverse().Skip(snap.LineCount - line.LineNumber);

            foreach (ITextSnapshotLine prevLine in lines)
            {
                var text = prevLine.GetText();
                if (text.All(c2 => System.Char.IsWhiteSpace(c2)))
                {
                    continue;
                }
                var toks = Utils.LexString(text).ToList();
                if (toks.Last().Type == RustLexer.RustLexer.LBRACE)
                {
                    return(prevLine.GetText().TakeWhile(c2 => c2 == ' ').Count() + 4);
                }
                else if (toks.Any(tok => tok.Type == RustLexer.RustLexer.RBRACE))
                {
                    ed.MoveLineUp(false);
                    ed.DecreaseLineIndent();
                    ed.MoveLineDown(false);
                    return(prevLine.GetText().TakeWhile(c2 => c2 == ' ').Count());
                }
            }
            // otherwise, there are no lines ending in braces before us.
            return(null);
        }