From 457a2c13a27a5fd49bdd5b0162111e3a9220a6ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 14 Aug 2014 16:01:04 +0200 Subject: [PATCH] editor: canvas arrow key navigation improvements --- .../modules/documentCanvas/canvas/keyboard.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index aae19a0..e2479a5 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -318,6 +318,17 @@ var keyEventHandlers = [ s.canvas.setCurrentElement(s.canvas.getDocumentElement(position.textNode), {caretTo: position.offset}); } } + if(target) { + scrolled = scroll('top', target); + var left = caretRect.left; + if(left > rect.left + rect.width) { + left = rect.left + rect.width; + } else if(left < rect.left ) { + left = rect.left; + } + position = utils.caretPositionFromPoint(left, rect.bottom - 1 - scrolled); + s.canvas.setCurrentElement(s.canvas.getDocumentElement(position.textNode), {caretTo: position.offset}); + } } }, { @@ -347,6 +358,17 @@ var keyEventHandlers = [ s.canvas.setCurrentElement(s.canvas.getDocumentElement(position.textNode), {caretTo: position.offset}); } } + if(target) { + scrolled = scroll('bottom', target); + var left = caretRect.left; + if(left > rect.left + rect.width) { + left = rect.left + rect.width; + } else if(left < rect.left ) { + left = rect.left; + } + position = utils.caretPositionFromPoint(left, rect.top +1 - scrolled); + s.canvas.setCurrentElement(s.canvas.getDocumentElement(position.textNode), {caretTo: position.offset}); + } } }, { -- 2.20.1