editor: canvas arrow key navigation improvements
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:01:04 +0000 (16:01 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:07:20 +0000 (16:07 +0200)
src/editor/modules/documentCanvas/canvas/keyboard.js

index aae19a0..e2479a5 100644 (file)
@@ -318,6 +318,17 @@ var keyEventHandlers = [
                     s.canvas.setCurrentElement(s.canvas.getDocumentElement(position.textNode), {caretTo: position.offset});
                 }
             }
                     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});
                 }
             }
                     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});
+            }
         }
     },
     {
         }
     },
     {