]> git.za3k.com Git - flowy.git/commitdiff
Make inserting work correctly visually
authorZachary Vance <vanceza@gmail.com>
Tue, 12 May 2015 03:10:42 +0000 (20:10 -0700)
committerZachary Vance <vanceza@gmail.com>
Tue, 12 May 2015 03:10:42 +0000 (20:10 -0700)
dist/flowy.js
dist/flowy.unwrapped.js
src/views/app.js
src/views/todo.js

index 35b3122cd2f96e215d52695b1402dfbe2b4b38c3..99d7cf9dca4d4f8280353098bc8740826f3f4f65 100644 (file)
@@ -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({
index a4d114f741b06bff5479e317dc3c145ab180b9f7..e9564258db0dd91d16c29266b88b07ede6bb7832 100644 (file)
@@ -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({
index 636cb22c5e63d07ec6c782bac431891ab7315d45..202c746853030265d81f2d45df6e7f469584482e 100644 (file)
@@ -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({
index 48a45011b399d6e1bd1c5ecfc0af20f5ffbfd853..145ab7b388324d5be9232e34f37d3c98adb436e6 100644 (file)
@@ -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;
   },