+ caretRect = window.getSelection().getRangeAt(0).getClientRects()[0],
+ frameRects = element.dom[0].getClientRects(),
+ lastRect = frameRects[frameRects.length-1],
+ position, target,rect, scrolled;
+
+ if(lastRect.bottom === caretRect.bottom || (caretRect.left > lastRect.left + lastRect.width)) {
+ event.preventDefault();
+ canvas.rootWrapper.find('[document-text-element]').each(function() {
+ var test = getFirstRectBelow(this, caretRect.bottom);
+ if(test) {
+ target = this;
+ rect = test;
+ return false;
+ }
+ });
+ if(target) {
+ scrolled = scroll('bottom', target);
+ position = utils.caretPositionFromPoint(caretRect.left, rect.top +1 - scrolled);
+ canvas.setCurrentElement(canvas.getDocumentElement(position.textNode), {caretTo: position.offset});
+ }
+ }
+ }
+});
+
+handlers.push({keys: [KEYS.ARROW_LEFT],
+ keydown: function(event, canvas) {
+ /* globals window */
+ var position = canvas.getCursor().getPosition(),
+ element = position.element,
+ prev;
+
+ if(position.offset === 0) {
+ event.preventDefault();
+ prev = canvas.getPreviousTextElement(element);
+ if(prev) {
+ scroll('top', prev.dom[0]);
+ canvas.setCurrentElement(canvas.getDocumentElement(prev.dom.contents()[0]), {caretTo: 'end'});