//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "backspace",
+ "keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- backspace: function(e) {
- if (e.keyCode !== 46 /* backspace */ && e.keyCode !== 8 /* delete */) {
- return;
+ keydown: function(e) {
+ if (e.keyCode == 46 /* backspace */ || e.keyCode == 8 /* delete */) {
+ return this.backspace(e);
+ } else if (e.keyCode == 17) {
+ return this.control(e);
+ } else {
+ console.log(e.keyCode + " key pressed");
}
+ },
+ control: function(e) {
+ this.stopEditingText();
+ this.model.toggleComplete();
+ var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ next.getView().startEditingText();
+ },
+ backspace: function(e) {
if (this.model.hasChildren()) {
return;
}
hasChildren: function() {
return this.get("bullets").length > 0;
},
+ getChildrenCount: function() {
+ return this.get("bullets").length;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
var index = parent.findChild(this.id);
- if (index <= 0) return undefined;
- return parent.getChild(collection, index-1);
+ if (index < 0 || index === 0) return undefined;
+ return parent.getChild(collection, index - 1);
+ },
+ getNextSibling: function(collection) {
+ var parent = this.getParent(collection);
+ var index = parent.findChild(this.id);
+ var numChildren = parent.getChildrenCount();
+ if (index < 0 || index === numChildren - 1) return undefined;
+ return parent.getChild(collection, index + 1);
+ },
+ nextNode: function(collection, options) {
+ options = _.defaults({}, options, {"childrenAllowed": true});
+ if (options.childrenAllowed) {
+ if (this.hasChildren()) {
+ return this.getChild(collection, 0);
+ }
+ }
+ for (var node = this; node && node.id !== collection.rootId; node = node.getParent(collection)) {
+ var next = node.getNextSibling(collection);
+ if (next) return next;
+ }
+ return undefined;
},
previousNode: function(collection) {
var previous = this.getPreviousSibling(collection) || this.getParent(collection);
//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "backspace",
+ "keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- backspace: function(e) {
- if (e.keyCode !== 46 /* backspace */ && e.keyCode !== 8 /* delete */) {
- return;
+ keydown: function(e) {
+ if (e.keyCode == 46 /* backspace */ || e.keyCode == 8 /* delete */) {
+ return this.backspace(e);
+ } else if (e.keyCode == 17) {
+ return this.control(e);
+ } else {
+ console.log(e.keyCode + " key pressed");
}
+ },
+ control: function(e) {
+ this.stopEditingText();
+ this.model.toggleComplete();
+ var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ next.getView().startEditingText();
+ },
+ backspace: function(e) {
if (this.model.hasChildren()) {
return;
}
hasChildren: function() {
return this.get("bullets").length > 0;
},
+ getChildrenCount: function() {
+ return this.get("bullets").length;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
var index = parent.findChild(this.id);
- if (index <= 0) return undefined;
- return parent.getChild(collection, index-1);
+ if (index < 0 || index === 0) return undefined;
+ return parent.getChild(collection, index - 1);
+ },
+ getNextSibling: function(collection) {
+ var parent = this.getParent(collection);
+ var index = parent.findChild(this.id);
+ var numChildren = parent.getChildrenCount();
+ if (index < 0 || index === numChildren - 1) return undefined;
+ return parent.getChild(collection, index + 1);
+ },
+ nextNode: function(collection, options) {
+ options = _.defaults({}, options, {"childrenAllowed": true});
+ if (options.childrenAllowed) {
+ if (this.hasChildren()) {
+ return this.getChild(collection, 0);
+ }
+ }
+ for (var node = this; node && node.id !== collection.rootId; node = node.getParent(collection)) {
+ var next = node.getNextSibling(collection);
+ if (next) return next;
+ }
+ return undefined;
},
previousNode: function(collection) {
var previous = this.getPreviousSibling(collection) || this.getParent(collection);
hasChildren: function() {
return this.get("bullets").length > 0;
},
+ getChildrenCount: function() {
+ return this.get("bullets").length;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
var index = parent.findChild(this.id);
- if (index <= 0) return undefined;
- return parent.getChild(collection, index-1);
+ if (index < 0 || index === 0) return undefined;
+ return parent.getChild(collection, index - 1);
+ },
+ getNextSibling: function(collection) {
+ var parent = this.getParent(collection);
+ var index = parent.findChild(this.id);
+ var numChildren = parent.getChildrenCount();
+ if (index < 0 || index === numChildren - 1) return undefined;
+ return parent.getChild(collection, index + 1);
+ },
+ nextNode: function(collection, options) {
+ options = _.defaults({}, options, {"childrenAllowed": true});
+ if (options.childrenAllowed) {
+ if (this.hasChildren()) {
+ return this.getChild(collection, 0);
+ }
+ }
+ for (var node = this; node && node.id !== collection.rootId; node = node.getParent(collection)) {
+ var next = node.getNextSibling(collection);
+ if (next) return next;
+ }
+ return undefined;
},
previousNode: function(collection) {
var previous = this.getPreviousSibling(collection) || this.getParent(collection);
//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "backspace",
+ "keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- backspace: function(e) {
- if (e.keyCode !== 46 /* backspace */ && e.keyCode !== 8 /* delete */) {
- return;
+ keydown: function(e) {
+ if (e.keyCode == 46 /* backspace */ || e.keyCode == 8 /* delete */) {
+ return this.backspace(e);
+ } else if (e.keyCode == 17) {
+ return this.control(e);
+ } else {
+ console.log(e.keyCode + " key pressed");
}
+ },
+ control: function(e) {
+ this.stopEditingText();
+ this.model.toggleComplete();
+ var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ next.getView().startEditingText();
+ },
+ backspace: function(e) {
if (this.model.hasChildren()) {
return;
}