if (e.keyCode !== 8 /* backspace */ && e.keyCode !== 46 /* delete */) {
return;
}
- if (this.model.get("text") !== "") {
- return;
+ if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.hasChildren()) {
+ return;
+ }
+ // TODO: Focus end of previous node
+ var previousNode = this.model.previousNode(this.model.collection);
+ if (!previousNode) {
+ return;
+ }
+ e.preventDefault();
+ this.model.remove(this.model.collection);
+ previousNode.getView().startEditingText({"atEnd":true});
}
- e.preventDefault();
- // TODO: Focus end of previous node
- //var previousNode = this.model.previousNode(this.model.collection);
- this.model.remove(this.model.collection);
- //var previousNodeView = this.collectionView.getViewFor(previousNode);
- //var previousNodeView.startEditingText({"atEnd":true});
},
textChange: function(e) {
var collection = this.model.collection;
setText: function(text) {
this.save({text: text});
},
+ hasChildren: function() {
+ return this.get("bullets").length > 0;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
}, this);
},
+ getChild: function(collection, index) {
+ return collection.get(this.get("bullets")[index]);
+ },
getParent: function(collection) {
return collection.get(this.get("parent"));
},
+ 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);
+ },
+ previousNode: function(collection) {
+ var previous = this.getPreviousSibling(collection) || this.getParent(collection);
+ if (previous.id === collection.rootId) {
+ return undefined;
+ } else {
+ return previous;
+ }
+ },
+ getView: function() { //TODO: remove
+ return this.collection.app.getView(this);
+ },
isTopLevel: function(collection) {
return this.get("parent") === collection.rootId;
},
initialize: function(options) {
options = _.defaults({}, options, appDefaults);
this.list = options.list || new FlowyDocModel();
+ this.list.app = this;
this.listenTo(this.list, 'add', this.addOne);
this.listenTo(this.list, 'reset', this.addAll);
var self = this;
if (e.keyCode !== 8 /* backspace */ && e.keyCode !== 46 /* delete */) {
return;
}
- if (this.model.get("text") !== "") {
- return;
+ if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.hasChildren()) {
+ return;
+ }
+ // TODO: Focus end of previous node
+ var previousNode = this.model.previousNode(this.model.collection);
+ if (!previousNode) {
+ return;
+ }
+ e.preventDefault();
+ this.model.remove(this.model.collection);
+ previousNode.getView().startEditingText({"atEnd":true});
}
- e.preventDefault();
- // TODO: Focus end of previous node
- //var previousNode = this.model.previousNode(this.model.collection);
- this.model.remove(this.model.collection);
- //var previousNodeView = this.collectionView.getViewFor(previousNode);
- //var previousNodeView.startEditingText({"atEnd":true});
},
textChange: function(e) {
var collection = this.model.collection;
setText: function(text) {
this.save({text: text});
},
+ hasChildren: function() {
+ return this.get("bullets").length > 0;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
}, this);
},
+ getChild: function(collection, index) {
+ return collection.get(this.get("bullets")[index]);
+ },
getParent: function(collection) {
return collection.get(this.get("parent"));
},
+ 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);
+ },
+ previousNode: function(collection) {
+ var previous = this.getPreviousSibling(collection) || this.getParent(collection);
+ if (previous.id === collection.rootId) {
+ return undefined;
+ } else {
+ return previous;
+ }
+ },
+ getView: function() { //TODO: remove
+ return this.collection.app.getView(this);
+ },
isTopLevel: function(collection) {
return this.get("parent") === collection.rootId;
},
initialize: function(options) {
options = _.defaults({}, options, appDefaults);
this.list = options.list || new FlowyDocModel();
+ this.list.app = this;
this.listenTo(this.list, 'add', this.addOne);
this.listenTo(this.list, 'reset', this.addAll);
var self = this;
setText: function(text) {
this.save({text: text});
},
+ hasChildren: function() {
+ return this.get("bullets").length > 0;
+ },
getChildren: function(collection) {
return _.map(this.get("bullets"), function(id) {
return collection.get(id);
}, this);
},
+ getChild: function(collection, index) {
+ return collection.get(this.get("bullets")[index]);
+ },
getParent: function(collection) {
return collection.get(this.get("parent"));
},
+ 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);
+ },
+ previousNode: function(collection) {
+ var previous = this.getPreviousSibling(collection) || this.getParent(collection);
+ if (previous.id === collection.rootId) {
+ return undefined;
+ } else {
+ return previous;
+ }
+ },
+ getView: function() { //TODO: remove
+ return this.collection.app.getView(this);
+ },
isTopLevel: function(collection) {
return this.get("parent") === collection.rootId;
},
initialize: function(options) {
options = _.defaults({}, options, appDefaults);
this.list = options.list || new FlowyDocModel();
+ this.list.app = this;
this.listenTo(this.list, 'add', this.addOne);
this.listenTo(this.list, 'reset', this.addAll);
var self = this;
if (e.keyCode !== 8 /* backspace */ && e.keyCode !== 46 /* delete */) {
return;
}
- if (this.model.get("text") !== "") {
- return;
+ if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.hasChildren()) {
+ return;
+ }
+ // TODO: Focus end of previous node
+ var previousNode = this.model.previousNode(this.model.collection);
+ if (!previousNode) {
+ return;
+ }
+ e.preventDefault();
+ this.model.remove(this.model.collection);
+ previousNode.getView().startEditingText({"atEnd":true});
}
- e.preventDefault();
- // TODO: Focus end of previous node
- //var previousNode = this.model.previousNode(this.model.collection);
- this.model.remove(this.model.collection);
- //var previousNodeView = this.collectionView.getViewFor(previousNode);
- //var previousNodeView.startEditingText({"atEnd":true});
},
textChange: function(e) {
var collection = this.model.collection;