+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'});
+ }
+ }
+ }
+});
+
+handlers.push({keys: [KEYS.ARROW_RIGHT],
+ keydown: function(event, canvas) {
+ /* globals window */
+ var position = canvas.getCursor().getPosition(),
+ element = position.element,
+ next;
+ if(position.offsetAtEnd) {
+ event.preventDefault();
+ next = canvas.getNextTextElement(element);
+ if(next) {
+ scroll('bottom', next.dom[0]);
+ canvas.setCurrentElement(canvas.getDocumentElement(next.dom.contents()[0]), {caretTo: 0});
+ }
+ } else {
+ var secondToLast = (position.offset === element.wlxmlNode.getText().length -1);
+ if(secondToLast) {
+ // Only Flying Spaghetti Monster knows why this is need for FF (for versions at least 26 to 31)
+ event.preventDefault();
+ canvas.setCurrentElement(element, {caretTo: 'end'});
+ }
+ }
+
+ }
+});