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