 
 # From element and its parents, find the first which we should scroll and which does scroll.
 findScrollableElement = (element, direction, amount, factor) ->
-  while element != document.body and
+  while element != document.documentElement and
     not (doesScroll(element, direction, amount, factor) and shouldScroll(element, direction))
-      element = element.parentElement || document.body
+      element = element.parentElement || document.documentElement
   element
 
-# On some pages, document.body is not scrollable.  Here, we search the document for the largest visible
+# On some pages, document.documentElement is not scrollable.  Here, we search the document for the largest visible
 # element which does scroll vertically. This is used to initialize activatedElement. See #1358.
-firstScrollableElement = (element=document.body) ->
+firstScrollableElement = (element=document.documentElement) ->
   if doesScroll(element, "y", 1, 1) or doesScroll(element, "y", -1, 1)
     element
   else

    name = amount
    # the clientSizes of the body are the dimensions of the entire page, but the viewport should only be the
    # part visible through the window
    if name is 'viewSize' and el is document.body
      # TODO(smblott) Should we not be returning the width/height of element, here?
      if direction is 'x' then window.innerWidth else window.innerHeight
    else

  # Scroll element to position top, left.  This is used by edit mode to ensure that the caret remains visible
  # in text inputs (not contentEditable).
  scrollToPosition: (element, top, left) ->
    activatedElement ||= document.documentElement and firstScrollableElement()

    # Scroll down, "y".
    amount = top + 20 - (element.clientHeight + element.scrollTop)
