From: Zachary Vance Date: Tue, 12 May 2015 03:10:42 +0000 (-0700) Subject: Make inserting work correctly visually X-Git-Url: https://git.za3k.com/?a=commitdiff_plain;h=4ed3c1c6eb19087ce1c98ba8f6ebf21062f84ec2;p=flowy.git Make inserting work correctly visually --- diff --git a/dist/flowy.js b/dist/flowy.js index 35b3122..99d7cf9 100644 --- a/dist/flowy.js +++ b/dist/flowy.js @@ -109,13 +109,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; }, @@ -252,7 +250,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/dist/flowy.unwrapped.js b/dist/flowy.unwrapped.js index a4d114f..e956425 100644 --- a/dist/flowy.unwrapped.js +++ b/dist/flowy.unwrapped.js @@ -108,13 +108,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; }, @@ -251,7 +249,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/src/views/app.js b/src/views/app.js index 636cb22..202c746 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -8,7 +8,7 @@ var testTodos = [ new TodoModel({ parent: null, id: 0, - text: "Root (will be invisible in final)", + text: "Root (will be invisible in final, DO NOT EDIT)", bullets: [1, 5], }), new TodoModel({ diff --git a/src/views/todo.js b/src/views/todo.js index 48a4501..145ab7b 100644 --- a/src/views/todo.js +++ b/src/views/todo.js @@ -108,13 +108,11 @@ var TodoView = Backbone.View.extend({ return this; } // Position was given as an index into the children array, not relative to inserted elements in the DOM. - // So, convert to index relative to things inserted so far - var relativePosition = _.chain(this.childViewPositions).where(function(x) { return x<= position; }).size().value(); - this.childViewPositions.push(position); - if (relativePosition === 0) { + // Nonetheless assume they're the same (either we're inserting in the middle of a populated array, or we're loading in order) + if (position === 0) { this.$el.find("> .bullets").prepend(el); } else { - this.$el.find("> .bullets > *").eq(relativePosition-1).after(el); + this.$el.find("> .bullets > *").eq(position-1).after(el); } return this; },