         offset = down.offset ?= positionOffset(down.clientX) - @segment.l
         pos = positionOffset(up.clientX) - offset
         return unless isFinite(pos)
-        pos = snapping()
+        pos = snapping(pos, @)
         @setPosition(pos)
         if up.type != 'mousemove'
           $scope.updatePosition()


      dragLeft: (event) ->
        @segment.l = positionOffset(event.clientX)
        snapping(@segment.l)
        if event.type != 'mousemove'
          $scope.form.position.$setDirty()
        return

      dragRight: (event) ->
        @segment.u = positionOffset(event.clientX)
        if event.type != 'mousemove'
          $scope.form.position.$setDirty()
        return

      fullRange.u = finite(slot.segment.u, u, 0)
      return

    tl = document.getElementById('slot-timeline')

    # Takes a time position and convert it to an offset in pixels. 
    getOffsetPixels = (item) ->
      #Grab the fraction offset of the item.
      op = offsetPosition(item)

      # Grab the surrounding rectangle.
      tlr  = tl.getBoundingClientRect()

      #Grab the width of the surrounding rectangle.
      totalPixels = tlr.width

      # Since we have the fraction and the total pixels, we can simply do
      # some multiplication and grab the offset pixels.
      offsetPixels = op * totalPixels

      # Return back the offset pixels.
      return offsetPixels



    snapping = (selectionEnd, exclude) ->
      listOfAllPlacements = []
      selectionOffsetPixels = getOffsetPixels selectionEnd
      $scope.tracks.concat(records, $scope.consents).forEach (i) ->
        if i is exclude then return
        if isFinite(i.segment?.l)
          listOfAllPlacements.push i.segment.l
        if isFinite(i.segment?.u)
          listOfAllPlacements.push i.segment.u
      if listOfAllPlacements.length == 0
        return selectionEnd

      min = _.min listOfAllPlacements, (i) ->
        Math.abs(selectionOffsetPixels - getOffsetPixels(i))
      if Math.abs(selectionOffsetPixels - getOffsetPixels(min)) <= 10
        return min
      else
        return selectionEnd

    # Takes a time position and turns it into a fraction.
    offsetPosition = (offset) ->
      return offset unless isFinite offset
      (offset - ruler.range.base) / (ruler.range.u - ruler.range.l)


    # Takes a position in pixels returns a time position offset.
    positionOffset = (position) ->
      tlr = tl.getBoundingClientRect()
      p = (position - tlr.left) / tlr.width
