From a01353f9eeb3a12415123fb49369d3447bf1df01 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Fri, 22 May 2015 17:57:43 -0700 Subject: [PATCH] Add up and down arrow keys, fixed some things around the end of the list --- dist/flowy.css | 1 + dist/flowy.js | 39 ++++++++++++++++++++++++++++++--------- dist/flowy.unwrapped.js | 39 ++++++++++++++++++++++++++++++--------- src/css/flowy.less | 1 + src/models/todo.js | 14 +++++++++++--- src/views/app.js | 4 ++-- src/views/todo.js | 21 +++++++++++++++++---- 7 files changed, 92 insertions(+), 27 deletions(-) diff --git a/dist/flowy.css b/dist/flowy.css index d931a52..1ae3cd2 100644 --- a/dist/flowy.css +++ b/dist/flowy.css @@ -12,6 +12,7 @@ body { padding-right: 60px; padding-left: 60px; background: #ffffff; + min-height: 552px; } .todo > .text { font-size: 20pt; diff --git a/dist/flowy.js b/dist/flowy.js index 876950d..0542e72 100644 --- a/dist/flowy.js +++ b/dist/flowy.js @@ -404,9 +404,8 @@ var TodoView = Backbone.View.extend({ 'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete", 'Shortcut("backspace", "Combine an item with the previous item", "backspace") > .text': "backspace", 'Shortcut("delete", "Combine an item with the next item", "del") > .text': "delete", - //'Shortcut("next", "Next", "down") > .text': 'next', - //'Shortcut("previous", "Previous", "previous") > .text': 'previous', - + 'Shortcut("next", "Next", "down") > .text': 'next', + 'Shortcut("previous", "Previous", "up") > .text': 'previous', }, initialize: function() { this.childViewPositions = []; @@ -450,12 +449,26 @@ var TodoView = Backbone.View.extend({ } else { this.stopEditingText(); this.model.toggleComplete(); - var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}); + var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection); if (!next) return false; next.getView().startEditingText(); } return false; // Don't propogate }, + next: function() { + var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true }); + if (!nextNode) return false; + this.stopEditingText(); + nextNode.getView().startEditingText(); + return false; + }, + previous: function() { + var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true }); + if (!previousNode) return false; + this.stopEditingText(); + previousNode.getView().startEditingText(); + return false; + }, backspace: function() { if (this.model.hasChildren()) { return; @@ -625,7 +638,7 @@ var TodoModel = Backbone.Model.extend({ return parent.getChild(collection, index + 1); }, nextNode: function(collection, options) { - options = _.defaults({}, options, {"childrenAllowed": true}); + options = _.defaults({}, options, {childrenAllowed: true}); if (options.childrenAllowed) { if (this.hasChildren()) { return this.getChild(collection, 0); @@ -637,8 +650,16 @@ var TodoModel = Backbone.Model.extend({ } return undefined; }, - previousNode: function(collection) { - var previous = this.getPreviousSibling(collection) || this.getParent(collection); + previousNode: function(collection, options) { + options = _.defaults({}, options, {childrenAllowed: true}); + var previous = this.getPreviousSibling(collection); + if (previous && options.childrenAllowed) { + while (previous.hasChildren()) { + previous = previous.getChild(collection, previous.getChildrenCount() - 1); + } + } + if (!previous) previous = this.getParent(collection); + if (!previous) return undefined; if (previous.id === collection.rootId) { return undefined; } else { @@ -771,7 +792,7 @@ var testTodos = [ parent: 0, id: 5, text: "To do this year", - collapsed: true, + collapsed: false, bullets: [6], }), new TodoModel({ @@ -811,7 +832,7 @@ var AppView = Backbone.View.extend({ e.save(); }); }); - Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete'] }); + Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete', 'next', 'previous'] }); this.views = {}; // A list of views for each element in the collection this.list.fetch(); this.render(); diff --git a/dist/flowy.unwrapped.js b/dist/flowy.unwrapped.js index 6ddd069..7aa1761 100644 --- a/dist/flowy.unwrapped.js +++ b/dist/flowy.unwrapped.js @@ -403,9 +403,8 @@ var TodoView = Backbone.View.extend({ 'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete", 'Shortcut("backspace", "Combine an item with the previous item", "backspace") > .text': "backspace", 'Shortcut("delete", "Combine an item with the next item", "del") > .text': "delete", - //'Shortcut("next", "Next", "down") > .text': 'next', - //'Shortcut("previous", "Previous", "previous") > .text': 'previous', - + 'Shortcut("next", "Next", "down") > .text': 'next', + 'Shortcut("previous", "Previous", "up") > .text': 'previous', }, initialize: function() { this.childViewPositions = []; @@ -449,12 +448,26 @@ var TodoView = Backbone.View.extend({ } else { this.stopEditingText(); this.model.toggleComplete(); - var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}); + var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection); if (!next) return false; next.getView().startEditingText(); } return false; // Don't propogate }, + next: function() { + var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true }); + if (!nextNode) return false; + this.stopEditingText(); + nextNode.getView().startEditingText(); + return false; + }, + previous: function() { + var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true }); + if (!previousNode) return false; + this.stopEditingText(); + previousNode.getView().startEditingText(); + return false; + }, backspace: function() { if (this.model.hasChildren()) { return; @@ -624,7 +637,7 @@ var TodoModel = Backbone.Model.extend({ return parent.getChild(collection, index + 1); }, nextNode: function(collection, options) { - options = _.defaults({}, options, {"childrenAllowed": true}); + options = _.defaults({}, options, {childrenAllowed: true}); if (options.childrenAllowed) { if (this.hasChildren()) { return this.getChild(collection, 0); @@ -636,8 +649,16 @@ var TodoModel = Backbone.Model.extend({ } return undefined; }, - previousNode: function(collection) { - var previous = this.getPreviousSibling(collection) || this.getParent(collection); + previousNode: function(collection, options) { + options = _.defaults({}, options, {childrenAllowed: true}); + var previous = this.getPreviousSibling(collection); + if (previous && options.childrenAllowed) { + while (previous.hasChildren()) { + previous = previous.getChild(collection, previous.getChildrenCount() - 1); + } + } + if (!previous) previous = this.getParent(collection); + if (!previous) return undefined; if (previous.id === collection.rootId) { return undefined; } else { @@ -770,7 +791,7 @@ var testTodos = [ parent: 0, id: 5, text: "To do this year", - collapsed: true, + collapsed: false, bullets: [6], }), new TodoModel({ @@ -810,7 +831,7 @@ var AppView = Backbone.View.extend({ e.save(); }); }); - Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete'] }); + Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete', 'next', 'previous'] }); this.views = {}; // A list of views for each element in the collection this.list.fetch(); this.render(); diff --git a/src/css/flowy.less b/src/css/flowy.less index 5d03024..9092e00 100644 --- a/src/css/flowy.less +++ b/src/css/flowy.less @@ -13,6 +13,7 @@ body { padding-right: 60px; padding-left: 60px; background: #ffffff; + min-height: 552px; } .todo > .text { diff --git a/src/models/todo.js b/src/models/todo.js index 08b0410..c33a2cf 100644 --- a/src/models/todo.js +++ b/src/models/todo.js @@ -50,7 +50,7 @@ var TodoModel = Backbone.Model.extend({ return parent.getChild(collection, index + 1); }, nextNode: function(collection, options) { - options = _.defaults({}, options, {"childrenAllowed": true}); + options = _.defaults({}, options, {childrenAllowed: true}); if (options.childrenAllowed) { if (this.hasChildren()) { return this.getChild(collection, 0); @@ -62,8 +62,16 @@ var TodoModel = Backbone.Model.extend({ } return undefined; }, - previousNode: function(collection) { - var previous = this.getPreviousSibling(collection) || this.getParent(collection); + previousNode: function(collection, options) { + options = _.defaults({}, options, {childrenAllowed: true}); + var previous = this.getPreviousSibling(collection); + if (previous && options.childrenAllowed) { + while (previous.hasChildren()) { + previous = previous.getChild(collection, previous.getChildrenCount() - 1); + } + } + if (!previous) previous = this.getParent(collection); + if (!previous) return undefined; if (previous.id === collection.rootId) { return undefined; } else { diff --git a/src/views/app.js b/src/views/app.js index ca9cd29..ee325d8 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -39,7 +39,7 @@ var testTodos = [ parent: 0, id: 5, text: "To do this year", - collapsed: true, + collapsed: false, bullets: [6], }), new TodoModel({ @@ -79,7 +79,7 @@ var AppView = Backbone.View.extend({ e.save(); }); }); - Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete'] }); + Shortcut.bindShortcutsDisplay(this.$("#shortcuts-wrapper")[0], {allowRebind: true, noDisplay: ['backspace', 'delete', 'next', 'previous'] }); this.views = {}; // A list of views for each element in the collection this.list.fetch(); this.render(); diff --git a/src/views/todo.js b/src/views/todo.js index 03a6a44..e4be2e5 100644 --- a/src/views/todo.js +++ b/src/views/todo.js @@ -14,9 +14,8 @@ var TodoView = Backbone.View.extend({ 'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete", 'Shortcut("backspace", "Combine an item with the previous item", "backspace") > .text': "backspace", 'Shortcut("delete", "Combine an item with the next item", "del") > .text': "delete", - //'Shortcut("next", "Next", "down") > .text': 'next', - //'Shortcut("previous", "Previous", "previous") > .text': 'previous', - + 'Shortcut("next", "Next", "down") > .text': 'next', + 'Shortcut("previous", "Previous", "up") > .text': 'previous', }, initialize: function() { this.childViewPositions = []; @@ -60,12 +59,26 @@ var TodoView = Backbone.View.extend({ } else { this.stopEditingText(); this.model.toggleComplete(); - var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}); + var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection); if (!next) return false; next.getView().startEditingText(); } return false; // Don't propogate }, + next: function() { + var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true }); + if (!nextNode) return false; + this.stopEditingText(); + nextNode.getView().startEditingText(); + return false; + }, + previous: function() { + var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true }); + if (!previousNode) return false; + this.stopEditingText(); + previousNode.getView().startEditingText(); + return false; + }, backspace: function() { if (this.model.hasChildren()) { return; -- 2.47.3