-handlers.push({key: KEYS.ENTER,
- keydown: function(event, canvas) {
- event.preventDefault();
- var cursor = canvas.getCursor(),
- position = cursor.getPosition(),
- element = position.element,
- added;
+var handleKeyEvent = function(e, s) {
+ keyEventHandlers.some(function(handler) {
+ if(handler.applies(e, s)) {
+ handler.run(e, s);
+ return true;
+ }
+ });
+};
+// todo: whileRemoveWholetext
+var keyEventHandlers = [
+ { // ctrl+x - prevented (?)
+ applies: function(e, s) {
+ return e.ctrlKey &&
+ e.key === KEYS.X &&
+ s.type === 'textSelection' &&
+ s.startsAtBeginning() &&
+ s.endsAtEnd();
+ },
+ run: function(e,s) {
+ void(s);
+ e.preventDefault();
+ }
+ },
+ {
+ applies: function(e, s) {
+ return e.key === KEYS.ARROW_UP && s.type === 'caret';
+ },
+ run: function(e, s) {
+ /* globals window */
+ var caretRect = window.getSelection().getRangeAt(0).getClientRects()[0],
+ frameRects = s.element.dom[0].getClientRects(),
+ caretTop = caretRect.bottom - caretRect.height,
+ position, target,rect, scrolled;