ARCed.Scintilla.Indentation.IndentLine C# (CSharp) Method

IndentLine() private method

Smart Indenting helper method
private IndentLine ( int line, int indent ) : void
line int
indent int
return void
        private void IndentLine(int line, int indent)
        {
            if (indent < 0)
            {
                return;
            }

            int selStart = Scintilla.Selection.Start;
            int selEnd = Scintilla.Selection.End;

            Line l = Scintilla.Lines[line];
            int posBefore = l.IndentPosition;
            l.Indentation = indent;

            int posAfter = l.IndentPosition;
            int posDifference = posAfter - posBefore;

            if (posAfter > posBefore)
            {
                // Move selection on
                if (selStart >= posBefore)
                {
                    selStart += posDifference;
                }

                if (selEnd >= posBefore)
                {
                    selEnd += posDifference;
                }
            }
            else if (posAfter < posBefore)
            {
                // Move selection back
                if (selStart >= posAfter)
                {
                    if (selStart >= posBefore)
                        selStart += posDifference;
                    else
                        selStart = posAfter;
                }
                if (selEnd >= posAfter)
                {
                    if (selEnd >= posBefore)
                        selEnd += posDifference;
                    else
                        selEnd = posAfter;
                }
            }

            Scintilla.Selection.Start = selStart;
            Scintilla.Selection.End = selEnd;
        }