return false;
}
},
+ _maintainingFocus: function(f) {
+ var el = this.$el.find(".text")[0];
+ var start = el.selectionStart, end = el.selectionEnd;
+ var retVal = f();
+ el.focus();
+ el.setSelectionRange(start, end);
+ return retVal;
+ },
"delete": function() {
// Delete node and its entire subtree
this.focusPrevious();
return false;
},
indent: function() {
- // TODO: maintain focus
- this.model.indent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.indent();
+ }, this));
return false;
},
outdent: function() {
- // TODO: maintain focus
- this.model.outdent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.outdent();
+ }, this));
+ return false;
},
expand: function() {
console.log("Expand not implemented"); // TODO
console.log("Zoom not implemented"); // TODO
},
moveDown: function() {
- // TODO: maintain focus
- this.model.moveDown();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveDown();
+ }, this));
+ return false;
},
moveUp: function() {
- // TODO: maintain focus
- this.model.moveUp();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveUp();
+ }, this));
+ return false;
},
textChange: function(e) {
var lines = $(e.target).html().split(/<br\\?>/);
}
return this;
},
+ removeChild: function(position) {
+ return this.$el.find("> .bullets > *").eq(position).detach();
+ },
render: function() {
if (this.$el.find("> .text").is(":focus")) {
// Don't re-render during editing
newLocation.parent.save();
this.save();
}
- this.collection.trigger("move", this, existingLocation);
+ this.collection.trigger("move", this, existingLocation, newLocation);
return this;
},
moveUp: function() {
addOne: function(todo) {
this.renderTodo(todo);
},
- moveOne: function(todo, oldLocation) {
- var view = this.getView(todo);
-
- var oldParent = oldLocation.parent;
- var oldParentView;
- if (oldParent) oldParentView = this.getView(oldParent);
- if (oldParentView) {
+ moveOne: function(todo, oldLocation, newLocation) {
+ if (oldLocation && oldLocation.parent) {
// Remove from old parent
+ var el = oldLocation.parent.getView().removeChild(oldLocation.index);
+ newLocation.parent.getView().addChild(el, newLocation.index);
+ } else {
+ // Not even on screen somehow, just render
+ this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
}
-
- this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
},
toggleShortcuts: function() {
this.$(".shortcuts").toggle();
return false;
}
},
+ _maintainingFocus: function(f) {
+ var el = this.$el.find(".text")[0];
+ var start = el.selectionStart, end = el.selectionEnd;
+ var retVal = f();
+ el.focus();
+ el.setSelectionRange(start, end);
+ return retVal;
+ },
"delete": function() {
// Delete node and its entire subtree
this.focusPrevious();
return false;
},
indent: function() {
- // TODO: maintain focus
- this.model.indent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.indent();
+ }, this));
return false;
},
outdent: function() {
- // TODO: maintain focus
- this.model.outdent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.outdent();
+ }, this));
+ return false;
},
expand: function() {
console.log("Expand not implemented"); // TODO
console.log("Zoom not implemented"); // TODO
},
moveDown: function() {
- // TODO: maintain focus
- this.model.moveDown();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveDown();
+ }, this));
+ return false;
},
moveUp: function() {
- // TODO: maintain focus
- this.model.moveUp();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveUp();
+ }, this));
+ return false;
},
textChange: function(e) {
var lines = $(e.target).html().split(/<br\\?>/);
}
return this;
},
+ removeChild: function(position) {
+ return this.$el.find("> .bullets > *").eq(position).detach();
+ },
render: function() {
if (this.$el.find("> .text").is(":focus")) {
// Don't re-render during editing
newLocation.parent.save();
this.save();
}
- this.collection.trigger("move", this, existingLocation);
+ this.collection.trigger("move", this, existingLocation, newLocation);
return this;
},
moveUp: function() {
addOne: function(todo) {
this.renderTodo(todo);
},
- moveOne: function(todo, oldLocation) {
- var view = this.getView(todo);
-
- var oldParent = oldLocation.parent;
- var oldParentView;
- if (oldParent) oldParentView = this.getView(oldParent);
- if (oldParentView) {
+ moveOne: function(todo, oldLocation, newLocation) {
+ if (oldLocation && oldLocation.parent) {
// Remove from old parent
+ var el = oldLocation.parent.getView().removeChild(oldLocation.index);
+ newLocation.parent.getView().addChild(el, newLocation.index);
+ } else {
+ // Not even on screen somehow, just render
+ this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
}
-
- this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
},
toggleShortcuts: function() {
this.$(".shortcuts").toggle();
newLocation.parent.save();
this.save();
}
- this.collection.trigger("move", this, existingLocation);
+ this.collection.trigger("move", this, existingLocation, newLocation);
return this;
},
moveUp: function() {
addOne: function(todo) {
this.renderTodo(todo);
},
- moveOne: function(todo, oldLocation) {
- var view = this.getView(todo);
-
- var oldParent = oldLocation.parent;
- var oldParentView;
- if (oldParent) oldParentView = this.getView(oldParent);
- if (oldParentView) {
+ moveOne: function(todo, oldLocation, newLocation) {
+ if (oldLocation && oldLocation.parent) {
// Remove from old parent
+ var el = oldLocation.parent.getView().removeChild(oldLocation.index);
+ newLocation.parent.getView().addChild(el, newLocation.index);
+ } else {
+ // Not even on screen somehow, just render
+ this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
}
-
- this.renderTodo(todo, { rerender: true }); // Don't remove existing view since it's still valid.
},
toggleShortcuts: function() {
this.$(".shortcuts").toggle();
return false;
}
},
+ _maintainingFocus: function(f) {
+ var el = this.$el.find(".text")[0];
+ var start = el.selectionStart, end = el.selectionEnd;
+ var retVal = f();
+ el.focus();
+ el.setSelectionRange(start, end);
+ return retVal;
+ },
"delete": function() {
// Delete node and its entire subtree
this.focusPrevious();
return false;
},
indent: function() {
- // TODO: maintain focus
- this.model.indent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.indent();
+ }, this));
return false;
},
outdent: function() {
- // TODO: maintain focus
- this.model.outdent();
+ this._maintainingFocus(_.bind(function() {
+ this.model.outdent();
+ }, this));
+ return false;
},
expand: function() {
console.log("Expand not implemented"); // TODO
console.log("Zoom not implemented"); // TODO
},
moveDown: function() {
- // TODO: maintain focus
- this.model.moveDown();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveDown();
+ }, this));
+ return false;
},
moveUp: function() {
- // TODO: maintain focus
- this.model.moveUp();
+ this._maintainingFocus(_.bind(function() {
+ this.model.moveUp();
+ }, this));
+ return false;
},
textChange: function(e) {
var lines = $(e.target).html().split(/<br\\?>/);
}
return this;
},
+ removeChild: function(position) {
+ return this.$el.find("> .bullets > *").eq(position).detach();
+ },
render: function() {
if (this.$el.find("> .text").is(":focus")) {
// Don't re-render during editing