- /* globals window */
- element = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', direction, window.getSelection().focusNode));
+ moves.some(function(move) {
+ /* globals window */
+ var targetNode = utils.nearestInDocumentOrder('[document-text-element]:visible', move.direction, window.getSelection().focusNode);
+ if(targetNode) {
+ element = canvas.getDocumentElement(targetNode);
+ caretTo = move.caretTo;
+ return true; // break
+ }
+ });
+ }
+ if(element) {
+ canvas.setCurrentElement(element, {caretTo: caretTo});