From b823623776a1b3e1aee97fe071a3fc7a39ea35f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Sat, 14 Dec 2013 15:47:58 +0100 Subject: [PATCH 1/1] editor: fix cursor out of text node handling Chrome hack The case where there were no more text nodes above/below was not handled correctly. Now, if that happens, we revert in the opposite direction, ideally to place where we started. This might be better handled at the keydown phase. --- .../modules/documentCanvas/canvas/keyboard.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index 0b876f0..603249e 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -139,18 +139,24 @@ handlers.push({keys: [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.ARROW_LEFT, KEYS.ARRO caretTo = false; if(!element) { // Chrome hack - var direction; - if(event.which === KEYS.ARROW_LEFT || event.which === KEYS.ARROW_UP) { - direction = 'above'; - caretTo = 'end'; - } else { - direction = 'below'; - caretTo = 'start'; + + var moves = [{direction: 'above', caretTo: 'end'}, {direction: 'below', caretTo: 'start'}]; + if(event.which === KEYS.ARROW_RIGHT || event.which === KEYS.ARROW_DOWN) { + moves.reverse(); } - /* 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}); } - canvas.setCurrentElement(element, {caretTo: caretTo}); } }); -- 2.20.1