public override bool Unindent() { if (_startPoint.LineNumber == _endPoint.LineNumber) { return(_startPoint.RemovePreviousIndent()); } using (ITextEdit edit = TextBuffer.AdvancedTextBuffer.CreateEdit()) { ITextSnapshot snapshot = TextBuffer.AdvancedTextBuffer.CurrentSnapshot; for (int i = _startPoint.LineNumber; i <= _endPoint.LineNumber; i++) { ITextSnapshotLine line = snapshot.GetLineFromLineNumber(i); if ((line.Length > 0) && (_endPoint.CurrentPosition != line.Start)) { if (snapshot[line.Start] == '\t') { if (!edit.Delete(new Span(line.Start, 1))) { return(false); } } else { int spacesToRemove = 0; for (; (line.Start + spacesToRemove < snapshot.Length) && (spacesToRemove < _editorOptions.GetTabSize()); spacesToRemove++) { if (snapshot[line.Start + spacesToRemove] != ' ') { break; } } if (spacesToRemove > 0) { if (!edit.Delete(new Span(line.Start, spacesToRemove))) { return(false); } } } } } edit.Apply(); if (edit.Canceled) { return(false); } } return(true); }
public override bool RemovePreviousIndent() { return(_bufferPoint.RemovePreviousIndent()); }