'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("indent", "Indent", "tab,alt+shift+right") > .text': 'indent',
'Shortcut("outdent", "Outdent", "shift+tab,alt+shift+left") > .text': 'outdent',
- 'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
- 'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
+ 'Shortcut("moveDown", "Move", "alt+shift+down") > .text': 'moveDown',
+ 'Shortcut("moveUp", "Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},
getChild: function(index) {
return this.collection.get(this.get("bullets")[index]);
},
+ lastChild: function() {
+ return this.getChild(this.getChildrenCount()-1);
+ },
getParent: function(options) {
options = _.defaults({}, options, { rootAllowed: true });
var parent = this.collection.get(this.get("parent"));
return previous;
}
},
- getView: function() { //TODO: remove
+ getView: function() {
return this.collection.app.getView(this);
},
isTopLevel: function() {
return this;
},
moveUp: function() {
- // Before previous sibling, then as last child of previous node of parent, then before parent, then nothing
+ // Before previous sibling, then as last descendent of previous node of parent, then before parent, then nothing
+ var previousSibling = this.getPreviousSibling();
+ if (previousSibling) {
+ return this.moveTo({
+ parent: this.getParent(),
+ index: this.getParent().findChild(previousSibling.id),
+ });
+ }
+ var parent = this.getParent();
+ if (parent.isRoot()) return undefined; // Top-level node with no previous sibling
+ var previousSiblingOfParent = parent.getPreviousSibling();
+ if (previousSiblingOfParent) {
+ // Insert as final child
+ return this.moveTo({
+ parent: previousSiblingOfParent,
+ index: previousSiblingOfParent.getChildrenCount(),
+ });
+ } else {
+ // This is a first child of a first child of ... the first top-level node.
+ // Place before the parent.
+ var grandparent = parent.getParent();
+ var parentIndex = grandparent.findChild(parent.id);
+ return this.moveTo({
+ parent: grandparent,
+ index: parentIndex,
+ });
+ }
},
moveDown: function() {
- // After next sibling, then as first child of next node after parent, then up one level, then nothing
+ // After next sibling, then as first child of next node after parent, then up one level (after parent), then nothing
+ var nextSibling = this.getNextSibling();
+ var parent = this.getParent();
+ if (nextSibling) {
+ return this.moveTo({
+ parent: parent,
+ index: parent.findChild(nextSibling.id),
+ });
+ }
+ var parentNextSibling = parent.getNextSibling();
+ if (parentNextSibling) {
+ return this.moveTo({
+ parent: parentNextSibling,
+ index: 0,
+ });
+ } else if (!this.isTopLevel()) { // Last child of last child of ... of last top-level node
+ var grandparent = parent.getParent();
+ return this.moveTo({
+ parent: grandparent,
+ index: grandparent.findChild(parent.id) + 1,
+ });
+ } else {
+ return undefined; // Last top-level node
+ }
},
indent: function() {
// Last child of previous sibling, then nothing
'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("indent", "Indent", "tab,alt+shift+right") > .text': 'indent',
'Shortcut("outdent", "Outdent", "shift+tab,alt+shift+left") > .text': 'outdent',
- 'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
- 'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
+ 'Shortcut("moveDown", "Move", "alt+shift+down") > .text': 'moveDown',
+ 'Shortcut("moveUp", "Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},
getChild: function(index) {
return this.collection.get(this.get("bullets")[index]);
},
+ lastChild: function() {
+ return this.getChild(this.getChildrenCount()-1);
+ },
getParent: function(options) {
options = _.defaults({}, options, { rootAllowed: true });
var parent = this.collection.get(this.get("parent"));
return previous;
}
},
- getView: function() { //TODO: remove
+ getView: function() {
return this.collection.app.getView(this);
},
isTopLevel: function() {
return this;
},
moveUp: function() {
- // Before previous sibling, then as last child of previous node of parent, then before parent, then nothing
+ // Before previous sibling, then as last descendent of previous node of parent, then before parent, then nothing
+ var previousSibling = this.getPreviousSibling();
+ if (previousSibling) {
+ return this.moveTo({
+ parent: this.getParent(),
+ index: this.getParent().findChild(previousSibling.id),
+ });
+ }
+ var parent = this.getParent();
+ if (parent.isRoot()) return undefined; // Top-level node with no previous sibling
+ var previousSiblingOfParent = parent.getPreviousSibling();
+ if (previousSiblingOfParent) {
+ // Insert as final child
+ return this.moveTo({
+ parent: previousSiblingOfParent,
+ index: previousSiblingOfParent.getChildrenCount(),
+ });
+ } else {
+ // This is a first child of a first child of ... the first top-level node.
+ // Place before the parent.
+ var grandparent = parent.getParent();
+ var parentIndex = grandparent.findChild(parent.id);
+ return this.moveTo({
+ parent: grandparent,
+ index: parentIndex,
+ });
+ }
},
moveDown: function() {
- // After next sibling, then as first child of next node after parent, then up one level, then nothing
+ // After next sibling, then as first child of next node after parent, then up one level (after parent), then nothing
+ var nextSibling = this.getNextSibling();
+ var parent = this.getParent();
+ if (nextSibling) {
+ return this.moveTo({
+ parent: parent,
+ index: parent.findChild(nextSibling.id),
+ });
+ }
+ var parentNextSibling = parent.getNextSibling();
+ if (parentNextSibling) {
+ return this.moveTo({
+ parent: parentNextSibling,
+ index: 0,
+ });
+ } else if (!this.isTopLevel()) { // Last child of last child of ... of last top-level node
+ var grandparent = parent.getParent();
+ return this.moveTo({
+ parent: grandparent,
+ index: grandparent.findChild(parent.id) + 1,
+ });
+ } else {
+ return undefined; // Last top-level node
+ }
},
indent: function() {
// Last child of previous sibling, then nothing
getChild: function(index) {
return this.collection.get(this.get("bullets")[index]);
},
+ lastChild: function() {
+ return this.getChild(this.getChildrenCount()-1);
+ },
getParent: function(options) {
options = _.defaults({}, options, { rootAllowed: true });
var parent = this.collection.get(this.get("parent"));
return previous;
}
},
- getView: function() { //TODO: remove
+ getView: function() {
return this.collection.app.getView(this);
},
isTopLevel: function() {
return this;
},
moveUp: function() {
- // Before previous sibling, then as last child of previous node of parent, then before parent, then nothing
+ // Before previous sibling, then as last descendent of previous node of parent, then before parent, then nothing
+ var previousSibling = this.getPreviousSibling();
+ if (previousSibling) {
+ return this.moveTo({
+ parent: this.getParent(),
+ index: this.getParent().findChild(previousSibling.id),
+ });
+ }
+ var parent = this.getParent();
+ if (parent.isRoot()) return undefined; // Top-level node with no previous sibling
+ var previousSiblingOfParent = parent.getPreviousSibling();
+ if (previousSiblingOfParent) {
+ // Insert as final child
+ return this.moveTo({
+ parent: previousSiblingOfParent,
+ index: previousSiblingOfParent.getChildrenCount(),
+ });
+ } else {
+ // This is a first child of a first child of ... the first top-level node.
+ // Place before the parent.
+ var grandparent = parent.getParent();
+ var parentIndex = grandparent.findChild(parent.id);
+ return this.moveTo({
+ parent: grandparent,
+ index: parentIndex,
+ });
+ }
},
moveDown: function() {
- // After next sibling, then as first child of next node after parent, then up one level, then nothing
+ // After next sibling, then as first child of next node after parent, then up one level (after parent), then nothing
+ var nextSibling = this.getNextSibling();
+ var parent = this.getParent();
+ if (nextSibling) {
+ return this.moveTo({
+ parent: parent,
+ index: parent.findChild(nextSibling.id),
+ });
+ }
+ var parentNextSibling = parent.getNextSibling();
+ if (parentNextSibling) {
+ return this.moveTo({
+ parent: parentNextSibling,
+ index: 0,
+ });
+ } else if (!this.isTopLevel()) { // Last child of last child of ... of last top-level node
+ var grandparent = parent.getParent();
+ return this.moveTo({
+ parent: grandparent,
+ index: grandparent.findChild(parent.id) + 1,
+ });
+ } else {
+ return undefined; // Last top-level node
+ }
},
indent: function() {
// Last child of previous sibling, then nothing
'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("indent", "Indent", "tab,alt+shift+right") > .text': 'indent',
'Shortcut("outdent", "Outdent", "shift+tab,alt+shift+left") > .text': 'outdent',
- 'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
- 'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
+ 'Shortcut("moveDown", "Move", "alt+shift+down") > .text': 'moveDown',
+ 'Shortcut("moveUp", "Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},