private ITextSnapshotLine GetSelectionEndLine(ITextSnapshotLine selectionStartLine) { var selectionEndLine = textView.Selection.End.Position.GetContainingLine(); // if the selection ends exactly at the beginning of a new line (ie line select), we do not comment out the last line if (!selectionStartLine.Equals(selectionEndLine) && selectionEndLine.Start.Equals(textView.Selection.End.Position)) { selectionEndLine = selectionEndLine.Snapshot.GetLineFromLineNumber(selectionEndLine.LineNumber - 1); } return selectionEndLine; }