"or if the range is collapsed, the cursor itself"
Really the cursor? Because then you might have just passed the cursor into this method, and if the range was collapsed, simply called cursor.getNode(), right?

If I got the logic of the code in case of range.collapsed, then instead the code picks whatever node there is to the left of the cursor node. Though I am slightly puzzled about the check container.hasChildNodes() && range.startOffset < container.childNodes.length: 
given that core.Cursor.getSelectedRange() calls selectedRange.setStartBefore(cursorNode), can't we assume (needs to be promised in the API of getSelectedRange() of course) that the startOffset will be never behind the last childNode of the startcontainer?
Please add some comment to this code, took me some time to get an idea why it might be done.